6

I'm having issues running my automation test scripts. When I run my script, a browser will appear but it will not type the URL and waits for 10 seconds until it throws an exception. Is there any solutions I can use so then I can get my automation test scripts to work?

Geckodriver.log:

1523997052492   geckodriver INFO    geckodriver 0.20.1
1523997052531   geckodriver INFO    Listening on 127.0.0.1:37807
1523997052592   mozrunner::runner   INFO    Running command: "/usr/bin/firefox/firefox" "-marionette" "--headless" "-profile" "/tmp/rust_mozprofile.PU1cngaAJ5Tg"
1523997054831   Marionette  INFO    Listening on port 2828

Stack Traces:

Error
Traceback (most recent call last):
File 
"/home/kavin/PycharmProjects/untitled/Testing/purchaseAmazonItems.py", line 13, in setUp
self.driver = webdriver.Firefox(firefox_binary=binary, firefox_options=opts)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/firefox/webdriver.py", line 162, in __init__
keep_alive=True)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 154, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 243, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: connection refused

Code:

def setUp(self):
    binary = FirefoxBinary('/usr/bin/firefox/firefox')
    opts = FirefoxOptions()
    opts.add_argument("--headless")
    self.driver = webdriver.Firefox(firefox_binary=binary, firefox_options=opts)
    driver = self.driver
    driver.get('https://www.amazon.com/')

Specs:

Ubuntu 16.04
geckodriver 0.20.1
firefox 59.0.2+build1-0ubuntu0.16.04.3
Python 3.6
Pycharm 2016.3
Selenium 3.11.0

3
  • Why do you want to do a driver = self.driver? Additionally consider updating the question with error stack trace instead of separate Exceptions and Geckodriver.log sections along with your binary versions. Commented Apr 18, 2018 at 8:59
  • @DebanjanB The reason why I did driver = self.driver was because I don't want to keep typing self.driver every time. Is that best practices? Also I updated my post with error stack trace. Commented Apr 18, 2018 at 18:06
  • @DebanjanB my exceptions is pretty similar to my stack trace. Commented Apr 18, 2018 at 18:08

2 Answers 2

4

In absence of the error stack trace configuration issues are pretty hard to debug. Having said that I don't see any major issues in your code block. You may require to perform some additional steps as follows :

  • Pass the Key executable_path along with the Value referring to the absolute path of the GeckoDriver as follows :

    def setUp(self):
        binary = FirefoxBinary('/usr/bin/firefox/firefox')
        opts = FirefoxOptions()
        opts.add_argument("--headless")
        self.driver = webdriver.Firefox(firefox_binary=binary, firefox_options=opts, executable_path='/path/to/geckodriver')
        driver = self.driver
        driver.get('https://www.amazon.com/')
    
  • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.

  • Use CCleaner tool to wipe off all the OS chores before and after the execution of your Test Suite.
  • If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.
  • Take a System Reboot.
  • Execute your @Test.
  • Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.

Alternative

As an alternative you can also try to use the set_headless(headless=boolean_value) as follows :

def setUp(self):
    binary = FirefoxBinary('/usr/bin/firefox/firefox')
    opts = FirefoxOptions()
    opts.set_headless(headless=True)
    self.driver = webdriver.Firefox(firefox_binary=binary, firefox_options=opts, executable_path='/path/to/geckodriver')
    driver = self.driver
    driver.get('https://www.amazon.com/')

Here you can find a detailed discussion on How to make firefox headless programatically in Selenium with python?

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks I was able to solve my issue by adding the following executable path executable_path='/path/to/geckodriver
Thanks @DebanjanB When validating my directories, I saw I have /usr/bin/firefox instead of /usr/bin/firefox/firefox, so I edited the code like this --> binary = FirefoxBinary('/usr/bin/firefox') and it fixed the error.
2

These two commands both start a webdriver on the same port. The second one causes the error because the port is already in use:

self.driver = webdriver.Firefox(firefox_binary=binary)
browser = webdriver.Firefox(firefox_options=opts)

To correct this, set the options before initializing the driver (in the first command).

self.driver = webdriver.Firefox(firefox_binary=binary, firefox_options=opts)

1 Comment

I tried the following the solutions you provided and it still producing the same issue. I updated my post with my updated code. and gecko logs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.