Skip to content

Commit 8da46dd

Browse files
authored
Merge pull request #137 from seleniumbase/reliability
Improve Reliability
2 parents 684c977 + 7cc4a38 commit 8da46dd

16 files changed

+62
-62
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ before_script:
2828
- sudo cp chromedriver /usr/local/bin/
2929
- sudo chmod +x /usr/local/bin/chromedriver
3030
script:
31-
- "nosetests examples/my_first_test.py --with-selenium --browser=chrome -s"
32-
- "pytest examples/my_first_test.py --with-selenium --browser=firefox -s"
33-
- "pytest examples/my_first_test.py --with-selenium --browser=phantomjs"
31+
- "nosetests examples/my_first_test.py --browser=chrome -s"
32+
- "pytest examples/my_first_test.py --browser=firefox -s"
33+
- "pytest examples/my_first_test.py --browser=phantomjs"
3434
notifications:
3535
email: false

examples/gui_test_runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
try:
77
# Python 2
88
from Tkinter import Tk, Frame, Button, Label
9-
except:
9+
except Exception:
1010
# Python 3
1111
from tkinter import Tk, Frame, Button, Label
1212
import os

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ nose==1.3.7
66
pytest==3.4.0
77
pytest-html==1.16.1
88
six==1.10.0
9-
flake8==3.4.1
9+
flake8==3.5.0
1010
requests==2.18.4
1111
BeautifulSoup4==4.6.0
1212
unittest2==1.1.0

seleniumbase/common/encryption.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def str_xor(string, key):
1919
try:
2020
result = "".join(
2121
[chr(ord(c1) ^ ord(c2)) for (c1, c2) in zip(string, key)])
22-
except:
22+
except Exception:
2323
string = string.decode('utf-8')
2424
result = "".join(
2525
[chr(ord(c1) ^ ord(c2)) for (c1, c2) in zip(string, key)])
@@ -80,7 +80,7 @@ def ord_string_sum(string):
8080
try:
8181
for c in string:
8282
count += ord(c)
83-
except:
83+
except Exception:
8484
string = string.decode('utf-8')
8585
for c in string:
8686
count += ord(c)

seleniumbase/common/obfuscate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def main():
2626
time.sleep(0.07)
2727
print(encryption.decrypt(password))
2828
time.sleep(0.21)
29-
except:
29+
except KeyboardInterrupt:
3030
print("\nExiting...\n")
3131

3232

seleniumbase/common/unobfuscate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def main():
1616
try:
1717
# Python 2 has the raw_input() method. Python 3 does not.
1818
input_method = raw_input # noqa: ignore=F821
19-
except:
19+
except Exception:
2020
input_method = input # Using Python 3
2121
try:
2222
while(1):
@@ -26,7 +26,7 @@ def main():
2626
time.sleep(0.07)
2727
print(encryption.decrypt(code))
2828
time.sleep(0.21)
29-
except:
29+
except KeyboardInterrupt:
3030
print("\nExiting...\n")
3131

3232

seleniumbase/config/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# Default seconds to wait for page elements to appear before performing actions
1212
TINY_TIMEOUT = 0.1
1313
MINI_TIMEOUT = 2
14-
SMALL_TIMEOUT = 5
14+
SMALL_TIMEOUT = 6
1515
LARGE_TIMEOUT = 10
1616
EXTREME_TIMEOUT = 30
1717

seleniumbase/core/browser_launcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def get_local_driver(browser_name, headless):
147147
firefox_driver = webdriver.Firefox(
148148
firefox_profile=profile, capabilities=firefox_capabilities)
149149
return firefox_driver
150-
except:
150+
except Exception:
151151
return webdriver.Firefox()
152152
if browser_name == constants.Browser.INTERNET_EXPLORER:
153153
return webdriver.Ie()

seleniumbase/core/log_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def log_test_failure_data(test, test_logpath, driver, browser):
2626
traceback_list = traceback.format_list(
2727
traceback.extract_tb(traceback_address)[1:])
2828
traceback_message = ''.join(traceback_list).strip()
29-
except:
29+
except Exception:
3030
exc_message = "(Unknown Exception)"
3131
traceback_message = "(Unknown Traceback)"
3232
data_to_save.append("Traceback: " + traceback_message)

