Automated testing with Selenium

Topics related to the integration of LSPS with external systems.
Forum rules
Make sure every topic contains information about your LSPS version and if relevant also your server OS, client OS, database name and version, and application server name and version.
Maros Bajtos
 
Posts: 145
Joined: Mon Feb 27, 2012 2:52 pm

Automated testing with Selenium

Fri May 08, 2015 2:31 pm

Given that LSPS based applications are standard web applications, selenium can be used to automate tests in a standard way. This is an example of very simple LSPS model and respective Selenium junit test that is testing it. The model contains the following:

1. Document "Start process" where user can enter several fields. Submitting the document will launch a new process instance.
2. Process with two tasks:
- first task is created for user in role "Producer" and in this task the data entered in the document can be reviewed and adjusted
- second task is created for user in role "Consumer" and in this task the data entered in previous task can be reviewed (read-only display)

These are the preconditions that must be met for the test to run correctly:
- The server that the test is running against must have the attached model uploaded
- The server that the test is running against must have two users created:
- login: consumer, password: consumer, roles: Consumer
- login: producer, password: producer, roles: Producer
- The server that the test is running against must have special debug system property set (add
parameter -Dcom.whitestein.lsps.vaadin.ui.debug=true to jvm parameters of the server) - this variable will force LSPS engine to add "id" attribute to all ui components in html. This helps to select the specific element in the resulting DOM tree. The id of the resulting html element is the same as modelling id of the component in PDS. This property is available on LSPS with version 2.7.1425 and higher. Obviously, the target elements can be selected also using xpath that does not depend on the id of the html elements.
- To configure the base url of the server, the junit test must have the following jvm system property set: -Dwebdriver.base.url=http://host:port/selenium-test
- The SeleniumTestBase class also contains a contextRoot that must be modified if the server is running on a different context root (the given example runs on selenium-test)

Keep in mind that Vaadin which LSPS uses is using AJAX calls. These calls are processed asynchronously and thus many times the test must wait till the processing end. This example is using the method waitFor to ensure that the processing has been completed. In this example it happens automatically in methods click and type (see the SeleniumTestBase class).

In the applications that have modified UI layot (e.g. menu links, login, logout) the respective methods in SeleniumTestBase class must be adjusted.

The java classes depends on seleniumhq and junit, you need to add the following maven dependencies:
Code: Select all
      <dependency>
         <groupId>junit</groupId>
         <artifactId>junit</artifactId>
         <version>4.11</version>
      </dependency>
      <dependency>
         <groupId>org.seleniumhq.selenium</groupId>
         <artifactId>selenium-java</artifactId>
         <version>2.45.0</version>
         <exclusions>
            <exclusion>
               <groupId>org.testng</groupId>
               <artifactId>testng</artifactId>
            </exclusion>
         </exclusions>
      </dependency>   


Please feel free to comment, any suggestions and questions are welcome.
Attachments
SeleniumTestBase.java
JUnit base class
(6.17 KiB) Downloaded 260 times
SeleniumTest.java
JUnit test
(3.74 KiB) Downloaded 309 times
selenium-test-1.0.zip
Model
(98 KiB) Downloaded 238 times

Martin Vysny
 
Posts: 51
Joined: Thu Dec 12, 2013 9:39 am

Re: Automated testing with Selenium

Mon May 11, 2015 1:02 pm

Thanks Maros. We plan to add proper official support for Selenium (or even Testbench) testing. This support will not be present in 3.0 though, I will post more when the feature is complete and available.

Return to Integration

Who is online

Users browsing this forum: No registered users and 1 guest