You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 17 Next »

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 
  • A Selenium standalone server runs on the guest VM
  • Test execution is done from the IDE, i.e. also on the host

Instructions

1a. VM Setup manually

  1. Setup your VM and install Ubuntu for example
    1. mount iso image in optical drive
  2. In VirtualBox preferences > Network > Host-only Networks, click the add icon
    • creates a new virtual network interface e.g. vboxnet0
       
  3. 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)
  4. Install guest additions
    • When VirtualBox VM is running
    • Devices > Insert Guest Additions CD image...

1b. VM Setup with Vagrant

  1. Download and install vagrant from https://www.vagrantup.com or use the vagrant manager http://vagrantmanager.com
  2. Clone the repro https://git.magnolia-cms.com/users/mmuehlebach/repos/uitestmachine
  3. Go to the cloned directory and run vagrant up
  4. Start selenium server with ./selenium-server.sh

2. Selenium server setup

  1. In the VM, download Selenium Server (formerly the Selenium RC Server)
  2. On your host run the UI Tests with the variables seleniumServerHostName which is the address of your newly created VM and containerHostName 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)

    $ mvn -U clean install -Pjetty9-standalone,ui-tests -DseleniumServerHostName=192.168.56.101 -DcontainerHostName=192.168.56.1

    If necessary replace the IP addresses.

  3. In your run configuration in IntelliJ you have to add these two variables seleniumServerHostName and containerHostName as well.


 

3. Fancy shell script + desktop launcher for the Selenium server

  1. Create a new script, e.g. selenium-server on the desktop as follows
    • (provided your selenium server jar is on the desktop too)
    • selenium-server.sh
      #!/bin/bash
      gnome-terminal -e "java -jar selenium-server-standalone-2.42.2.jar"
  2. Make it executable
    • chmod +x your-script
    • Go to Nautilus (eq. Finder) preferences
      • Edit > Preferences, "Behavior" tab
      • Tick "Run executable text files when they are opened"

  3. The fancy icon
    • Select your script, right-click and go to the file Properties >  Click the icon and select yours

Double-click your script and you're good to go! (smile)

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:

Tomcat VM options
-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:

JUnit VM options
-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:

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

  1. Start
    1. Tomcat from the IDE
    2. selenium-server.sh on the VM

  2. Make sure that:
    1. Both exploded wars are deployed at Tomcat startup (check out the log)
    2. http://localhost:8080/magnoliaTest can be accessed on the host machine
    3. http://192.168.56.1:8080 can be accessed from the VM
  3. Run the magnolia installs at:
    1. http://localhost:8080/magnoliaTest/.magnolia/
    2. http://localhost:8080/magnoliaTestPublic/.magnolia/
  4. Run a test from the IDE
  5. Repeat the whole process if the setup breaks
  • No labels