seleniumbase/core/s3_manager.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
class S3LoggingBucket(object):
1212
"""
13-
A class to upload our log files from tests to S3, from
14-
whence we can share them.
13+
A class to upload log files from tests to S3.
14+
Those files can then be shared easily.
1515
"""
1616

1717
def __init__(self,
@@ -26,16 +26,16 @@ def __init__(self,
2626
self.bucket_url = bucket_url
2727

2828
def get_key(self, _name):
29-
"""create a new Key instance with the given name"""
29+
""" Create a new Key instance with the given name. """
3030
return Key(bucket=self.bucket, name=_name)
3131

3232
def get_bucket(self):
33-
"""return the bucket we're using"""
33+
""" Return the bucket being used. """
3434
return self.bucket
3535

3636
def upload_file(self, file_name, file_path):
37-
"""upload a given file from the file_path to the bucket
38-
with the new name/path file_name"""
37+
""" Upload a given file from the file_path to the bucket
38+
with the new name/path file_name. """
3939
upload_key = Key(bucket=self.bucket, name=file_name)
4040
content_type = "text/plain"
4141
if file_name.endswith(".html"):
@@ -51,13 +51,13 @@ def upload_file(self, file_name, file_path):
5151
upload_key.generate_url(expires_in=3600).split("?")[0]
5252
try:
5353
upload_key.make_public()
54-
except:
54+
except Exception:
5555
pass
5656
return file_name
5757

5858
def upload_index_file(self, test_address, timestamp):
59-
"""create an index.html file with links to all the log files we
60-
just uploaded"""
59+
""" Create an index.html file with links to all the log files we
60+
just uploaded. """
6161
global already_uploaded_files
6262
already_uploaded_files = list(set(already_uploaded_files))
6363
already_uploaded_files.sort()
@@ -74,8 +74,8 @@ def upload_index_file(self, test_address, timestamp):
7474
return "%s%s" % (self.bucket_url, file_name)
7575

7676
def save_uploaded_file_names(self, files):
77-
"""We keep record of file names that have been uploaded. We upload log
78-
files related to each test after its execution. Once we're done, we
79-
use already_uploaded_files to create an index file"""
77+
""" Keep a record of all file names that've been uploaded. Upload log
78+
files related to each test after its execution. Once done, use
79+
already_uploaded_files to create an index file. """
8080
global already_uploaded_files
8181
already_uploaded_files.extend(files)

seleniumbase/fixtures/base_case.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,10 @@ def get_image_url(self, selector, by=By.CSS_SELECTOR,
339339
attribute='src', by=by, timeout=timeout)
340340

341341
def add_text(self, selector, new_value, by=By.CSS_SELECTOR,
342-
timeout=settings.SMALL_TIMEOUT):
342+
timeout=settings.LARGE_TIMEOUT):
343343
""" The more-reliable version of driver.send_keys()
344344
Similar to update_text(), but won't clear the text field first. """
345-
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
345+
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
346346
timeout = self._get_new_timeout(timeout)
347347
if page_utils.is_xpath_selector(selector):
348348
by = By.XPATH
@@ -382,16 +382,16 @@ def add_text(self, selector, new_value, by=By.CSS_SELECTOR,
382382
self._demo_mode_pause_if_active(tiny=True)
383383

384384
def send_keys(self, selector, new_value, by=By.CSS_SELECTOR,
385-
timeout=settings.SMALL_TIMEOUT):
385+
timeout=settings.LARGE_TIMEOUT):
386386
""" Same as add_text() -> more reliable, but less name confusion. """
387-
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
387+
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
388388
timeout = self._get_new_timeout(timeout)
389389
if page_utils.is_xpath_selector(selector):
390390
by = By.XPATH
391391
self.add_text(selector, new_value, by=by, timeout=timeout)
392392

393393
def update_text_value(self, selector, new_value, by=By.CSS_SELECTOR,
394-
timeout=settings.SMALL_TIMEOUT, retry=False):
394+
timeout=settings.LARGE_TIMEOUT, retry=False):
395395
""" This method updates an element's text value with a new value.
396396
@Params
397397
selector - the selector with the value to update
@@ -400,7 +400,7 @@ def update_text_value(self, selector, new_value, by=By.CSS_SELECTOR,
400400
timeout - how long to wait for the selector to be visible
401401
retry - if True, use jquery if the selenium text update fails
402402
"""
403-
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
403+
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
404404
timeout = self._get_new_timeout(timeout)
405405
if page_utils.is_xpath_selector(selector):
406406
by = By.XPATH
@@ -456,11 +456,11 @@ def update_text_value(self, selector, new_value, by=By.CSS_SELECTOR,
456456
self._demo_mode_pause_if_active(tiny=True)
457457

458458
def update_text(self, selector, new_value, by=By.CSS_SELECTOR,
459-
timeout=settings.SMALL_TIMEOUT, retry=False):
459+
timeout=settings.LARGE_TIMEOUT, retry=False):
460460
""" The shorter version of update_text_value(), which
461461
clears existing text and adds new text into the text field.
462462
We want to keep the old version for backward compatibility. """
463-
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
463+
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
464464
timeout = self._get_new_timeout(timeout)
465465
if page_utils.is_xpath_selector(selector):
466466
by = By.XPATH
@@ -746,9 +746,9 @@ def convert_to_css_selector(self, selector, by):
746746
selector, by))
747747

