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

Compare with Current View Page History

« Previous Version 2 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.

Author's note: This page is a first draft, feel free to complete the missing parts.

 

Outlook

  • The Magnolia webapp runs on the host as usual
    • with manual-tests profile
    • e.g. mvn clean install -P jetty6-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

1. VM Setup

  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...

2. Selenium server setup

  1. Download Selenium Server (formerly the Selenium RC Server)
  2. Adjust AbstractMagnoliaUITest locally only
    • Basically replace the FirefoxDriver with a RemoteWebDriver
    • pass on the URL of your selenium server
      • default URL is something like http://{your-hostname.local}:4444/wd/hub
    • pass the FirefoxProfile along through the DesiredCapabilities
      • AbstractMagnoliaUITest.java
        URL seleniumServerUrl = null;
        try {
            String vmHostName = "your-vm-hostname";
            seleniumServerUrl = new URL(String.format("http://%s.local:4444/wd/hub", vmHostName));
        } catch (MalformedURLException e1) {}
        DesiredCapabilities capabilities = DesiredCapabilities.firefox();
        capabilities.setCapability(FirefoxDriver.PROFILE, firefoxProfile);
        driver = new RemoteWebDriver(seleniumServerUrl, capabilities);
    • Check out the patch file in the attachments!

 

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

  1. Create a new script, e.g. selenium-server on the desktop as follows
    1. provided your selenium server jar is on the desktop too)
    2. 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
    1. Download it http://www.seleniumhq.org/images/selenium-logo.png and save it locally to e.g. /home/{user}/.icons/
    2. 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)

 

  • No labels