Skip to content

Commit c16eaa4

Browse files
pandafynemesifier
authored andcommitted
[tests] Automatically assign a free port to browser instance
1 parent b307f4a commit c16eaa4

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

openwisp_utils/tests/selenium.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from selenium import webdriver
44
from selenium.common.exceptions import TimeoutException
55
from selenium.webdriver.common.by import By
6+
from selenium.webdriver.common.utils import free_port
67
from selenium.webdriver.firefox.options import Options
78
from selenium.webdriver.support import expected_conditions as EC
89
from selenium.webdriver.support.ui import WebDriverWait
@@ -52,9 +53,8 @@ def get_firefox_webdriver(cls):
5253
# debugging ports for each TestCase. To accomplish this,
5354
# we can leverage the randomized live test server port to
5455
# generate a unique port for each browser instance.
55-
marionette_port = cls.server_thread.port + 100
5656
options.set_capability(
57-
'moz:firefoxOptions', {'args': ['--marionette-port', marionette_port]}
57+
'moz:firefoxOptions', {'args': ['--marionette-port', free_port()]}
5858
)
5959
kwargs = dict(options=options)
6060
# Optional: Store logs in a file
@@ -96,7 +96,7 @@ def get_chrome_webdriver(cls):
9696
# debugging ports for each TestCase. To accomplish this,
9797
# we can leverage the randomized live test server port to
9898
# generate a unique port for each browser instance.
99-
options.add_argument(f'--remote-debugging-port={cls.server_thread.port + 100}')
99+
options.add_argument(f'--remote-debugging-port={free_port()}')
100100
options.set_capability('goog:loggingPrefs', {'browser': 'ALL'})
101101
return webdriver.Chrome(
102102
options=options,

0 commit comments

Comments
 (0)