Page History
Note |
---|
This page probably is outdated partially. For a more up-to-date documentation regarding UI tests for Magnolia 6.1 and higher, please also check the documentation on bitbucket. |
Info |
---|
UI tests typically require browser/machine focus (especially when entering text in input fields). To avoid being stuck while UI tests proceed, it's handy to run them — the Selenium part — inside a VM. |
Outlook
- The Magnolia webapp runs on the host as usual
- with manual-tests profile
- e.g.
mvn clean verify -P jetty9-standalone,manual-tests
- free hint #1: run this build from another location on your machine than the one you typically work at
- free hint #2: run it in offline mode (
mvn -o ...
) if you just installed one of the modules you want to put under test
...
- Setup your VM and install Ubuntu for example
- mount iso image in optical drive
- In VirtualBox preferences File > Network > Host-only NetworksHost Network Manager..., click the add icon
- creates a new virtual network interface e.g.
vboxnet0
- (used to be Preferences > Network in former vbox versions, as illustrated below)
- creates a new virtual network interface e.g.
- In VM Settings > Network
- 1st slot: select "Host-only Adapter", then choose the one you just created — that
vboxnet0
- 2nd slot: select NAT as is usually the default (to access the interwebs through the host)
- 1st slot: select "Host-only Adapter", then choose the one you just created — that
- Install guest additions
- When VirtualBox VM is running
- Devices > Insert Guest Additions CD image...
...
- In the VM, download Selenium Server (formerly the Selenium RC Server)
- http://docs.seleniumhq.org/download/
- in case of problems with the only linked version (i.e. 3.0.0-beta3), links to older packages can be found here: http://selenium-release.storage.googleapis.com/, e.g. http://selenium-release.storage.googleapis.com/2.52/selenium-server-standalone-2.52.jar
- should be something like
selenium-server-standalone-2.42.2.jar
- and then run it, e.g.
java -jar selenium-server-standalone-2.42.2.jar
- For Selenium 3+, you'll need to get Geckodriver first and provide it's location to Selenium through the webdriver.gecko.driver (Java) system property.
To do so, either- run it as
java -jar -Dwebdriver.gecko.driver=/path/to/geckodriver selenium-server-standalone-3.3.1.jar
- or once set it globally in
/etc/environment
, e.g. throughecho "_JAVA_OPTIONS='-Dwebdriver.gecko.driver=/path/to/geckodriver" | sudo tee -a /etc/environment
, then log out and back in for the changes to take effect
- run it as
- For Selenium 3+, you'll need to get Geckodriver first and provide it's location to Selenium through the webdriver.gecko.driver (Java) system property.
- http://docs.seleniumhq.org/download/
On your host run the UI Tests with the variables
seleniumServerHostName
which is the address of your newly created VM andcontainerHostName
which is the address used of your VM to access your host system (this is probably not equal to your machines address in the magnolia network)Code Block language bash $ mvn -U clean install -Pjetty9-standalone,ui-tests -DseleniumServerHostName=192.168.56.101 -DcontainerHostName=192.168.56.1
If necessary replace the IP addresses.
In your run configuration in IntelliJ you have to add these two variables
seleniumServerHostName
andcontainerHostName
as well.
3. Fancy shell script + desktop launcher for the Selenium server
...
Double-click your script and you're good to go!
Jetty 9 compatible IntelliJ setup
Disclaimer: This setup has only been tried on two machines so far. The procedure might need to be completed, or adapted.
In IntelliJ, go to Edit Configurations. For Tomcat, insert the following VM options:
Code Block | ||||
---|---|---|---|---|
| ||||
-Xms128M -Xmx1048M -Djava.awt.headless=true -Dfile.encoding=UTF-8 -XX:MaxPermSize=256m -DseleniumServerHostName=192.168.56.101 -DcontainerHostName=192.168.56.1 |
Also, in the Deployment tab, add two artifacts:
- magnolia-test-webapp:war exploded, with 'Application context' set to /magnoliaTest
- magnolia-test-public-webapp:war exploded, with 'Application context' set to /magnoliaTestPublic
In that same window, select JUnit under Defaults in the left pane. Insert the following VM options:
Code Block | ||||
---|---|---|---|---|
| ||||
-ea -DseleniumServerHostName=192.168.56.101 -DcontainerHostName=192.168.56.1 -DcontainerRootURL=http://192.168.56.1:8080/ |
Next step is to clean and rebuild both instances:
Code Block | ||
---|---|---|
| ||
cd ce/magnolia-integration-tests/magnolia-test-public-webapp/; mvn clean install; rm -rf overlays
cd ce/magnolia-integration-tests/magnolia-test-webapp/; mvn clean install; rm -rf overlays |
Once done, go in the 'Maven projects' sidebar in the IDE (on the top right), and click on 'Reimport all Maven projets' (blue circular arrow).
Then
...
- Tomcat from the IDE
selenium-server.sh on the VM
...
- Both exploded wars are deployed at Tomcat startup (check out the log)
- http://localhost:8080/magnoliaTest can be accessed on the host machine
- http://192.168.56.1:8080 can be accessed from the VM
...
...
Tips for simulating low-end hardware (like on Jenkins test runs)
When tests seem to fail randomly in a non-reproducible manner on from Jenkins, it's sometimes related to slower hardware compared to local execution. To be more consistent and robust, it can be helpful to mimic such a low-end environment.
Use low screen resolution
Some failures (like hidden dialog commit buttons) only occur on screens with low resolution. With VirtualBox guest extensions properly installed, you should be able to simply resize the VM window and the guest's virtual screen should automatically adjust. As a reference for size, screenshots from failed Jenkins build may be used; or just roughly 1000 x 700 px.
Throttle Magnolia
Other test failures are caused by racing conditions only surfacing on slow systems, where certain elements take longer to load than usual. For Linux (now OS X too), there's a command line tool called cpulimit to set an upper CPU time percentage limit for certain processes.
- On Ubuntu, install with
sudo apt-get install cpulimit
or simply click here (apt-url) - On OS X, clone it from GitHub and check the README for build instructions or with brew → cpulimit with brew
Setting the limit to 5% for the process with id 1234 is done by
cpulimit -l 5 -i 1234
...