Merge pull request #842 from seleniumbase/reliability-and-other-improvements

Reliability and other improvements
This commit is contained in:
Michael Mintz 2021-03-18 00:12:52 -04:00 committed by GitHub
commit 122ea92953
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 65 additions and 39 deletions

View File

@ -565,6 +565,14 @@ nosetests test_suite.py --report
See: [https://docs.qameta.io/allure/](https://docs.qameta.io/allure/#_pytest) See: [https://docs.qameta.io/allure/](https://docs.qameta.io/allure/#_pytest)
SeleniumBase no longer includes ``allure-pytest`` as part of installed dependencies. If you want to use it, install it first:
```bash
pip install allure-pytest
```
Now your tests can create Allure results files, which can be processed by Allure Reports.
```bash ```bash
pytest test_suite.py --alluredir=allure_results pytest test_suite.py --alluredir=allure_results
``` ```

View File

@ -11,8 +11,6 @@ jobs:
vmImage: 'Ubuntu-20.04' vmImage: 'Ubuntu-20.04'
strategy: strategy:
matrix: matrix:
Python2.7:
python.version: '2.7'
Python3.5: Python3.5:
python.version: '3.5' python.version: '3.5'
Python3.6: Python3.6:
@ -23,7 +21,7 @@ jobs:
python.version: '3.8' python.version: '3.8'
Python3.9: Python3.9:
python.version: '3.9' python.version: '3.9'
maxParallel: 6 maxParallel: 5
steps: steps:
- task: UsePythonVersion@0 - task: UsePythonVersion@0

View File

@ -1,4 +1,4 @@
regex>=2020.11.13 regex>=2021.3.17
tqdm>=4.59.0 tqdm>=4.59.0
livereload==2.6.3;python_version>="3.6" livereload==2.6.3;python_version>="3.6"
joblib==1.0.1;python_version>="3.6" joblib==1.0.1;python_version>="3.6"

View File

@ -1,5 +1,6 @@
""" """
This test is only for Microsoft Edge (Chromium)! This test is only for Microsoft Edge (Chromium)!
(Tested on Edge Version 89.0.774.54)
""" """
from seleniumbase import BaseCase from seleniumbase import BaseCase
@ -12,10 +13,10 @@ class EdgeTests(BaseCase):
print(' (Run this test using "--edge" or "--browser=edge")') print(' (Run this test using "--edge" or "--browser=edge")')
self.skip('Use "--edge" or "--browser=edge"') self.skip('Use "--edge" or "--browser=edge"')
self.open("edge://settings/help") self.open("edge://settings/help")
self.assert_element('img[alt="Edge logo"] + span') self.highlight('div[role="main"]')
self.highlight('#section_about div + div') self.highlight('img[srcset*="logo"]')
self.highlight('#section_about div + div > div') self.assert_text("Microsoft Edge", 'img[srcset*="logo"] + div')
self.highlight('img[alt="Edge logo"]') self.highlight('img[srcset*="logo"] + div span:nth-of-type(1)')
self.highlight('img[alt="Edge logo"] + span') self.highlight('img[srcset*="logo"] + div span:nth-of-type(2)')
self.highlight('#section_about div + div > div + div') self.highlight('span[aria-live="assertive"]')
self.highlight('#section_about div + div > div + div + div > div') self.highlight('a[href*="chromium"]')

View File

@ -4,7 +4,8 @@ packaging>=20.9
setuptools>=44.1.1;python_version<"3.5" setuptools>=44.1.1;python_version<"3.5"
setuptools>=50.3.2;python_version>="3.5" and python_version<"3.6" setuptools>=50.3.2;python_version>="3.5" and python_version<"3.6"
setuptools>=54.1.2;python_version>="3.6" setuptools>=54.1.2;python_version>="3.6"
setuptools-scm>=5.0.2 setuptools-scm==5.0.2;python_version<"3.6"
setuptools-scm>=6.0.1;python_version>="3.6"
wheel>=0.36.2 wheel>=0.36.2
attrs>=20.3.0 attrs>=20.3.0
PyYAML>=5.4.1;python_version>="3.6" PyYAML>=5.4.1;python_version>="3.6"
@ -80,8 +81,6 @@ Pillow==8.1.2;python_version>="3.6"
rich==9.13.0;python_version>="3.6" and python_version<"4.0" rich==9.13.0;python_version>="3.6" and python_version<"4.0"
tornado==5.1.1;python_version<"3.5" tornado==5.1.1;python_version<"3.5"
tornado==6.1;python_version>="3.5" tornado==6.1;python_version>="3.5"
allure-pytest==2.8.22;python_version<"3.5"
allure-pytest==2.8.36;python_version>="3.5"
pdfminer.six==20191110;python_version<"3.5" pdfminer.six==20191110;python_version<"3.5"
pdfminer.six==20201018;python_version>="3.5" pdfminer.six==20201018;python_version>="3.5"

View File

@ -1,2 +1,2 @@
# seleniumbase package # seleniumbase package
__version__ = "1.58.1" __version__ = "1.58.2"

View File

@ -116,12 +116,12 @@ def show_install_usage():
print(" sbase install chromedriver") print(" sbase install chromedriver")
print(" sbase install geckodriver") print(" sbase install geckodriver")
print(" sbase install edgedriver") print(" sbase install edgedriver")
print(" sbase install chromedriver 88") print(" sbase install chromedriver 89")
print(" sbase install chromedriver 88.0.4324.96") print(" sbase install chromedriver 89.0.4389.23")
print(" sbase install chromedriver latest") print(" sbase install chromedriver latest")
print(" sbase install chromedriver -p") print(" sbase install chromedriver -p")
print(" sbase install chromedriver latest -p") print(" sbase install chromedriver latest -p")
print(" sbase install edgedriver 88.0.705.74") print(" sbase install edgedriver 89.0.774.54")
print(" Output:") print(" Output:")
print(" Installs the chosen webdriver to seleniumbase/drivers/") print(" Installs the chosen webdriver to seleniumbase/drivers/")
print(" (chromedriver is required for Chrome automation)") print(" (chromedriver is required for Chrome automation)")

View File

@ -13,12 +13,12 @@ Example:
sbase install chromedriver sbase install chromedriver
sbase install geckodriver sbase install geckodriver
sbase install edgedriver sbase install edgedriver
sbase install chromedriver 88.0.4324.96 sbase install chromedriver 89.0.4389.23
sbase install chromedriver 88 sbase install chromedriver 89
sbase install chromedriver latest sbase install chromedriver latest
sbase install chromedriver -p sbase install chromedriver -p
sbase install chromedriver latest -p sbase install chromedriver latest -p
sbase install edgedriver 88.0.705.63 sbase install edgedriver 89.0.774.54
Output: Output:
Installs the chosen webdriver to seleniumbase/drivers/ Installs the chosen webdriver to seleniumbase/drivers/
(chromedriver is required for Chrome automation) (chromedriver is required for Chrome automation)
@ -43,8 +43,8 @@ DRIVER_DIR = os.path.dirname(os.path.realpath(drivers.__file__))
LOCAL_PATH = "/usr/local/bin/" # On Mac and Linux systems LOCAL_PATH = "/usr/local/bin/" # On Mac and Linux systems
DEFAULT_CHROMEDRIVER_VERSION = "2.44" # (Specify "latest" to get the latest) DEFAULT_CHROMEDRIVER_VERSION = "2.44" # (Specify "latest" to get the latest)
DEFAULT_GECKODRIVER_VERSION = "v0.29.0" DEFAULT_GECKODRIVER_VERSION = "v0.29.0"
DEFAULT_EDGEDRIVER_VERSION = "88.0.705.63" # (Looks for LATEST_STABLE first) DEFAULT_EDGEDRIVER_VERSION = "89.0.774.54" # (Looks for LATEST_STABLE first)
DEFAULT_OPERADRIVER_VERSION = "v.84.0.4147.89" DEFAULT_OPERADRIVER_VERSION = "v.88.0.4324.104"
def invalid_run_command(): def invalid_run_command():
@ -61,7 +61,8 @@ def invalid_run_command():
exp += " Example:\n" exp += " Example:\n"
exp += " seleniumbase install chromedriver\n" exp += " seleniumbase install chromedriver\n"
exp += " seleniumbase install geckodriver\n" exp += " seleniumbase install geckodriver\n"
exp += " seleniumbase install chromedriver 76.0.3809.126\n" exp += " seleniumbase install chromedriver 89\n"
exp += " seleniumbase install chromedriver 89.0.4389.23\n"
exp += " seleniumbase install chromedriver latest\n" exp += " seleniumbase install chromedriver latest\n"
exp += " seleniumbase install chromedriver -p\n" exp += " seleniumbase install chromedriver -p\n"
exp += " seleniumbase install chromedriver latest -p\n" exp += " seleniumbase install chromedriver latest -p\n"

View File

@ -1865,6 +1865,9 @@ class BaseCase(unittest.TestCase):
time.sleep(0.01) time.sleep(0.01)
if switch_to: if switch_to:
self.switch_to_window(len(self.driver.window_handles) - 1) self.switch_to_window(len(self.driver.window_handles) - 1)
time.sleep(0.01)
if self.browser == "safari":
self.wait_for_ready_state_complete()
def switch_to_window(self, window, timeout=None): def switch_to_window(self, window, timeout=None):
self.__check_scope() self.__check_scope()
@ -3149,6 +3152,7 @@ class BaseCase(unittest.TestCase):
start_ms = time.time() * 1000.0 start_ms = time.time() * 1000.0
stop_ms = start_ms + (timeout * 1000.0) stop_ms = start_ms + (timeout * 1000.0)
downloaded_file_path = self.get_path_of_downloaded_file(file, browser) downloaded_file_path = self.get_path_of_downloaded_file(file, browser)
found = False
for x in range(int(timeout)): for x in range(int(timeout)):
shared_utils.check_if_time_limit_exceeded() shared_utils.check_if_time_limit_exceeded()
try: try:
@ -3156,17 +3160,14 @@ class BaseCase(unittest.TestCase):
os.path.exists(downloaded_file_path), os.path.exists(downloaded_file_path),
"File [%s] was not found in the downloads folder [%s]!" "File [%s] was not found in the downloads folder [%s]!"
"" % (file, self.get_downloads_folder())) "" % (file, self.get_downloads_folder()))
if self.demo_mode: found = True
messenger_post = ("ASSERT DOWNLOADED FILE: [%s]" % file) break
js_utils.post_messenger_success_message(
self.driver, messenger_post, self.message_duration)
return
except Exception: except Exception:
now_ms = time.time() * 1000.0 now_ms = time.time() * 1000.0
if now_ms >= stop_ms: if now_ms >= stop_ms:
break break
time.sleep(1) time.sleep(1)
if not os.path.exists(downloaded_file_path): if not found and not os.path.exists(downloaded_file_path):
message = ( message = (
"File {%s} was not found in the downloads folder {%s} " "File {%s} was not found in the downloads folder {%s} "
"after %s seconds! (Or the download didn't complete!)" "after %s seconds! (Or the download didn't complete!)"
@ -3174,8 +3175,12 @@ class BaseCase(unittest.TestCase):
page_actions.timeout_exception("NoSuchFileException", message) page_actions.timeout_exception("NoSuchFileException", message)
if self.demo_mode: if self.demo_mode:
messenger_post = ("ASSERT DOWNLOADED FILE: [%s]" % file) messenger_post = ("ASSERT DOWNLOADED FILE: [%s]" % file)
js_utils.post_messenger_success_message( try:
self.driver, messenger_post, self.message_duration) js_utils.activate_jquery(self.driver)
js_utils.post_messenger_success_message(
self.driver, messenger_post, self.message_duration)
except Exception:
pass
def assert_true(self, expr, msg=None): def assert_true(self, expr, msg=None):
""" Asserts that the expression is True. """ Asserts that the expression is True.
@ -6920,6 +6925,12 @@ class BaseCase(unittest.TestCase):
url = self.get_current_url() url = self.get_current_url()
if url is not None: if url is not None:
has_url = True has_url = True
if (len(self.driver.window_handles) > 1):
while (len(self.driver.window_handles) > 1):
self.switch_to_window(
len(self.driver.window_handles) - 1)
self.driver.close()
self.switch_to_window(0)
if self._crumbs: if self._crumbs:
self.driver.delete_all_cookies() self.driver.delete_all_cookies()
except Exception: except Exception:

View File

@ -634,10 +634,15 @@ def highlight_with_js_2(driver, message, selector, o_bs, msg_dur):
driver.execute_script(script) driver.execute_script(script)
time.sleep(0.0181) time.sleep(0.0181)
post_messenger_success_message(driver, message, msg_dur) try:
activate_jquery(driver)
post_messenger_success_message(driver, message, msg_dur)
except Exception:
pass
script = ("""document.querySelector('%s').style.boxShadow = script = (
'%s';""" % (selector, o_bs)) """document.querySelector('%s').style.boxShadow = '%s';""" % (
selector, o_bs))
driver.execute_script(script) driver.execute_script(script)
@ -668,7 +673,11 @@ def highlight_with_jquery_2(driver, message, selector, o_bs, msg_dur):
driver.execute_script(script) driver.execute_script(script)
time.sleep(0.0181) time.sleep(0.0181)
post_messenger_success_message(driver, message, msg_dur) try:
activate_jquery(driver)
post_messenger_success_message(driver, message, msg_dur)
except Exception:
pass
script = """jQuery('%s').css('box-shadow', '%s');""" % (selector, o_bs) script = """jQuery('%s').css('box-shadow', '%s');""" % (selector, o_bs)
driver.execute_script(script) driver.execute_script(script)

View File

@ -109,7 +109,8 @@ setup(
'setuptools>=44.1.1;python_version<"3.5"', 'setuptools>=44.1.1;python_version<"3.5"',
'setuptools>=50.3.2;python_version>="3.5" and python_version<"3.6"', 'setuptools>=50.3.2;python_version>="3.5" and python_version<"3.6"',
'setuptools>=54.1.2;python_version>="3.6"', 'setuptools>=54.1.2;python_version>="3.6"',
'setuptools-scm>=5.0.2', 'setuptools-scm==5.0.2;python_version<"3.6"',
'setuptools-scm>=6.0.1;python_version>="3.6"',
'wheel>=0.36.2', 'wheel>=0.36.2',
'attrs>=20.3.0', 'attrs>=20.3.0',
'PyYAML>=5.4.1;python_version>="3.6"', 'PyYAML>=5.4.1;python_version>="3.6"',
@ -185,8 +186,6 @@ setup(
'rich==9.13.0;python_version>="3.6" and python_version<"4.0"', 'rich==9.13.0;python_version>="3.6" and python_version<"4.0"',
'tornado==5.1.1;python_version<"3.5"', 'tornado==5.1.1;python_version<"3.5"',
'tornado==6.1;python_version>="3.5"', 'tornado==6.1;python_version>="3.5"',
'allure-pytest==2.8.22;python_version<"3.5"',
'allure-pytest==2.8.36;python_version>="3.5"',
'pdfminer.six==20191110;python_version<"3.5"', 'pdfminer.six==20191110;python_version<"3.5"',
'pdfminer.six==20201018;python_version>="3.5"', 'pdfminer.six==20201018;python_version>="3.5"',
], ],