Skip to content

Commit dcd7746

Browse files
Merge pull request #205 from AutomationSolutionz/selenium_grid
Selenium grid
2 parents e4bae93 + bc60bde commit dcd7746

File tree

3 files changed

+155
-17
lines changed

3 files changed

+155
-17
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66
# Version 16
77

88
### [Current changes]
9+
- **[Add]** Added selenium grid functionality. Usage:
10+
```shell
11+
cd .../Framework/Built_In_Automation/Web/Selenium
12+
docker-compose -f docker-compose-v3.yml up
13+
```
914
- **[Fix]** Compare data *ignore_list_order* bug fix
1015
- **[Fix]** Zeuz_auto_teardown variable bug fix
1116
- **[Fix]** Mobile browser update bug fix
1217
- **[Fix]** zeuz_pid_finder bug fix for chrome
13-
1418
- **[Add]** Authenticator code generator action is added for windows
1519
- **[Improve]** Function handle capability inside csv cells is implemented
1620
- **[Fix]** Windows_pid issue solved for image searching

Framework/Built_In_Automation/Web/Selenium/BuiltInFunctions.py

Lines changed: 70 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,26 @@ def Open_Browser(dependency, window_size_X=None, window_size_Y=None, capability=
380380
"Dependency not set for browser. Please set the Apply Filter value to YES."
381381
)
382382
return CommonUtil.Exception_Handler(sys.exc_info(), None, ErrorMessage)
383+
384+
if Shared_Resources.Test_Shared_Variables('run_time_params'): # Look for remote config in runtime params
385+
run_time_params = Shared_Resources.Get_Shared_Variables('run_time_params')
386+
remote_config = run_time_params.get("remote_config")
387+
if(remote_config):
388+
remote_host = remote_config.get('host')
389+
remote_browser_version = remote_config.get('browser_version')
390+
if(remote_host):
391+
try:
392+
if requests.get(remote_host).status_code != 200:
393+
remote_host = None
394+
except requests.exceptions.RequestException as e:
395+
remote_host = None
396+
if remote_host == None:
397+
CommonUtil.ExecLog(
398+
sModuleInfo, "Remote host: %s is not up. Running the browser locally " % remote_config.get('host'), 3
399+
)
400+
else:
401+
remote_host = None
402+
remote_browser_version = None
383403
# try:
384404
# selenium_driver.close()
385405
# except:
@@ -430,6 +450,8 @@ def Open_Browser(dependency, window_size_X=None, window_size_Y=None, capability=
430450
ConfigModule.add_config_value("Selenium_driver_paths", "chrome_path", chrome_path)
431451
options = Options()
432452

453+
if remote_browser_version:
454+
options.set_capability("browserVersion",remote_browser_version)
433455
# capability
434456
if capability:
435457
for key, value in capability.items():
@@ -474,11 +496,18 @@ def Open_Browser(dependency, window_size_X=None, window_size_Y=None, capability=
474496
"download.directory_upgrade": True
475497
}
476498
options.add_experimental_option('prefs', prefs)
477-
selenium_driver = webdriver.Chrome(
478-
executable_path=chrome_path,
479-
chrome_options=options,
480-
desired_capabilities=d
481-
)
499+
if remote_host:
500+
selenium_driver = webdriver.Remote(
501+
command_executor= remote_host + "wd/hub",
502+
options=options,
503+
desired_capabilities=d
504+
)
505+
else:
506+
selenium_driver = webdriver.Chrome(
507+
executable_path=chrome_path,
508+
chrome_options=options,
509+
desired_capabilities=d
510+
)
482511
selenium_driver.implicitly_wait(WebDriver_Wait)
483512
if not window_size_X and not window_size_Y:
484513
selenium_driver.set_window_size(default_x, default_y)
@@ -502,6 +531,10 @@ def Open_Browser(dependency, window_size_X=None, window_size_Y=None, capability=
502531
from sys import platform as _platform
503532
from selenium.webdriver.firefox.options import Options
504533
options = Options()
534+
535+
if remote_browser_version:
536+
options.set_capability("browserVersion",remote_browser_version)
537+
505538
if "headless" in browser:
506539
options.headless = True
507540
if _platform == "win32":
@@ -533,12 +566,20 @@ def Open_Browser(dependency, window_size_X=None, window_size_Y=None, capability=
533566
apps = "application/pdf;text/plain;application/text;text/xml;application/xml;application/xlsx;application/csv;application/zip"
534567
profile.set_preference("browser.helperApps.neverAsk.saveToDisk", apps)
535568
profile.accept_untrusted_certs = True
536-
selenium_driver = webdriver.Firefox(
537-
executable_path=firefox_path,
538-
capabilities=capabilities,
539-
options=options,
540-
firefox_profile=profile
541-
)
569+
if(remote_host):
570+
selenium_driver = webdriver.Remote(
571+
command_executor= remote_host + "wd/hub",
572+
options=options,
573+
desired_capabilities=capabilities,
574+
browser_profile=profile
575+
)
576+
else:
577+
selenium_driver = webdriver.Firefox(
578+
executable_path=firefox_path,
579+
capabilities=capabilities,
580+
options=options,
581+
firefox_profile=profile
582+
)
542583
selenium_driver.implicitly_wait(WebDriver_Wait)
543584
if not window_size_X and not window_size_Y:
544585
selenium_driver.set_window_size(default_x, default_y)
@@ -565,15 +606,28 @@ def Open_Browser(dependency, window_size_X=None, window_size_Y=None, capability=
565606
"""
566607
from Framework.edge_module.msedge.selenium_tools import EdgeOptions, Edge
567608
download_dir = ConfigModule.get_config_value("sectionOne", "initial_download_folder", temp_config)
568-
options = EdgeOptions()
569-
capabilities = EdgeOptions().capabilities
609+
options = webdriver.EdgeOptions()
610+
611+
if remote_browser_version:
612+
options.set_capability("browserVersion",remote_browser_version)
613+
capabilities = webdriver.EdgeOptions().capabilities
570614
capabilities['acceptSslCerts'] = True
571615
options.use_chromium = True
572616
options.headless = "headless" in browser
573617
options.add_experimental_option("prefs", {"download.default_directory": download_dir})
574618
options.add_argument('--zeuz_pid_finder')
575-
selenium_driver = Edge(executable_path=edge_path, options=options, capabilities=capabilities)
576-
619+
if(remote_host):
620+
selenium_driver = webdriver.Remote(
621+
command_executor= remote_host + "wd/hub",
622+
options=options,
623+
desired_capabilities=capabilities
624+
)
625+
else:
626+
selenium_driver = Edge(
627+
executable_path=edge_path,
628+
options=options,
629+
capabilities=capabilities
630+
)
577631
selenium_driver.implicitly_wait(WebDriver_Wait)
578632
if not window_size_X and not window_size_Y:
579633
selenium_driver.set_window_size(default_x, default_y)
@@ -803,7 +857,7 @@ def Go_To_Link(step_data, page_title=False):
803857
else:
804858
# any other shared capabilities can be added from the selenium document
805859
capabilities[left.strip()] = right.strip()
806-
860+
807861
# Todo: profile, argument, extension, chrome option => go_to_link
808862
elif mid.strip().lower() in ("chrome option", "chrome options") and dependency["Browser"].lower() == "chrome":
809863
browser_options.append([left, right.strip()])
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# To execute this docker-compose yml file use `docker-compose -f docker-compose-v3.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-video.yml down`
4+
version: "3"
5+
services:
6+
chrome:
7+
image: selenium/node-chrome:4.3.0-20220628
8+
shm_size: 2gb
9+
depends_on:
10+
- selenium-hub
11+
environment:
12+
- SE_EVENT_BUS_HOST=selenium-hub
13+
- SE_EVENT_BUS_PUBLISH_PORT=4442
14+
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
15+
chrome_2:
16+
image: selenium/node-chrome:102.0-20220609
17+
shm_size: 2gb
18+
depends_on:
19+
- selenium-hub
20+
environment:
21+
- SE_EVENT_BUS_HOST=selenium-hub
22+
- SE_EVENT_BUS_PUBLISH_PORT=4442
23+
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
24+
edge:
25+
image: selenium/node-edge:4.3.0-20220628
26+
shm_size: 2gb
27+
depends_on:
28+
- selenium-hub
29+
environment:
30+
- SE_EVENT_BUS_HOST=selenium-hub
31+
- SE_EVENT_BUS_PUBLISH_PORT=4442
32+
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
33+
34+
firefox:
35+
image: selenium/node-firefox:4.3.0-20220628
36+
shm_size: 2gb
37+
depends_on:
38+
- selenium-hub
39+
environment:
40+
- SE_EVENT_BUS_HOST=selenium-hub
41+
- SE_EVENT_BUS_PUBLISH_PORT=4442
42+
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
43+
44+
chrome_video:
45+
image: selenium/video:ffmpeg-4.3.1-20220628
46+
volumes:
47+
- ./videos:/videos
48+
depends_on:
49+
- chrome
50+
environment:
51+
- DISPLAY_CONTAINER_NAME=chrome
52+
- FILE_NAME=chrome_video.mp4
53+
54+
edge_video:
55+
image: selenium/video:ffmpeg-4.3.1-20220628
56+
volumes:
57+
- ./videos:/videos
58+
depends_on:
59+
- edge
60+
environment:
61+
- DISPLAY_CONTAINER_NAME=edge
62+
- FILE_NAME=edge_video.mp4
63+
64+
firefox_video:
65+
image: selenium/video:ffmpeg-4.3.1-20220628
66+
volumes:
67+
- ./videos:/videos
68+
depends_on:
69+
- firefox
70+
environment:
71+
- DISPLAY_CONTAINER_NAME=firefox
72+
- FILE_NAME=firefox_video.mp4
73+
74+
selenium-hub:
75+
image: selenium/hub:4.3.0-20220628
76+
container_name: selenium-hub
77+
ports:
78+
- "4442:4442"
79+
- "4443:4443"
80+
- "4444:4444"

0 commit comments

Comments
 (0)