Page MenuHomePhabricator

Run Selenium tests on Cloudbees using PhantomJS
Closed, ResolvedPublic

Description


Version: unspecified
Severity: normal

Details

Reference
bz58035

Event Timeline

bzimport raised the priority of this task from to Needs Triage.Nov 22 2014, 2:20 AM
bzimport set Reference to bz58035.

This installs phantomjs in ./phantomjs-1.9.2-linux-x86_64/bin/phantomjs

curl -O https://phantomjs.googlecode.com/files/phantomjs-1.9.2-linux-x86_64.tar.bz2
tar xvf phantomjs-1.9.2-linux-x86_64.tar.bz2

This opens the browser, opens a page and takes a screen shot

require "selenium-webdriver"
Selenium::WebDriver::PhantomJS.path = "./phantomjs-1.9.2-linux-x86_64/bin/phantomjs"
browser = Selenium::WebDriver.for :phantomjs
browser.navigate.to "http://cloudbees.com"
browser.save_screenshot "cloudbees.png"

Installing phantomjs via curl requires that it is installed every time a job is executed.

If the browser is installed via npm then it can be reused between job runs, and maybe even between jobs.

curl -s -o use-node https://repository-cloudbees.forge.cloudbees.com/distributions/ci-addons/node/use-node
NODE_VERSION=0.11.8 . ./use-node
npm install phantomjs

Looks like this is the way to go:

curl -s -o use-node https://repository-cloudbees.forge.cloudbees.com/distributions/ci-addons/node/use-node
NODE_VERSION=0.11.8 . ./use-node
npm install phantomjs

mkdir -p $HOME/bin
ln -Fs /scratch/jenkins/workspace/phantomjs/node_modules/phantomjs/lib/phantom/bin/phantomjs $HOME/bin/phantomjs

curl -s -o use-ruby https://repository-cloudbees.forge.cloudbees.com/distributions/ci-addons/ruby/use-ruby
RUBY_VERSION=2.0.0-p247 \

source ./use-ruby

gem install selenium-webdriver --no-ri --no-rdoc
ruby test.rb

To avoid:

ln -Fs /scratch/jenkins/workspace/phantomjs/node_modules/phantomjs/lib/phantom/bin/phantomjs /home/jenkins/bin/phantomjs
ln: failed to create symbolic link `/home/jenkins/bin/phantomjs': File exists

Use if:

curl -s -o use-node https://repository-cloudbees.forge.cloudbees.com/distributions/ci-addons/node/use-node
NODE_VERSION=0.11.8 . ./use-node
npm install phantomjs

mkdir -p $HOME/bin

if [ ! -f $HOME/bin/phantomjs ]

then
  ln -Fs /scratch/jenkins/workspace/phantomjs/node_modules/phantomjs/lib/phantom/bin/phantomjs $HOME/bin/phantomjs

fi

According to http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html, -h should be used instead of -f.

curl -s -o use-node https://repository-cloudbees.forge.cloudbees.com/distributions/ci-addons/node/use-node
NODE_VERSION=0.11.8 . ./use-node
npm install phantomjs

mkdir -p $HOME/bin

if [ ! -h $HOME/bin/phantomjs ]

then
  ln -Fs /scratch/jenkins/workspace/phantomjs/node_modules/phantomjs/lib/phantom/bin/phantomjs $HOME/bin/phantomjs

fi

Getting somewhere, finally:

https://wmf.ci.cloudbees.com/view/fs/job/free-style-UniversalLanguageSelector-commons.wikimedia.beta.wmflabs.org-linux-phantomjs/17/console

...
ruby -r selenium-webdriver -e 'browser = Selenium::WebDriver.for :phantomjs; browser.navigate.to "https://www.google.com/"; browser.save_screenshot "google.png"'
/scratch/jenkins/addons/ruby/ruby-2.0.0-p247-x86_64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.38.0/lib/selenium/webdriver/phantomjs/service.rb:20:in `executable_path': Unable to find phantomjs executable. (Selenium::WebDriver::Error::WebDriverError)
...

Looks like this is the way to go:

curl -s -o use-node https://repository-cloudbees.forge.cloudbees.com/distributions/ci-addons/node/use-node
NODE_VERSION=0.11.8 . ./use-node
npm install phantomjs

mkdir -p $HOME/bin

if [ ! -h $HOME/bin/phantomjs ]

then
  ln -Fs ${WORKSPACE}/lib/phantom/bin/phantomjs $HOME/bin/phantomjs

fi

curl -s -o use-ruby https://repository-cloudbees.forge.cloudbees.com/distributions/ci-addons/ruby/use-ruby
RUBY_VERSION=2.0.0-p247 \

source ./use-ruby

gem install selenium-webdriver --no-ri --no-rdoc

ruby -r selenium-webdriver -e 'browser = Selenium::WebDriver.for :phantomjs; browser.navigate.to "https://www.google.com/"; browser.save_screenshot "google.png"'

Change 100384 had a related patch set uploaded by Zfilipin:
WIP Updated Ruby gems

https://gerrit.wikimedia.org/r/100384

Change 100375 had a related patch set uploaded by Zfilipin:
WIP Make it possible to run tests on Cloudbees using PhantomJS

https://gerrit.wikimedia.org/r/100375

Change 100384 merged by jenkins-bot:
Updated Ruby gems

https://gerrit.wikimedia.org/r/100384

Looks like this should do it:

curl -s -o use-node https://repository-cloudbees.forge.cloudbees.com/distributions/ci-addons/node/use-node
NODE_VERSION=0.11.8 . ./use-node
npm install phantomjs

mkdir -p $HOME/bin
if [ ! -h $HOME/bin/phantomjs ]

then
  ln -Fs $WORKSPACE/node_modules/phantomjs/lib/phantom/bin/phantomjs $HOME/bin/phantomjs

fi

phantomjs -v

Change 100375 merged by jenkins-bot:
Make it possible to run tests on Cloudbees using PhantomJS

https://gerrit.wikimedia.org/r/100375

The latest advice from Cloudbees support says this should be the way to go:

curl -s -o use-node https://repository-cloudbees.forge.cloudbees.com/distributions/ci-addons/node/use-node
NODE_VERSION=0.11.8 . ./use-node
rm $HOME/bin/phantomjs
npm install phantomjs
ln -fs $WORKSPACE/node_modules/phantomjs/lib/phantom/bin/phantomjs $HOME/bin/phantomjs
phantomjs -v