55import pytest
66from podman import PodmanClient
77from selenium import webdriver
8- from selenium .webdriver .common .desired_capabilities import DesiredCapabilities
98from wait_for import wait_for
109from widgetastic .browser import Browser
1110
1211
1312selenium_browser = None
1413
14+ OPTIONS = {"firefox" : webdriver .FirefoxOptions (), "chrome" : webdriver .ChromeOptions ()}
15+
1516# Begging, borrowing, and stealing from @quarkster
1617# https://github.com/RedHatQE/widgetastic.patternfly4/blob/master/testing/conftest.py#L21
1718
@@ -42,6 +43,7 @@ def pod(podman, worker_id):
4243 portmappings = [
4344 {"host_ip" : localhost_for_worker , "container_port" : 5999 , "host_port" : 5999 },
4445 {"host_ip" : localhost_for_worker , "container_port" : 4444 , "host_port" : 4444 },
46+ {"host_ip" : localhost_for_worker , "container_port" : 80 , "host_port" : 8080 },
4547 ],
4648 )
4749 pod .start ()
@@ -59,15 +61,21 @@ def selenium_url(pytestconfig, worker_id, podman, pod):
5961 """Yields a command executor URL for selenium, and a port mapped for the test page to run on"""
6062 # use the worker id number from gw# to create hosts on loopback
6163 last_oktet = 1 if worker_id == "master" else int (worker_id .lstrip ("gw" )) + 1
62- localhost_for_worker = f"127.0.0.{ last_oktet } "
64+ driver_url = f"http:// 127.0.0.{ last_oktet } :4444 "
6365 container = podman .containers .create (
6466 image = "quay.io/redhatqe/selenium-standalone:latest" ,
6567 pod = pod .id ,
6668 remove = True ,
6769 name = f"selenium_{ worker_id } " ,
6870 )
6971 container .start ()
70- yield f"http://{ localhost_for_worker } :4444/wd/hub"
72+ wait_for (
73+ urlopen ,
74+ func_args = [driver_url ],
75+ timeout = 180 ,
76+ handle_exception = True ,
77+ )
78+ yield driver_url
7179 container .remove (force = True )
7280
7381
@@ -87,21 +95,13 @@ def testing_page_url(worker_id, podman, pod):
8795 ],
8896 )
8997 container .start ()
90- yield "http://127.0.0.1 /testing_page.html"
98+ yield "http://localhost:80 /testing_page.html"
9199 container .remove (force = True )
92100
93101
94102@pytest .fixture (scope = "session" )
95103def selenium_webdriver (browser_name , selenium_url , testing_page_url ):
96- wait_for (urlopen , func_args = [selenium_url ], timeout = 180 , handle_exception = True )
97- if browser_name == "firefox" :
98- desired_capabilities = DesiredCapabilities .FIREFOX .copy ()
99- else :
100- desired_capabilities = DesiredCapabilities .CHROME .copy ()
101- desired_capabilities ["chromeOptions" ] = {"args" : ["--no-sandbox" ]}
102- driver = webdriver .Remote (
103- command_executor = selenium_url , desired_capabilities = desired_capabilities
104- )
104+ driver = webdriver .Remote (command_executor = selenium_url , options = OPTIONS [browser_name .lower ()])
105105 driver .maximize_window ()
106106 driver .get (testing_page_url )
107107 global selenium_browser
0 commit comments