Trying to get test running on phantomjs

Asked by Callistus

I have setup phantomjs on my machine by following your instructions here: http://coreygoldberg.blogspot.ca/2013/01/python-testing-phantomjs-with-selenium.html

I'm trying to run a basic script:
#!/usr/bin/env python
from sst.actions import *
driver = webdriver.PhantomJS('./phantomjs/bin/phantomjs')

go_to('http://www.ubuntu.com/')
assert_title_contains('Ubuntu homepage')

driver.quit()

This is the output:
(ENV)qa@jsrvr24-ub4-vm:~/ENV$ sst-run mytest
--------------------------------------------------------------
starting SST...

  date time: 2013-05-02 10:12
  test directory: '.'
  report format: 'console'
  browser type: 'Firefox'
  shared directory: None
  screenshots on error: False
  failfast: False
  debug: False
  headless xserver: False

  1 test cases loaded

--------------------------------------------------------------
sst.runtests.SSTScriptTestCase.test_mytest (sst.runtests.SSTScriptTestCase) ... DEBUG:SST:
Starting browser
ERROR

======================================================================
ERROR: sst.runtests.SSTScriptTestCase.test_mytest (sst.runtests.SSTScriptTestCase)
----------------------------------------------------------------------
_StringException: Traceback (most recent call last):
  File "/home/qa/ENV/local/lib/python2.7/site-packages/sst/runtests.py", line 519, in setUp
    super(SSTScriptTestCase, self).setUp()
  File "/home/qa/ENV/local/lib/python2.7/site-packages/sst/runtests.py", line 418, in setUp
    self.start_browser()
  File "/home/qa/ENV/local/lib/python2.7/site-packages/sst/runtests.py", line 431, in start_browser
    self.browser = self.browser_factory.browser()
  File "/home/qa/ENV/local/lib/python2.7/site-packages/sst/runtests.py", line 368, in browser
    return self.webdriver_class(self.profile)
  File "/home/qa/ENV/local/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 50, in __init__
    self.binary = FirefoxBinary()
  File "/home/qa/ENV/local/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 33, in __init__
    self._start_cmd = self._get_firefox_start_cmd()
  File "/home/qa/ENV/local/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 141, in _get_firefox_start_cmd
    " Please specify the firefox binary location or install firefox")
RuntimeError: Could not find firefox in your system PATH. Please specify the firefox binary location or install firefox

----------------------------------------------------------------------
Ran 1 test in 0.022s

FAILED (errors=1)
--------------------------------------------------------------
I dont have FF installed on my machine.

If I run it with -b PhantomJS I get this error.

(ENV)qa@jsrvr24-ub4-vm:~/ENV$ sst-run mytest -b PhantomJS
--------------------------------------------------------------
starting SST...

  date time: 2013-05-02 11:37
  test directory: '.'
  report format: 'console'
  browser type: 'PhantomJS'
  shared directory: None
  screenshots on error: False
  failfast: False
  debug: False
  headless xserver: False

  1 test cases loaded

--------------------------------------------------------------
sst.runtests.SSTScriptTestCase.test_mytest (sst.runtests.SSTScriptTestCase) ... DEBUG:SST:
Starting browser
ERROR

======================================================================
ERROR: sst.runtests.SSTScriptTestCase.test_mytest (sst.runtests.SSTScriptTestCase)
----------------------------------------------------------------------
_StringException: Traceback (most recent call last):
  File "/home/qa/ENV/local/lib/python2.7/site-packages/sst/runtests.py", line 519, in setUp
    super(SSTScriptTestCase, self).setUp()
  File "/home/qa/ENV/local/lib/python2.7/site-packages/sst/runtests.py", line 418, in setUp
    self.start_browser()
  File "/home/qa/ENV/local/lib/python2.7/site-packages/sst/runtests.py", line 431, in start_browser
    self.browser = self.browser_factory.browser()
  File "/home/qa/ENV/local/lib/python2.7/site-packages/sst/runtests.py", line 308, in browser
    return self.webdriver_class()
  File "/home/qa/ENV/local/lib/python2.7/site-packages/selenium/webdriver/phantomjs/webdriver.py", line 50, in __init__
    self.service.start()
  File "/home/qa/ENV/local/lib/python2.7/site-packages/selenium/webdriver/phantomjs/service.py", line 63, in start
    raise WebDriverException("Unable to start phantomjs with ghostdriver.", e)
WebDriverException: Message: 'Unable to start phantomjs with ghostdriver.' ; Screenshot: available via screen

----------------------------------------------------------------------
Ran 1 test in 0.032s

FAILED (errors=1)
--------------------------------------------------------------

Thanks.

Question information

Language:
English Edit question
Status:
Answered
For:
selenium-simple-test Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Corey Goldberg (coreygoldberg) said :
#1

Hi...

> I have setup phantomjs on my machine by following your instructions here

those directions are quite dated... Ghostdriver is now part of PhantomJS itself. The easiest way to get it is to just grab a binary package of PhantomJS: http://phantomjs.org/download.html

once you download a binary version for your system, take the "phantomjs" executable and place it somewhere on your system path (or add it's location to your system path). then webdriver will be able to find phantomsjs.

 > driver = webdriver.PhantomJS('./phantomjs/bin/phantomjs')

don't create your own driver in an sst script. the SST framework takes care of creating the webdriver object and starting the browser. so your sst script should look like this (no matter which browser you run with):

--------
#!/usr/bin/env python
from sst.actions import *
go_to('http://www.ubuntu.com/')
assert_title_contains('Ubuntu homepage')
--------

> (ENV)qa@jsrvr24-ub4-vm:~/ENV$ sst-run mytest

you haven't specified a browser, so it should use Firefox, not phantomjs... is firefox installed?

> (ENV)qa@jsrvr24-ub4-vm:~/ENV$ sst-run mytest -b PhantomJS

that is a correct invocation of sst-run using PhantomJS. it most likely can't find the phantomjs binary (see comment above about adding to system path).

hope that helps.

-Corey

Can you help with this problem?

Provide an answer of your own, or ask Callistus for more information if necessary.

To post a message you must log in.