Skip to content

Commit de9c5c1

Browse files
committed
Update files in tests
Signed-off-by: Viet Nguyen Duc <[email protected]>
1 parent cabae69 commit de9c5c1

4 files changed

+131
-17
lines changed

tests/docker-compose-v3-dev-arm64.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# To execute this docker compose yml file use `docker compose -f docker-compose-v3-dev-arm64.yml up`
2+
# Add the `-d` flag at the end for detached execution
3+
# To stop the execution, hit Ctrl+C, and then `docker compose -f docker-compose-v3-dev-arm64.yml down`
4+
services:
5+
chrome:
6+
deploy:
7+
mode: replicated
8+
replicas: 3
9+
image: selenium/node-chromium:4.32.0-20250515
10+
platform: linux/arm64
11+
shm_size: 2gb
12+
volumes:
13+
- ./selenium_server_deploy.jar:/opt/selenium/selenium-server.jar
14+
depends_on:
15+
- selenium-hub
16+
environment:
17+
- SE_EVENT_BUS_HOST=selenium-hub
18+
- SE_VNC_NO_PASSWORD=true
19+
- SE_NODE_ENABLE_MANAGED_DOWNLOADS=true
20+
21+
firefox:
22+
deploy:
23+
mode: replicated
24+
replicas: 3
25+
image: selenium/node-firefox:4.32.0-20250515
26+
shm_size: 2gb
27+
volumes:
28+
- ./selenium_server_deploy.jar:/opt/selenium/selenium-server.jar
29+
depends_on:
30+
- selenium-hub
31+
environment:
32+
- SE_EVENT_BUS_HOST=selenium-hub
33+
- SE_VNC_NO_PASSWORD=true
34+
- SE_NODE_ENABLE_MANAGED_DOWNLOADS=true
35+
36+
selenium-hub:
37+
image: selenium/hub:4.32.0-20250515
38+
container_name: selenium-hub
39+
volumes:
40+
- ./selenium_server_deploy.jar:/opt/selenium/selenium-server.jar
41+
ports:
42+
- "4442:4442"
43+
- "4443:4443"
44+
- "4444:4444"

tests/docker-compose-v3-get-started-arm64.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# To execute this docker compose yml file use `docker compose -f docker-compose-v3-video-arm64.yml up`
1+
# To execute this docker compose yml file use `docker compose -f docker-compose-v3-get-started-arm64.yml up`
22
# Add the `-d` flag at the end for detached execution
3-
# To stop the execution, hit Ctrl+C, and then `docker compose -f docker-compose-v3-video-arm64.yml down`
3+
# To stop the execution, hit Ctrl+C, and then `docker compose -f docker-compose-v3-get-started-arm64.yml down`
44
services:
55
chrome:
66
deploy:

tests/get_started.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,29 @@
1818
else:
1919
GRID_URL = "http://localhost:4444/wd/hub"
2020

21-
options = None
22-
if browser == "chrome":
23-
options = ChromeOptions()
24-
elif browser == "firefox":
25-
options = FirefoxOptions()
26-
elif browser == "edge":
27-
options = EdgeOptions()
21+
import concurrent.futures
2822

29-
driver = webdriver.Remote(
30-
command_executor=GRID_URL,
31-
options=options,
32-
)
23+
def run_browser_instance(browser, grid_url):
24+
options = None
25+
if browser == "chrome":
26+
options = ChromeOptions()
27+
elif browser == "firefox":
28+
options = FirefoxOptions()
29+
elif browser == "edge":
30+
options = EdgeOptions()
31+
options.enable_bidi = True
32+
options.enable_downloads = True
3333

34-
driver.get('https://www.google.com/')
35-
print(driver.title)
36-
time.sleep(100)
37-
driver.quit()
34+
while True:
35+
driver = webdriver.Remote(
36+
command_executor=grid_url,
37+
options=options,
38+
)
39+
driver.get('https://www.google.com/')
40+
print(driver.title)
41+
time.sleep(100)
42+
driver.quit()
43+
44+
with concurrent.futures.ThreadPoolExecutor(max_workers=3) as executor:
45+
for _ in range(3):
46+
executor.submit(run_browser_instance, browser, GRID_URL)

tests/test_grid_ui.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import sys
2+
3+
from selenium import webdriver
4+
from selenium.webdriver.common.by import By
5+
from selenium.webdriver.support.ui import WebDriverWait
6+
from selenium.webdriver.support import expected_conditions as EC
7+
from selenium.webdriver.chrome.options import Options as ChromeOptions
8+
from selenium.webdriver.firefox.options import Options as FirefoxOptions
9+
from selenium.webdriver.edge.options import Options as EdgeOptions
10+
import time
11+
12+
if len(sys.argv) < 2:
13+
print("Usage: python3 get_started.py [chrome|firefox|edge]")
14+
sys.exit(1)
15+
browser = sys.argv[1].lower()
16+
if browser not in ["chrome", "firefox", "edge"]:
17+
print("Unsupported browser. Use 'chrome', 'firefox', or 'edge'.")
18+
sys.exit(1)
19+
20+
def run_browser_instance(browser):
21+
22+
while True:
23+
options = None
24+
if browser == "chrome":
25+
options = ChromeOptions()
26+
options.add_argument("--headless=new")
27+
driver = webdriver.Chrome(options=options)
28+
elif browser == "firefox":
29+
options = FirefoxOptions()
30+
driver = webdriver.Firefox(options=options)
31+
elif browser == "edge":
32+
options = EdgeOptions()
33+
driver = webdriver.Edge(options=options)
34+
else:
35+
raise ValueError("Unsupported browser. Use 'chrome', 'firefox', or 'edge'.")
36+
37+
try:
38+
driver.get('http://localhost:4444')
39+
print(driver.title)
40+
41+
# Explicit wait for the search bar to be visible
42+
WebDriverWait(driver, 10).until(
43+
EC.visibility_of_element_located((By.XPATH, "//*[@data-testid='VideocamIcon']/.."))
44+
)
45+
46+
import random
47+
elements = driver.find_elements(By.XPATH, "//*[@data-testid='VideocamIcon']/..")
48+
if elements:
49+
random.choice(elements).click()
50+
print("Random element clicked.")
51+
else:
52+
print("No elements found.")
53+
finally:
54+
time.sleep(15) # Keep the browser open for 10 seconds
55+
driver.quit()
56+
57+
import concurrent.futures
58+
59+
with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
60+
for _ in range(5):
61+
executor.submit(run_browser_instance, browser)

0 commit comments

Comments
 (0)