-
Notifications
You must be signed in to change notification settings - Fork 784
Expand file tree
/
Copy pathOpenBrowserExample.py
More file actions
132 lines (124 loc) · 4.18 KB
/
OpenBrowserExample.py
File metadata and controls
132 lines (124 loc) · 4.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
from robot.api import logger
from selenium import webdriver
from SeleniumLibrary.base import LibraryComponent, keyword
from SeleniumLibrary.keywords import BrowserManagementKeywords
from SeleniumLibrary.keywords.webdrivertools import WebDriverCreator
class OpenBrowserExample(LibraryComponent):
def __init__(self, ctx):
LibraryComponent.__init__(self, ctx)
self._new_creator = NewWebDriverCreator(self.log_dir)
@keyword
def open_browser(
self,
url,
browser="firefox",
alias=None,
remote_url=False,
desired_capabilities=None,
ff_profile_dir=None,
options=None,
service_log_path=None,
extra_dictionary=None,
executable_path=None,
service=None,
):
self._new_creator.extra_dictionary = extra_dictionary
browser_manager = BrowserManagementKeywords(self.ctx)
browser_manager._make_driver = self._make_driver
browser_manager.open_browser(
url,
browser=browser,
alias=alias,
remote_url=remote_url,
desired_capabilities=desired_capabilities,
ff_profile_dir=ff_profile_dir,
options=options,
service_log_path=service_log_path,
executable_path=executable_path,
service=service,
)
def _make_driver(
self,
browser,
desired_capabilities=None,
profile_dir=None,
remote=None,
options=None,
service_log_path=None,
executable_path=None,
service=None,
):
driver = self._new_creator.create_driver(
browser=browser,
desired_capabilities=desired_capabilities,
remote_url=remote,
profile_dir=profile_dir,
options=options,
service_log_path=service_log_path,
executable_path=executable_path,
service=None,
)
driver.set_script_timeout(self.ctx.timeout)
driver.implicitly_wait(self.ctx.implicit_wait)
if self.ctx.speed:
self._monkey_patch_speed(driver)
return driver
class NewWebDriverCreator(WebDriverCreator):
def create_driver(
self,
browser,
desired_capabilities,
remote_url,
profile_dir=None,
options=None,
service_log_path=None,
executable_path=None,
service=None,
):
self.browser_names["seleniumwire"] = "seleniumwire"
browser = self._normalise_browser_name(browser)
creation_method = self._get_creator_method(browser)
desired_capabilities = self._parse_capabilities(desired_capabilities, browser)
service_log_path = self._get_log_path(service_log_path)
options = self.selenium_options.create(self.browser_names.get(browser), options)
service = self.selenium_service.create(self.browser_names.get(browser), service)
if service_log_path:
logger.info("Browser driver log file created to: %s" % service_log_path)
self._create_directory(service_log_path)
if (
creation_method == self.create_firefox
or creation_method == self.create_headless_firefox
):
return creation_method(
desired_capabilities,
remote_url,
profile_dir,
options=options,
service_log_path=service_log_path,
service=service,
)
if creation_method == self.create_seleniumwire:
return creation_method(
desired_capabilities,
remote_url,
options=options,
service_log_path=service_log_path,
service=service,
)
return creation_method(
desired_capabilities,
remote_url,
options=options,
service_log_path=service_log_path,
service=service,
)
def create_seleniumwire(
self,
desired_capabilities,
remote_url,
options=None,
service_log_path=None,
service=None,
):
logger.info(self.extra_dictionary)
return webdriver.Chrome()