Selenium and phantom
running selenium server locally in a way that should complement using
Quick notes for Selenium with NodeJS, CucumberJS and PhantomJS….. and also thinking about Travis CI.
WebDriver
Use a project called WebDriverIO, it is the new version of WebDriverJS.
It also has support for AngularJS, which is very interesting. As I have run into issues with running Protractor with PhantomJS. The documentation states that the WebDriverJS-Angular hooks into the browser object meaning you so not have to be aware of Angular, and use Pause(). Thats nice icing on the cake.
Using the demo code
Run the following
npm install -g cucumber
npm install --save-d webdriverio
Get the demo code copy it into a features folder
project
|-----features
|- my-feature.feature
|- step-definitions.js
Change the following in the step file
var webdriverjs = require('../../../index'),
TO
var webdriverjs = require('webdriverio'),
Note the demo CucumberJS with WebDriverIO, especially the following line
var client = webdriverjs.remote({ desiredCapabilities: {browserName: 'phantomjs'}, logLevel: 'silent' }),
There is no location provided to the phantomjs driver, which will mean it should just work on Travis without a change.
Setup Selenium Server
Setting up the sever is really simple.
- Install the Java JDK (I’m using Oracles 1.8 JDK)
- Create a folder to place selenium and any drivers you want to support.
- Download the selenium-server copy the jar file into the new folder
- Download PhantomJS - copy the .exe into the new folder
The folder structure should look like this:
selenium-server
|- selenium-server-standalone-2.42.2.jar
|- phantomjs.exe
|- Any Other Driver
Run Selenium Server
open the CMD and navigate to the selenium-server folder, and execute the following:
java -jar selenium-server-standalone-2.42.2.jar -Dphantomjs.binary.path="phantomjs.exe"
This will start the server ready for testing
Run your tests
in npm
cucumber-js
this will now run all the tests, you will see the commands being run against the selenium server in its own console.
Note that we have run the server telling it where the Browser Drivers are, so our test client only has to supply the name only
Helpful Sever links
List Sessions (also see if your sever is up)
http://localhost:4444/wd/hub <- this is a web io
http://localhost:4444/wd/hub/status <- Json endpoint
Shutdown Server (other than ctrl+c)
http://localhost:4444/selenium-server/driver?cmd=shutDownSeleniumServer