Unable to execute Selenium (3.5.0) Grid when "firefox_binary=binary" is passed as an argument in "self.driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub', firefox_binary=binary, desired_capabilities=desired_capabilities=DesiredCapabilities.FIREFOX)" method through Python PyDev (Eclipse) unittest module
browser = webdriver.Firefox(firefox_binary=binary, executable_path="C:\\Utility\\BrowserDrivers\\geckodriver.exe")
While using unittest in Python 3.6.1 we used:
def setUp(self):
self.driver = webdriver.Firefox(firefox_binary=binary, executable_path=r'C:\Utility\BrowserDrivers\geckodriver.exe')
So when we use self.driver = webdriver.Remote()
the following should work as:
def setUp(self):
self.driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub', firefox_binary=binary, desired_capabilities=DesiredCapabilities.FIREFOX)
Actual Behavior -
But while trying to use self.driver = webdriver.Remote()
as:
def setUp(self):
self.driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub', firefox_binary=binary, desired_capabilities=DesiredCapabilities.FIREFOX)
The following error is observed on the console:
Finding files... done.
Importing test modules ... done.
======================================================================
ERROR: test_search_in_python_org (readthedocs.SeleniumGridFirefox.PythonOrgSearch)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\AtechM_03\LearnAutmation\PythonProject\readthedocs\SeleniumGridFirefox.py", line 11, in setUp
self.driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub', firefox_binary=binary, desired_capabilities=DesiredCapabilities.FIREFOX)
TypeError: __init__() got an unexpected keyword argument 'firefox_binary'
----------------------------------------------------------------------
Ran 1 test in 0.001s
FAILED (errors=1)
Steps to reproduce -
Minimal Code Block:
import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
binary = r'C:\Program Files\Mozilla Firefox\firefox.exe'
class PythonOrgSearch(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub', firefox_binary=binary, desired_capabilities=DesiredCapabilities.FIREFOX)
print("Firefox Browser Invoked")
def test_search_in_python_org(self):
driver = self.driver
driver.get("http://www.python.org")
print("Application Accessed")
self.assertIn("Python", driver.title)
print("Page Title Validated")
elem = driver.find_element_by_name("q")
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
print("Page Source Validated")
def tearDown(self):
self.driver.quit()
print("WebDriver Killed")
if __name__ == "__main__":
unittest.main()
changed the title
Unable to execute Selenium (3.5.0) Grid when "firefox_binary=binary" is passed as an argument in "self.driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub', firefox_binary=binary, desired_capabilities=DesiredCapabilities.CHROME)" method through Python PyDev (Eclipse) unittest module
Unable to execute Selenium (3.5.0) Grid when "firefox_binary=binary" is passed as an argument in "self.driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub', firefox_binary=binary, desired_capabilities=desired_capabilities=DesiredCapabilities.FIREFOX)" method through Python PyDev (Eclipse) unittest module
Aug 18, 2017
firefox_binary
is not a valid parameter for the Remote
webdriver.
If your server is local to your machine and you want to specify the binary path, you'll have to do so via the desired_capabilities
parameter. This would be done such as:
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.firefox.options import Options
caps = DesiredCapabilities.FIREFOX.copy()
options = Options()
options.binary = '/path_to_binary'
caps.update(options.to_capabilities())
driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub', desired_capabilities=caps)
If you're running the server on another machine, you'll have to specify the location of the binary via a java option to the standalone server or node via:
java -dwebdriver.firefox.bin=/path_to_binary -jar standalone.jar
@lmtierney Thanks for the suggestion.
I am not sure if I exactly understood your comment when you say:
If you're running the server on another machine, you'll have to specify the location of the binary via a java option to the standalone server or node via:
java -dwebdriver.firefox.bin=/path_to_binary -jar standalone.jar
How ever, as we are still working on a POC to use Selenium Grid configuration through Python, I am initiating both the Selenium Grid Hub
& Selenium Grid Node
on my local system.
While initiating the Selenium Grid Node, we definitely issue the following command:
java -Dwebdriver.gecko.driver=geckodriver.exe -jar selenium-server-standalone-3.5.0.jar -role node -hub http://localhost:4444/grid/register
As per your suggestion, I have modified my code with the firefox.options
:
Modified Code:
import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
binary = r'C:\Program Files\Mozilla Firefox\firefox.exe'
class PythonOrgSearch(unittest.TestCase):
def setUp(self):
options = Options()
options.binary = 'binary'
caps = DesiredCapabilities.FIREFOX.copy()
caps.update(options.to_capabilities())
self.driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub', desired_capabilities=caps)
print("Firefox Browser Invoked")
def test_search_in_python_org(self):
driver = self.driver
driver.get("http://www.python.org")
print("Application Accessed")
self.assertIn("Python", driver.title)
print("Page Title Validated")
elem = driver.find_element_by_name("q")
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
print("Page Source Validated")
def tearDown(self):
self.driver.quit()
print("WebDriver Killed")
if __name__ == "__main__":
unittest.main()
And it Works as Expected.
But I have a followup question as:
If at all we are doing a from selenium.webdriver.firefox.options import Options
keeping in line with #4507 should't we be supporting firefox_options=options
within webdriver.Remote()
?
As of now providing firefox_options=options
within webdriver.Remote()
I am seeing:
Finding files... done.
Importing test modules ... done.
======================================================================
ERROR: test_search_in_python_org (readthedocs.SeleniumGridFirefox.PythonOrgSearch)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\AtechM_03\LearnAutmation\PythonProject\readthedocs\SeleniumGridFirefox.py", line 20, in setUp
self.driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub', firefox_options=options, desired_capabilities=DesiredCapabilities.FIREFOX)
TypeError: __init__() got an unexpected keyword argument 'firefox_options'
----------------------------------------------------------------------
Ran 1 test in 0.016s
FAILED (errors=1)
Is there a valid Business Case why can't we have firefox_options=options
within webdriver.Remote()
supported?
If we add firefox_options=options
in the Remote(), we would have to also add chrome_options
, etc. The better idea would be to add a generic options
key and handle accordingly. This may be an option down the road, but it's easy enough to send the options through capabilities (the option that I gave).
As far as the binary goes, it's better to specify it when you initiate the node as you shouldn't expect the system running the language bindings to know where the binary is located on the node. You mentioned you are specifying the geckodriver location, but you should also specify where the firefox binary is:
java -Dwebdriver.gecko.driver=geckodriver.exe -Dwebdriver.firefox.bin=/path_to_firefox.exe -jar selenium-server-standalone-3.5.0.jar -role node -hub http://localhost:4444/grid/register
This way you can also have specific nodes for specific versions.
Unable to execute Selenium (3.5.0) Grid when "chrome_options=options" is passed as an argument in "self.driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub', chrome_options=options, desired_capabilities=DesiredCapabilities.CHROME)" method through Python PyDev (Eclipse) unittest module
#4507