@@ -29,10 +29,98 @@ def _create_firefox_profile(downloads_path):
29
29
return profile
30
30
31
31
32
- def get_driver (browser_name , headless = False ):
32
+ def get_driver (browser_name , headless = False , use_grid = False ,
33
+ servername = 'localhost' , port = 4444 ):
34
+ if use_grid :
35
+ return get_remote_driver (browser_name , headless , servername , port )
36
+ else :
37
+ return get_local_driver (browser_name , headless )
38
+
39
+
40
+ def get_remote_driver (browser_name , headless , servername , port ):
41
+ downloads_path = download_helper .get_downloads_folder ()
42
+ download_helper .reset_downloads_folder ()
43
+ address = "http://%s:%s/wd/hub" % (servername , port )
44
+
45
+ if browser_name == constants .Browser .GOOGLE_CHROME :
46
+ chrome_options = webdriver .ChromeOptions ()
47
+ prefs = {
48
+ "download.default_directory" : downloads_path ,
49
+ "credentials_enable_service" : False ,
50
+ "profile" : {
51
+ "password_manager_enabled" : False
52
+ }
53
+ }
54
+ chrome_options .add_experimental_option ("prefs" , prefs )
55
+ chrome_options .add_argument ("--allow-file-access-from-files" )
56
+ chrome_options .add_argument ("--allow-running-insecure-content" )
57
+ chrome_options .add_argument ("--disable-infobars" )
58
+ if headless :
59
+ chrome_options .add_argument ("--headless" )
60
+ if settings .START_CHROME_IN_FULL_SCREEN_MODE :
61
+ # Run Chrome in full screen mode on WINDOWS
62
+ chrome_options .add_argument ("--start-maximized" )
63
+ # Run Chrome in full screen mode on MAC/Linux
64
+ chrome_options .add_argument ("--kiosk" )
65
+ capabilities = chrome_options .to_capabilities ()
66
+ return webdriver .Remote (
67
+ command_executor = address ,
68
+ desired_capabilities = capabilities )
69
+
70
+ if browser_name == constants .Browser .FIREFOX :
71
+ try :
72
+ # Use Geckodriver for Firefox if it's on the PATH
73
+ profile = _create_firefox_profile (downloads_path )
74
+ firefox_capabilities = DesiredCapabilities .FIREFOX .copy ()
75
+ firefox_capabilities ['marionette' ] = True
76
+ if headless :
77
+ firefox_capabilities ['moz:firefoxOptions' ] = (
78
+ {'args' : ['-headless' ]})
79
+ capabilities = firefox_capabilities
80
+ address = "http://%s:%s/wd/hub" % (servername , port )
81
+ return webdriver .Remote (
82
+ command_executor = address ,
83
+ desired_capabilities = capabilities ,
84
+ browser_profile = profile )
85
+ except WebDriverException :
86
+ # Don't use Geckodriver: Only works for old versions of Firefox
87
+ profile = _create_firefox_profile (downloads_path )
88
+ firefox_capabilities = DesiredCapabilities .FIREFOX .copy ()
89
+ firefox_capabilities ['marionette' ] = False
90
+ if headless :
91
+ firefox_capabilities ['moz:firefoxOptions' ] = (
92
+ {'args' : ['-headless' ]})
93
+ capabilities = firefox_capabilities
94
+ return webdriver .Remote (
95
+ command_executor = address ,
96
+ desired_capabilities = capabilities ,
97
+ browser_profile = profile )
98
+
99
+ if browser_name == constants .Browser .INTERNET_EXPLORER :
100
+ return webdriver .Remote (
101
+ command_executor = address ,
102
+ desired_capabilities = (
103
+ webdriver .DesiredCapabilities .INTERNETEXPLORER ))
104
+ if browser_name == constants .Browser .EDGE :
105
+ return webdriver .Remote (
106
+ command_executor = address ,
107
+ desired_capabilities = (
108
+ webdriver .DesiredCapabilities .EDGE ))
109
+ if browser_name == constants .Browser .SAFARI :
110
+ return webdriver .Remote (
111
+ command_executor = address ,
112
+ desired_capabilities = (
113
+ webdriver .DesiredCapabilities .SAFARI ))
114
+ if browser_name == constants .Browser .PHANTOM_JS :
115
+ return webdriver .Remote (
116
+ command_executor = address ,
117
+ desired_capabilities = (
118
+ webdriver .DesiredCapabilities .PHANTOMJS ))
119
+
120
+
121
+ def get_local_driver (browser_name , headless ):
33
122
'''
34
123
Spins up a new web browser and returns the driver.
35
- Tests that run with pytest spin up the browser from here.
36
124
Can also be used to spin up additional browsers for the same test.
37
125
'''
38
126
downloads_path = download_helper .get_downloads_folder ()
0 commit comments