Skip to content

Commit ce7b83a

Browse files
authored
Merge pull request #151 from seleniumbase/update-chrome-options-and-proxy
Update chrome options; update valid proxy input; and add a method
2 parents 59ddf8a + c65d86e commit ce7b83a

File tree

7 files changed

+120
-76
lines changed

7 files changed

+120
-76
lines changed

help_docs/method_summary.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ self.maximize_window()
8585

8686
self.activate_jquery()
8787

88+
self.get_property_value(selector, property, by=By.CSS_SELECTOR,
89+
timeout=settings.SMALL_TIMEOUT)
90+
8891
self.bring_to_front(selector, by=By.CSS_SELECTOR)
8992

9093
self.highlight(selector, by=By.CSS_SELECTOR, loops=4, scroll=True)

help_docs/webdriver_installation.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
## Installing Google Chromedriver, Firefox Geckodriver, and other drivers
22

33

4-
To run automation on various web browsers, you'll need to download a driver file for each one and place it on your System **[PATH](http://java.com/en/download/help/path.xml)**. On a Mac, ``/usr/local/bin`` is a good spot. On Windows, make sure you set the System Path under Environment Variables to include the location where you placed the driver files:
4+
To run automation on various web browsers, you'll need to download a driver file for each one and place it on your System **[PATH](http://java.com/en/download/help/path.xml)**. On a Mac, ``/usr/local/bin`` is a good spot. On Windows, make sure you set the System Path under Environment Variables to include the location where you placed the driver files. You may want to download newer versions of drivers as they become available.
55

