Creating a testing infrastructure with Pytest , Selenium Grid and Docker
I think you're almost there.
I would add a pytest
service to the docker-compose.yml
, and remove the volumes_from
and external_links
from the hub
image (so that it looks more like the example from the blog post you linked).
The pytest
service will run the python code, but it should connect to hub to run selenium. I believe somewhere in the org_QA_folder
there is configuration that tries to start up selenium locally. It needs to be reconfigured to use the hub
server instead.
I finally made it to work like this:
From my code I use this:
class Fixtures_docker(unittest.TestCase): def setUp(self, hub_ip="http://HUB_CONTAINER_IP", hub_port=4444): print "--Fixtures_docker in config.py trying to run on--: %s:%s"%(hub_ip, hub_port) if platform.system() == 'Linux': from pyvirtualdisplay import Display self.display = Display(visible=0, size=(1024, 768)) self.display.start() if browser == "Firefox": self.wd = webdriver.Remote( command_executor=hub_ip + ':' + str(hub_port) + '/wd/hub', desired_capabilities={ #FIREFOX "browserName" : "firefox", # "maxInstances" : 10, "seleniumProtocol": "WebDriver", "platform" : "ANY", "node" : hub_port }) # for debugging purposes from local machine elif browser == "Firefox" and os == "Windows": self.wd = webdriver.Remote( command_executor=hub_ip + ':' + str(hub_port) + '/wd/hub', desired_capabilities={ # FIREFOX -> WINDOWS # "firefox_binary":"C:\\firefox3\Firefox3.exe", # path to find another version of ff "browserName" : "firefox", #"version" : "3.0b3", # trying to run a specific ff version "platform" : "WINDOWS", "node" : hub_port, "maxSession" : 5 }) self.wd.implicitly_wait(10) def tearDown(self): self.wd.quit() if platform.system() == 'Linux': self.display.stop()
and in the docker-compose.yml:
hub: image: org/grid:hub # image must already exist ports: - "8080:4444" # HOST:CONTAINER external_links: # link to a container created outside of this YAML file - pytest volumes_from: - pytest # must be created first expose: - "4444" # intercontainer communication [other containers with selenium server]firefox: image: org/grid:nodeff # image must already exist links: - hub expose: - "5555" # intercontainer communication [node registers to hub]