views:

586

answers:

2

I am getting the following errors when running a basic Selenium test script in Python:

======================================================================
ERROR: test_untitled (__main__.TestTesting)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "TestTesting.py", line 15, in setUp
    self.selenium.start()
  File "/usr/lib/python2.6/dist-packages/selenium.py", line 166, in start
    result = self.get_string("getNewBrowserSession", [self.browserStartCommand, self.browserURL])
  File "/usr/lib/python2.6/dist-packages/selenium.py", line 195, in get_string
    result = self.do_command(verb, args)
  File "/usr/lib/python2.6/dist-packages/selenium.py", line 191, in do_command
    raise Exception, data
Exception: Failed to start new browser session: Error while launching browser

----------------------------------------------------------------------
Ran 1 test in 20.427s

FAILED (errors=1)

The code was generated from the Selenium IDE, the firefox plug in, so I am not sure why it doesn't work. My guess is some sort of configuration is incorrect, but I am not sure. Here is my code:

from selenium import selenium

class TestTesting(unittest.TestCase):
    def setUp(self):
        self.verificationErrors = []
        self.selenium = selenium("localhost", 4444, "*firefox", "http://www.google.com/")
        self.selenium.start()

    def test_untitled(self):
        sel = self.selenium
        sel.open("/firefox?client=firefox-a&rls=org.mozilla:en-US:official")
        sel.type("sf", "test")
        sel.click("btnG")
        sel.wait_for_page_to_load("30000")

    def tearDown(self):
        self.selenium.stop()
        self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
    unittest.main()

The server is running on Ubuntu.

How can I avoid this error?

A: 

The fix that I got to work was that the display for firefox was not set. So I needed to execute the following statement:

export DISPLAY=:0

right before I started the Selenium server. This solve the issue, but a new one has arisen.

Phegan
I used that fix initially, and it fixed part of my issue. There was also an issue, maybe versioning, where the session was coming back as a uuid, but in selenium.py is was casting it as a long..which created issues. So the combination of the export DISPLAY and the fixing of the casting worked.
Phegan
A: 

This normally happens when another firefox is already opened. i.e. You are using specific FF profile to tet application. When you run the script, close FF.

Bharat Patel
Unfortunately, that was not the case, it would happen even when FF was absolutely not running.
Phegan