748748
def set_value(self, selector, new_value, by=By.CSS_SELECTOR,
749-
timeout=settings.SMALL_TIMEOUT):
749+
timeout=settings.LARGE_TIMEOUT):
750750
""" This method uses jQuery to update a text field. """
751-
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
751+
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
752752
timeout = self._get_new_timeout(timeout)
753753
if page_utils.is_xpath_selector(selector):
754754
by = By.XPATH
@@ -772,12 +772,12 @@ def set_value(self, selector, new_value, by=By.CSS_SELECTOR,
772772
self._demo_mode_pause_if_active()
773773

774774
def jquery_update_text_value(self, selector, new_value, by=By.CSS_SELECTOR,
775-
timeout=settings.SMALL_TIMEOUT):
775+
timeout=settings.LARGE_TIMEOUT):
776776
""" This method uses jQuery to update a text field.
777777
If the new_value string ends with the newline character,
778778
WebDriver will finish the call, which simulates pressing
779779
{Enter/Return} after the text is entered. """
780-
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
780+
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
781781
timeout = self._get_new_timeout(timeout)
782782
if page_utils.is_xpath_selector(selector):
783783
by = By.XPATH
@@ -805,10 +805,10 @@ def jquery_update_text_value(self, selector, new_value, by=By.CSS_SELECTOR,
805805
self._demo_mode_pause_if_active()
806806

807807
def jquery_update_text(self, selector, new_value, by=By.CSS_SELECTOR,
808-
timeout=settings.SMALL_TIMEOUT):
808+
timeout=settings.LARGE_TIMEOUT):
809809
""" The shorter version of jquery_update_text_value()
810810
(The longer version remains for backwards compatibility.) """
811-
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
811+
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
812812
timeout = self._get_new_timeout(timeout)
813813
self.jquery_update_text_value(
814814
selector, new_value, by=by, timeout=timeout)
@@ -847,29 +847,29 @@ def hover_and_click(self, hover_selector, click_selector,
847847

848848
def pick_select_option_by_text(self, dropdown_selector, option,
849849
dropdown_by=By.CSS_SELECTOR,
850-
timeout=settings.SMALL_TIMEOUT):
850+
timeout=settings.LARGE_TIMEOUT):
851851
""" Picks an HTML <select> option by option text. """
852-
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
852+
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
853853
timeout = self._get_new_timeout(timeout)
854854
self._pick_select_option(dropdown_selector, option,
855855
dropdown_by=dropdown_by, option_by="text",
856856
timeout=timeout)
857857