6-
* For Chrome, get [Chromedriver](https://sites.google.com/a/chromium.org/chromedriver/downloads) on your System Path. (**[Version 2.37](https://chromedriver.storage.googleapis.com/index.html?path=2.37/) or above is recommended!**)
6+
* For Chrome, get [Chromedriver](https://sites.google.com/a/chromium.org/chromedriver/downloads) on your System Path.
77

88
* For Firefox, get [Geckodriver](https://github.com/mozilla/geckodriver/releases) on your System Path.
99

@@ -34,15 +34,15 @@ brew upgrade geckodriver
3434
Linux:
3535

3636
```bash
37-
wget http://chromedriver.storage.googleapis.com/2.36/chromedriver_linux64.zip
37+
wget http://chromedriver.storage.googleapis.com/2.37/chromedriver_linux64.zip
3838
unzip chromedriver_linux64.zip
3939
mv chromedriver /usr/local/bin/
4040
chmod +x /usr/local/bin/chromedriver
4141
```
4242

4343
```bash
44-
wget https://github.com/mozilla/geckodriver/releases/download/v0.19.1/geckodriver-v0.19.1-linux64.tar.gz
45-
tar xvfz geckodriver-v0.19.1-linux64.tar.gz
44+
wget https://github.com/mozilla/geckodriver/releases/download/v0.20.0/geckodriver-v0.20.0-linux64.tar.gz
45+
tar xvfz geckodriver-v0.20.0-linux64.tar.gz
4646
mv geckodriver /usr/local/bin/
4747
chmod +x /usr/local/bin/geckodriver
4848
```

seleniumbase/config/proxy_list.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
PROXY_LIST = {
2121
# "example1": "35.196.26.166:3128", # (Example) - set your own proxy here
22-
# "example2": "208.95.62.81:3128", # (Example) - set your own proxy here
2322
"proxy1": None,
2423
"proxy2": None,
2524
"proxy3": None,

seleniumbase/core/browser_launcher.py

Lines changed: 63 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,38 @@
77
from seleniumbase.config import proxy_list
88
from seleniumbase.core import download_helper
99
from seleniumbase.fixtures import constants
10+
from seleniumbase.fixtures import page_utils
11+
12+
13+
def _set_chrome_options(downloads_path, proxy_string):
14+
chrome_options = webdriver.ChromeOptions()
15+
prefs = {
16+
"download.default_directory": downloads_path,
17+
"credentials_enable_service": False,
18+
"profile": {
19+
"password_manager_enabled": False
20+
}
21+
}
22+
chrome_options.add_experimental_option("prefs", prefs)
23+
chrome_options.add_argument("--test-type")
24+
chrome_options.add_argument("--no-first-run")
25+
chrome_options.add_argument("--ignore-certificate-errors")
26+
chrome_options.add_argument("--allow-file-access-from-files")
27+
chrome_options.add_argument("--allow-insecure-localhost")
28+
chrome_options.add_argument("--allow-running-insecure-content")
29+
chrome_options.add_argument("--disable-infobars")
30+
chrome_options.add_argument("--disable-save-password-bubble")
31+
chrome_options.add_argument("--disable-single-click-autofill")
32+
chrome_options.add_argument("--disable-translate")
33+
chrome_options.add_argument("--disable-web-security")
34+
if proxy_string:
35+
chrome_options.add_argument('--proxy-server=%s' % proxy_string)
36+
if settings.START_CHROME_IN_FULL_SCREEN_MODE:
37+
# Run Chrome in full screen mode on WINDOWS
38+
chrome_options.add_argument("--start-maximized")
39+
# Run Chrome in full screen mode on MAC/Linux
40+
chrome_options.add_argument("--kiosk")
41+
return chrome_options
1042

1143

1244
def _create_firefox_profile(downloads_path, proxy_string):
@@ -42,8 +74,8 @@ def _create_firefox_profile(downloads_path, proxy_string):
4274

4375
def display_proxy_warning(proxy_string):
4476
message = ('\n\nWARNING: Proxy String ["%s"] is NOT in the expected '
45-
'"ip_address:port" format, (OR the key does not exist '
46-
'in proxy_list.PROXY_LIST). '
77+
'"ip_address:port" or "server:port" format, '
78+
'(OR the key does not exist in proxy_list.PROXY_LIST). '
4779
'*** DEFAULTING to NOT USING a Proxy Server! ***'
4880
% proxy_string)
4981
warnings.simplefilter('always', Warning) # See Warnings
@@ -56,10 +88,24 @@ def validate_proxy_string(proxy_string):
5688
proxy_string = proxy_list.PROXY_LIST[proxy_string]
5789
if not proxy_string:
5890
return None
59-
valid = re.match('^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d+$', proxy_string)
60-
if valid:
61-
proxy_string = valid.group()
91+
valid = False
92+
val_ip = re.match('^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d+$', proxy_string)
93+
if not val_ip:
94+
if proxy_string.startswith('http://'):
95+
proxy_string = proxy_string.split('http://')[1]
96+
elif proxy_string.startswith('https://'):
97+
proxy_string = proxy_string.split('https://')[1]
98+
elif '://' in proxy_string:
99+
proxy_string = proxy_string.split('://')[1]
100+
chunks = proxy_string.split(':')
101+
if len(chunks) == 2:
102+
if re.match('^\d+$', chunks[1]):
103+
if page_utils.is_valid_url('http://' + proxy_string):
104+
valid = True
62105
else:
106+
proxy_string = val_ip.group()
107+
valid = True
108+
if not valid:
63109
display_proxy_warning(proxy_string)
64110
proxy_string = None
65111
return proxy_string
@@ -82,33 +128,14 @@ def get_remote_driver(browser_name, headless, servername, port, proxy_string):
82128
address = "http://%s:%s/wd/hub" % (servername, port)
83129

84130
if browser_name == constants.Browser.GOOGLE_CHROME:
85-
chrome_options = webdriver.ChromeOptions()
86-
prefs = {
87-
"download.default_directory": downloads_path,
88-
"credentials_enable_service": False,
89-
"profile": {
90-
"password_manager_enabled": False
91-
}
92-
}
93-
chrome_options.add_experimental_option("prefs", prefs)
94-
chrome_options.add_argument("--allow-file-access-from-files")
95-
chrome_options.add_argument("--allow-running-insecure-content")
96-
chrome_options.add_argument("--disable-infobars")
131+
chrome_options = _set_chrome_options(downloads_path, proxy_string)
97132
if headless:
98133
chrome_options.add_argument("--headless")
99-
if proxy_string:
100-
chrome_options.add_argument('--proxy-server=%s' % proxy_string)
101-
if settings.START_CHROME_IN_FULL_SCREEN_MODE:
102-
# Run Chrome in full screen mode on WINDOWS
103-
chrome_options.add_argument("--start-maximized")
104-
# Run Chrome in full screen mode on MAC/Linux
105-
chrome_options.add_argument("--kiosk")
106134
capabilities = chrome_options.to_capabilities()
107135
return webdriver.Remote(
108136
command_executor=address,
109137
desired_capabilities=capabilities)
110-
111-
if browser_name == constants.Browser.FIREFOX:
138+
elif browser_name == constants.Browser.FIREFOX:
112139
try:
113140
# Use Geckodriver for Firefox if it's on the PATH
114141
profile = _create_firefox_profile(downloads_path, proxy_string)
@@ -136,23 +163,22 @@ def get_remote_driver(browser_name, headless, servername, port, proxy_string):
136163
command_executor=address,
137164
desired_capabilities=capabilities,
138165
browser_profile=profile)
139-
140-
if browser_name == constants.Browser.INTERNET_EXPLORER:
166+
elif browser_name == constants.Browser.INTERNET_EXPLORER:
141167
return webdriver.Remote(
142168
command_executor=address,
143169
desired_capabilities=(
144170
webdriver.DesiredCapabilities.INTERNETEXPLORER))
145-
if browser_name == constants.Browser.EDGE:
171+
elif browser_name == constants.Browser.EDGE:
146172
return webdriver.Remote(
147173
command_executor=address,
148174
desired_capabilities=(
149175
webdriver.DesiredCapabilities.EDGE))
150-
if browser_name == constants.Browser.SAFARI:
176+
elif browser_name == constants.Browser.SAFARI:
151177
return webdriver.Remote(
152178
command_executor=address,
153179
desired_capabilities=(
154180
webdriver.DesiredCapabilities.SAFARI))
155-
if browser_name == constants.Browser.PHANTOM_JS:
181+
elif browser_name == constants.Browser.PHANTOM_JS:
156182
with warnings.catch_warnings():
157183
# Ignore "PhantomJS has been deprecated" UserWarning
158184
warnings.simplefilter("ignore", category=UserWarning)
@@ -195,40 +221,22 @@ def get_local_driver(browser_name, headless, proxy_string):
195221
if headless:
196222
raise Exception(e)
197223
return webdriver.Firefox()
198-
if browser_name == constants.Browser.INTERNET_EXPLORER:
224+
elif browser_name == constants.Browser.INTERNET_EXPLORER:
199225
return webdriver.Ie()
200-
if browser_name == constants.Browser.EDGE:
226+
elif browser_name == constants.Browser.EDGE:
201227
return webdriver.Edge()
202-
if browser_name == constants.Browser.SAFARI:
228+
elif browser_name == constants.Browser.SAFARI:
203229
return webdriver.Safari()
204-
if browser_name == constants.Browser.PHANTOM_JS:
230+
elif browser_name == constants.Browser.PHANTOM_JS:
205231
with warnings.catch_warnings():
206232
# Ignore "PhantomJS has been deprecated" UserWarning
207233
warnings.simplefilter("ignore", category=UserWarning)
208234
return webdriver.PhantomJS()
209-
if browser_name == constants.Browser.GOOGLE_CHROME:
235+
elif browser_name == constants.Browser.GOOGLE_CHROME:
210236
try:
211-
chrome_options = webdriver.ChromeOptions()
212-
prefs = {
213-
"download.default_directory": downloads_path,
214-
"credentials_enable_service": False,
215-
"profile": {
216-
"password_manager_enabled": False
217-
}
218-
}
219-
chrome_options.add_experimental_option("prefs", prefs)
220-
chrome_options.add_argument("--allow-file-access-from-files")
221-
chrome_options.add_argument("--allow-running-insecure-content")
222-
chrome_options.add_argument("--disable-infobars")
237+
chrome_options = _set_chrome_options(downloads_path, proxy_string)
223238
if headless:
224239
chrome_options.add_argument("--headless")
225-
if proxy_string:
226-
chrome_options.add_argument('--proxy-server=%s' % proxy_string)
227-
if settings.START_CHROME_IN_FULL_SCREEN_MODE:
228-
# Run Chrome in full screen mode on WINDOWS
229-
chrome_options.add_argument("--start-maximized")
230-
# Run Chrome in full screen mode on MAC/Linux
231-
chrome_options.add_argument("--kiosk")
232240
return webdriver.Chrome(options=chrome_options)
233241
except Exception as e:
234242
if headless:

seleniumbase/fixtures/base_case.py

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,12 @@ def get_link_attribute(self, link_text, attribute, hard_fail=True):
198198
return attribute_value
199199
if hard_fail:
200200
raise Exception(
201-
'Unable to find attribute [%s] from link text [%s]!'
201+
'Unable to find attribute {%s} from link text {%s}!'
202202
% (attribute, link_text))
203203
else:
204204
return None
205205
if hard_fail:
206-
raise Exception("Link text [%s] was not found!" % link_text)
206+
raise Exception("Link text {%s} was not found!" % link_text)
207207
else:
208208
return None
209209

@@ -214,15 +214,15 @@ def wait_for_link_text_present(self, link_text,
214214
for x in range(int(timeout * 5)):
215215
try:
216216
if not self.is_link_text_present(link_text):
217-
raise Exception("Link text [%s] not found!" % link_text)
217+
raise Exception("Link text {%s} not found!" % link_text)
218218
return
219219
except Exception:
220220
now_ms = time.time() * 1000.0
221221
if now_ms >= stop_ms:
222222
break
223223
time.sleep(0.2)
224224
raise Exception(
225-
"Link text [%s] was not present after %s seconds!" % (
225+
"Link text {%s} was not present after %s seconds!" % (
226226
link_text, timeout))
227227

228228
def click_link_text(self, link_text, timeout=settings.SMALL_TIMEOUT):
@@ -336,9 +336,9 @@ def click_partial_link_text(self, partial_link_text,
336336
return
337337
raise Exception(
338338
'Could not parse link from partial link_text '
339-
'[%s]' % partial_link_text)
339+
'{%s}' % partial_link_text)
340340
raise Exception(
341-
"Partial link text [%s] was not found!" % partial_link_text)
341+
"Partial link text {%s} was not found!" % partial_link_text)
342342
# Not using phantomjs
343343
element = self.wait_for_partial_link_text(
344344
partial_link_text, timeout=timeout)
@@ -405,7 +405,7 @@ def get_attribute(self, selector, attribute, by=By.CSS_SELECTOR,
405405
if attribute_value is not None:
406406
return attribute_value
407407
else:
408-
raise Exception("Element [%s] has no attribute [%s]!" % (
408+
raise Exception("Element {%s} has no attribute {%s}!" % (
409409
selector, attribute))
410410

411411
def refresh_page(self):
@@ -706,6 +706,40 @@ def activate_jquery(self):
706706
# Since jQuery still isn't activating, give up and raise an exception
707707
raise Exception("Exception: WebDriver could not activate jQuery!")
708708

709+
def get_property_value(self, selector, property, by=By.CSS_SELECTOR,
710+
timeout=settings.SMALL_TIMEOUT):
711+
""" Returns the property value of a page element's computed style.
712+
Example:
713+
opacity = self.get_property_value("html body a", "opacity")
714+
self.assertTrue(float(opacity) > 0, "Element not visible!") """
715+
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
716+
timeout = self._get_new_timeout(timeout)
717+
if page_utils.is_xpath_selector(selector):
718+
by = By.XPATH
719+
if page_utils.is_link_text_selector(selector):
720+
selector = page_utils.get_link_text_from_selector(selector)
721+
by = By.LINK_TEXT
722+
self.wait_for_ready_state_complete()
723+
page_actions.wait_for_element_present(
724+
self.driver, selector, by, timeout)
725+
try:
726+
selector = self.convert_to_css_selector(selector, by=by)
727+
except Exception:
728+
# Don't run action if can't convert to CSS_Selector for JavaScript
729+
raise Exception(
730+
"Exception: Could not convert {%s}(by=%s) to CSS_SELECTOR!" % (
731+
selector, by))
732+
selector = self.jq_format(selector)
733+
script = ("""var $elm = document.querySelector('%s');
734+
$val = window.getComputedStyle($elm).getPropertyValue('%s');
735+
return $val;"""
736+
% (selector, property))
737+
value = self.execute_script(script)
738+
if value is not None:
739+
return value
740+
else:
741+
return "" # Return an empty string if the property doesn't exist
742+
709743
def bring_to_front(self, selector, by=By.CSS_SELECTOR):
710744
""" Updates the Z-index of a page element to bring it into view.
711745
Useful when getting a WebDriverException, such as the one below:
@@ -717,10 +751,10 @@ def bring_to_front(self, selector, by=By.CSS_SELECTOR):
717751
try:
718752
selector = self.convert_to_css_selector(selector, by=by)
719753
except Exception:
720-
# Don't perform action if can't convert to CSS_SELECTOR for jQuery
754+
# Don't run action if can't convert to CSS_Selector for JavaScript
721755
return
722-
723-
script = ("""document.querySelector('%s').style.zIndex = "1";"""
756+
selector = self.jq_format(selector)
757+
script = ("""document.querySelector('%s').style.zIndex = "100";"""
724758
% selector)
725759
self.execute_script(script)
726760

@@ -960,7 +994,7 @@ def convert_to_css_selector(self, selector, by):
960994
return 'a:contains("%s")' % selector
961995
else:
962996
raise Exception(
963-
"Exception: Could not convert [%s](by=%s) to CSS_SELECTOR!" % (
997+
"Exception: Could not convert {%s}(by=%s) to CSS_SELECTOR!" % (
964998
selector, by))
965999

9661000
def set_value(self, selector, new_value, by=By.CSS_SELECTOR,
@@ -1081,12 +1115,12 @@ def generate_referral(self, start_page, destination_page):
10811115
(This generates real traffic for testing analytics software.) """
10821116
if not page_utils.is_valid_url(destination_page):
10831117
raise Exception(
1084-
"Exception: destination_page [%s] is not a valid URL!"
1118+
"Exception: destination_page {%s} is not a valid URL!"
10851119
% destination_page)
10861120
if start_page:
10871121
if not page_utils.is_valid_url(start_page):
10881122
raise Exception(
1089-
"Exception: start_page [%s] is not a valid URL! "
1123+
"Exception: start_page {%s} is not a valid URL! "
10901124
"(Use an empty string or None to start from current page.)"
10911125
% start_page)
10921126
self.open(start_page)

server_setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
setup(
99
name='seleniumbase',
10-
version='1.7.4',
10+
version='1.7.5',
1111
description='Web Automation & Testing Framework - http://seleniumbase.com',
1212
long_description='Web Automation and Testing Framework - seleniumbase.com',
1313
platforms='Mac * Windows * Linux * Docker',

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
setup(
99
name='seleniumbase',
10-
version='1.7.4',
10+
version='1.7.5',
1111
description='Web Automation & Testing Framework - http://seleniumbase.com',
1212
long_description='Web Automation and Testing Framework - seleniumbase.com',
1313
platforms='Mac * Windows * Linux * Docker',

0 commit comments

Comments
 (0)