Testing Times – hubs, nodes and grids

I have been doing some basic testing experiments within the SSP.  I thought it was a good time to try out Selenium GRID which brings cross browser testing to selenium and Appium for mobile testing.

So I thought I would share how I set up some basic settings to get started with Selenium GRID and Appium.

Setting up Selenium Grid

This requires you to download the Selenium Server jar and run it as a hub which lets you attach clients as nodes.

Setup the HUB

Run the below to set-up a simple default selenium hub (runs on port 4444)

java -jar selenium-server-standalone-2.35.0.jar -role hub

Setup the nodes

You need to register the hubs with the server, this will allow the selenium server to farm out the testing to the different browsers and platforms

Sample basic
java -jar selenium-server-standalone-2.35.0.jar -role node  -hub http://<IP>:4444/grid/register
sample Mac Safari
java -jar selenium-server-standalone-2.42.2.jar -role node -hub http://<IP>:4444/grid/register -port 5557 -browser browserName=safari,platform=MAC

You can then run tests against the hub, and depending on the capabilities you want for testing, it will select the registered browser and farm it off to that node.

This can be great for browser testing or just making your selenium tests run a little faster

Appium

You can use appium for all kinds of mobile testing, native, hybrid or just plain web apps.

My primary interest was just to expand the selenium grid testing and use it to capture ios safari (and add android in when I had it all sorted).

It is very straight forward to setup once you know a few secrets.  The most straight forward think is to download the app (I set this up for the Mac), it also makes your life a lot easier if you install nodejs.  Appium uses WebDriver JSON so you can build on some of your existing web driver scripts.

Set the permission for the IOS simulator

When you install appium it will try and run the permission script for the ios simulator (it needs to use some specific settings), this should work but it might not, so I would suggest running the script “authorize-ios.js” as sudo, I tried a more direct solution and ended up breaking ios simulator but the below worked a treat.

sudo node authorize-ios.js

 

Selenium Grid with Appium

To get it to work with Selenium Grid you just need to create a simple configuration file.  This will basically tell selenium where to send the requests.

{
 "capabilities":
 [
 {
 "platformName": "iOS"
 , "platformVersion": "7.1"
 , "browserName": "Safari"
 , "deviceName": "iPhone Simulator"
 }
 ],
 "configuration":
 {
 "cleanUpCycle":2000,
 "timeout":30000,
 "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
 "url":"http://<appiumIPaddress>:4723/wd/hub",
 "host": "<appiumServer_IP>",
 "port": 4723,
 "maxSession": 10,
 "register": true,
 "registerCycle": 5000,
 "hubPort": 4444,
 "hubHost": "<SELENIUMSERVER_IP>"
 }
 }

You then add that into your configuration, select the Selenium Grid Configuration and it should just magically work.

Appium

The only change you should need to make to your webdriver code is to ensure that it is pointing to the remote service and state which desiredCapabilites you want to run.

        self.driver = webdriver.Remote(desired_capabilities={           
            "browserName": "iphone", 
            "platform":"MAC"
        })

A little more detail can be found in the appium docs for mobile testing

You can point it to android simulators as well as real devices (this requires some setup).  So if you are using selenium in your project or you need to test a mobile application you might want to consider looking at some of these features.