858858
def pick_select_option_by_index(self, dropdown_selector, option,
859859
dropdown_by=By.CSS_SELECTOR,
860-
timeout=settings.SMALL_TIMEOUT):
860+
timeout=settings.LARGE_TIMEOUT):
861861
""" Picks an HTML <select> option by option index. """
862-
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
862+
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
863863
timeout = self._get_new_timeout(timeout)
864864
self._pick_select_option(dropdown_selector, option,
865865
dropdown_by=dropdown_by, option_by="index",
866866
timeout=timeout)
867867

868868
def pick_select_option_by_value(self, dropdown_selector, option,
869869
dropdown_by=By.CSS_SELECTOR,
870-
timeout=settings.SMALL_TIMEOUT):
870+
timeout=settings.LARGE_TIMEOUT):
871871
""" Picks an HTML <select> option by option value. """
872-
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
872+
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
873873
timeout = self._get_new_timeout(timeout)
874874
self._pick_select_option(dropdown_selector, option,
875875
dropdown_by=dropdown_by, option_by="value",
@@ -1170,7 +1170,7 @@ def _get_new_timeout(self, timeout):
11701170
timeout_multiplier = 0.5
11711171
timeout = int(math.ceil(timeout_multiplier * timeout))
11721172
return timeout
1173-
except:
1173+
except Exception:
11741174
# Wrong data type for timeout_multiplier (expecting int or float)
11751175
return timeout
11761176

@@ -1185,7 +1185,7 @@ def _get_exception_message(self):
11851185
if exception_info:
11861186
try:
11871187
exc_message = exception_info[0][1][1]
1188-
except:
1188+
except Exception:
11891189
exc_message = "(Unknown Exception)"
11901190
else:
11911191
exc_message = "(Unknown Exception)"
@@ -1474,7 +1474,7 @@ def _add_pytest_html_extra(self):
14741474
name='Screenshot')
14751475
self._html_report_extra.append(extra_url)
14761476
self._html_report_extra.append(extra_image)
1477-
except:
1477+
except Exception:
14781478
pass
14791479

14801480
def tearDown(self):
@@ -1541,8 +1541,8 @@ def tearDown(self):
15411541
self.driver.quit()
15421542
except AttributeError:
15431543
pass
1544-
except:
1545-
print("No driver to quit.")
1544+
except Exception:
1545+
pass
15461546
self.driver = None
15471547
if self.headless:
15481548
if self.headless_active:
@@ -1587,6 +1587,6 @@ def tearDown(self):
15871587
self.driver.quit()
15881588
except AttributeError:
15891589
pass
1590-
except:
1591-
print("No driver to quit.")
1590+
except Exception:
1591+
pass
15921592
self.driver = None

seleniumbase/plugins/pytest_plugin.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,16 @@ def pytest_runtest_teardown(item):
159159
try:
160160
if hasattr(self, 'driver') and self.driver:
161161
self.driver.quit()
162-
except:
162+
except Exception:
163163
pass
164164
try:
165165
if hasattr(self, 'headless') and self.headless:
166166
if self.headless_active:
167167
if hasattr(self, 'display') and self.display:
168168
self.display.stop()
169-
except:
169+
except Exception:
170170
pass
171-
except:
171+
except Exception:
172172
pass
173173

174174

@@ -182,5 +182,5 @@ def pytest_runtest_makereport(item, call):
182182
extra_report = item._testcase._html_report_extra
183183
extra = getattr(report, 'extra', [])
184184
report.extra = extra + extra_report
185-
except:
185+
except Exception:
186186
pass

seleniumbase/plugins/selenium_plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def afterTest(self, test):
125125
self.driver.quit()
126126
except AttributeError:
127127
pass
128-
except:
128+
except Exception:
129129
pass
130130
if self.options.headless:
131131
if self.headless_active:

server_requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ nose==1.3.7
66
pytest==3.4.0
77
pytest-html==1.16.1
88
six==1.10.0
9-
flake8==3.4.1
9+
flake8==3.5.0
1010
requests==2.18.4
1111
BeautifulSoup4==4.6.0
1212
unittest2==1.1.0

0 commit comments

Comments
 (0)