Skip to content

Python 3.11 Official Support #1592

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ pytest my_first_test.py --pdb
--window-size=WIDTH,HEIGHT # (Set the browser's starting window size.)
--maximize # (Start tests with the browser window maximized.)
--screenshot # (Save a screenshot at the end of each test.)
--no-screenshot # (No screenshots saved unless tests directly ask it.)
--visual-baseline # (Set the visual baseline for Visual/Layout tests.)
--wire # (Use selenium-wire's webdriver for replacing selenium webdriver.)
--external-pdf # (Set Chromium "plugins.always_open_pdf_externally":True.)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
""" Solve the Wordle game using SeleniumBase.
This test runs on archived versions of Wordle, containing Shadow-DOM. """
"""
Solve the Wordle game using SeleniumBase.
This test runs on archived versions of Wordle, containing Shadow-DOM.
"""

import ast
import random
Expand Down Expand Up @@ -86,7 +88,7 @@ def test_wordle(self):
keyboard_base = "game-app::shadow game-keyboard::shadow "
word = random.choice(self.word_list)
num_attempts = 0
success = False
found_word = False
for attempt in range(6):
num_attempts += 1
word = random.choice(self.word_list)
Expand All @@ -105,13 +107,13 @@ def test_wordle(self):
letter_eval = self.get_attribute(tile % str(i), "evaluation")
letter_status.append(letter_eval)
if letter_status.count("correct") == 5:
success = True
found_word = True
break
self.word_list.remove(word)
self.modify_word_list(word, letter_status)

self.save_screenshot_to_logs()
if success:
if found_word:
print('Word: "%s"\nAttempts: %s' % (word.upper(), num_attempts))
else:
print('Final guess: "%s" (Not the correct word!)' % word.upper())
Expand Down
1 change: 1 addition & 0 deletions examples/raw_parameter_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
sb.maximize_option = False
sb._disable_beforeunload = False
sb.save_screenshot_after_test = False
sb.no_screenshot_after_test = False
sb.page_load_strategy = None
sb.timeout_multiplier = None
sb.pytest_html_report = None
Expand Down
13 changes: 9 additions & 4 deletions examples/test_apple_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ def test_apple_developer_site_webdriver_instructions(self):
self.demo_mode = True
self.demo_sleep = 0.5
self.message_duration = 2.0
if self.headless and (
self.browser == "chrome" or self.browser == "edge"
):
self.get_new_driver(browser=self.browser, headless2=True)
if self.headless:
if self._multithreaded:
print("Skipping test in headless multi-threaded mode.")
self.skip("Skipping test in headless multi-threaded mode.")
elif self.undetectable:
print("Skipping test in headless undetectable mode.")
self.skip("Skipping test in headless undetectable mode.")
elif self.browser == "chrome" or self.browser == "edge":
self.get_new_driver(browser=self.browser, headless2=True)
self.open("https://developer.apple.com/search/")
title = "Testing with WebDriver in Safari"
self.type('[placeholder*="developer.apple.com"]', title + "\n")
Expand Down
2 changes: 1 addition & 1 deletion examples/test_get_locale_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class LocaleTests(BaseCase):
def test_get_locale_code(self):
self.open("data:,")
self.open("about:blank")
locale_code = self.get_locale_code()
message = '\nLocale Code = "%s"' % locale_code
print(message)
Expand Down
2 changes: 1 addition & 1 deletion examples/visual_testing/test_layout_fail.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_applitools_change(self):
# Click a button that changes the text of an element
self.click('a[href="?diff1"]')
# Click a button that makes a hidden element visible
self.click("button")
self.slow_click("button")
print("(This test should fail)") # due to image now seen
self.check_window(name="helloworld", level=3)

Expand Down
8 changes: 5 additions & 3 deletions examples/wordle_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_wordle(self):
self.initialize_word_list()
word = random.choice(self.word_list)
num_attempts = 0
success = False
found_word = False
for attempt in range(6):
num_attempts += 1
word = random.choice(self.word_list)
Expand All @@ -74,25 +74,27 @@ def test_wordle(self):
button = 'button[data-key="%s"]' % letter
self.click(button)
button = 'button[class*="oneAndAHalf"]'
self.wait_for_ready_state_complete()
self.click(button)
row = (
'div[class*="lbzlf"] div[class*="Row-module"]:nth-of-type(%s) '
% num_attempts
)
tile = row + 'div:nth-child(%s) div[class*="module_tile__3ayIZ"]'
self.wait_for_element(tile % "5" + '[data-state*="e"]')
self.wait_for_ready_state_complete()
letter_status = []
for i in range(1, 6):
letter_eval = self.get_attribute(tile % str(i), "data-state")
letter_status.append(letter_eval)
if letter_status.count("correct") == 5:
success = True
found_word = True
break
self.word_list.remove(word)
self.modify_word_list(word, letter_status)

self.save_screenshot_to_logs()
if success:
if found_word:
print('\nWord: "%s"\nAttempts: %s' % (word.upper(), num_attempts))
else:
print('Final guess: "%s" (Not the correct word!)' % word.upper())
Expand Down
1 change: 1 addition & 0 deletions help_docs/customizing_test_runs.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ pytest my_first_test.py --settings-file=custom_settings.py
--window-size=WIDTH,HEIGHT # (Set the browser's starting window size.)
--maximize # (Start tests with the browser window maximized.)
--screenshot # (Save a screenshot at the end of each test.)
--no-screenshot # (No screenshots saved unless tests directly ask it.)
--visual-baseline # (Set the visual baseline for Visual/Layout tests.)
--wire # (Use selenium-wire's webdriver for replacing selenium webdriver.)
--external-pdf # (Set Chromium "plugins.always_open_pdf_externally":True.)
Expand Down
6 changes: 3 additions & 3 deletions mkdocs_build/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# mkdocs dependencies for generating the seleniumbase.io website
# Minimum Python version: 3.7

regex>=2022.9.13
regex>=2022.10.31
docutils==0.19
python-dateutil==2.8.2
livereload==2.6.3
Expand All @@ -14,7 +14,7 @@ Jinja2==3.1.2
click==8.1.3
zipp==3.10.0
ghp-import==2.1.0
readme-renderer==37.2
readme-renderer==37.3
pymdown-extensions==9.7
importlib-metadata==5.0.0
bleach==5.0.1
Expand All @@ -28,7 +28,7 @@ cairosvg==2.5.2
cssselect2==0.7.0
tinycss2==1.2.1
defusedxml==0.7.1
mkdocs==1.4.1
mkdocs==1.4.2
mkdocs-material==8.5.7
mkdocs-exclude-search==0.6.4
mkdocs-simple-hooks==0.1.5
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pytest-html==1.22.1;python_version<"3.6"
pytest-html==2.0.1;python_version>="3.6"
pytest-metadata==1.8.0;python_version<"3.6"
pytest-metadata==1.11.0;python_version>="3.6" and python_version<"3.7"
pytest-metadata==2.0.3;python_version>="3.7"
pytest-metadata==2.0.4;python_version>="3.7"
pytest-ordering==0.6
pytest-rerunfailures==8.0;python_version<"3.6"
pytest-rerunfailures==10.2;python_version>="3.6"
Expand All @@ -98,7 +98,7 @@ beautifulsoup4==4.9.3;python_version<"3.6"
beautifulsoup4==4.11.1;python_version>="3.6"
cryptography==2.9.2;python_version<"3.6"
cryptography==36.0.2;python_version>="3.6" and python_version<"3.7"
cryptography==38.0.1;python_version>="3.7"
cryptography==38.0.3;python_version>="3.7"
pygments==2.5.2;python_version<"3.6"
pygments==2.13.0;python_version>="3.6"
prompt-toolkit==1.0.18;python_version<"3.6"
Expand Down
2 changes: 1 addition & 1 deletion seleniumbase/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# seleniumbase package
__version__ = "4.7.0"
__version__ = "4.7.1"
9 changes: 8 additions & 1 deletion seleniumbase/behave/behave_sb.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@
-D window-size=WIDTH,HEIGHT (Set the browser's starting window size.)
-D maximize (Start tests with the browser window maximized.)
-D screenshot (Save a screenshot at the end of each test.)
-D no-screenshot (No screenshots saved unless tests directly ask it.)
-D visual-baseline (Set the visual baseline for Visual/Layout tests.)
-D wire (Use selenium-wire's webdriver for replacing selenium webdriver.)
-D external-pdf (Set Chromium "plugins.always_open_pdf_externally": True.)
-D external-pdf (Set Chromium "plugins.always_open_pdf_externally":True.)
-D timeout-multiplier=MULTIPLIER (Multiplies the default timeout values.)
"""

Expand Down Expand Up @@ -185,6 +186,7 @@ def get_configured_sb(context):
sb.maximize_option = False
sb.is_context_manager = False
sb.save_screenshot_after_test = False
sb.no_screenshot_after_test = False
sb.timeout_multiplier = None
sb.pytest_html_report = None
sb.with_db_reporting = False
Expand Down Expand Up @@ -565,6 +567,10 @@ def get_configured_sb(context):
]:
sb.save_screenshot_after_test = True
continue
# Handle: -D no-screenshot / no_screenshot / ns
if low_key in ["no-screenshot", "no_screenshot", "ns"]:
sb.no_screenshot_after_test = True
continue
# Handle: -D timeout-multiplier=FLOAT / timeout_multiplier=FLOAT
if low_key in ["timeout-multiplier", "timeout_multiplier"]:
timeout_multiplier = userdata[key]
Expand Down Expand Up @@ -848,6 +854,7 @@ def get_configured_sb(context):
sb_config.maximize_option = sb.maximize_option
sb_config.xvfb = sb.xvfb
sb_config.save_screenshot = sb.save_screenshot_after_test
sb_config.no_screenshot = sb.no_screenshot_after_test
sb_config._has_logs = False
sb_config.variables = sb.variables
sb_config.dashboard = sb.dashboard
Expand Down
4 changes: 2 additions & 2 deletions seleniumbase/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@
# (Headless resolutions take priority, and include all browsers.)
# (Firefox starts maximized by default when running in GUI Mode.)
CHROME_START_WIDTH = 1250
CHROME_START_HEIGHT = 840
CHROME_START_HEIGHT = 825
HEADLESS_START_WIDTH = 1440
HEADLESS_START_HEIGHT = 1880
HEADLESS_START_HEIGHT = 1875

# #####>>>>>----- MasterQA SETTINGS -----<<<<<#####
# ##### (Used when importing MasterQA as the parent class)
Expand Down
52 changes: 37 additions & 15 deletions seleniumbase/core/browser_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from selenium.webdriver.chrome.service import Service as ChromeService
from selenium.webdriver.edge.service import Service as EdgeService
from selenium.webdriver.firefox.service import Service as FirefoxService
from selenium.webdriver.safari.service import Service as SafariService
from seleniumbase.config import settings
from seleniumbase.core import download_helper
from seleniumbase.core import proxy_helper
Expand Down Expand Up @@ -477,6 +478,18 @@ def _set_chrome_options(
chrome_options.add_experimental_option(
"mobileEmulation", emulator_settings
)
if headless or headless2:
chrome_options.add_argument(
"--window-size=%s,%s" % (
settings.HEADLESS_START_WIDTH, settings.HEADLESS_START_HEIGHT
)
)
else:
chrome_options.add_argument(
"--window-size=%s,%s" % (
settings.CHROME_START_WIDTH, settings.CHROME_START_HEIGHT
)
)
if (
not proxy_auth
and not disable_csp
Expand All @@ -498,7 +511,7 @@ def _set_chrome_options(
chrome_options.add_argument("--guest")
else:
pass
if user_data_dir and not undetectable:
if user_data_dir and not is_using_uc(undetectable, browser_name):
abs_path = os.path.abspath(user_data_dir)
chrome_options.add_argument("user-data-dir=%s" % abs_path)
if extension_zip:
Expand Down Expand Up @@ -527,13 +540,6 @@ def _set_chrome_options(
):
# Only change it if not "normal", which is the default.
chrome_options.page_load_strategy = settings.PAGE_LOAD_STRATEGY.lower()
if servername != "localhost":
use_auto_ext = True # Use Automation Extension
if not use_auto_ext: # Disable Automation Extension. (Default)
if browser_name != constants.Browser.OPERA:
chrome_options.add_argument(
"--disable-blink-features=AutomationControlled"
)
if headless2:
chrome_options.add_argument("--headless=chrome")
elif headless:
Expand Down Expand Up @@ -591,10 +597,11 @@ def _set_chrome_options(
chrome_options.add_argument("--proxy-pac-url=%s" % proxy_pac_url)
if browser_name != constants.Browser.OPERA:
# Opera Chromium doesn't support these switches
chrome_options.add_argument("--ignore-certificate-errors")
if not is_using_uc(undetectable, browser_name) or not enable_ws:
chrome_options.add_argument("--ignore-certificate-errors")
if not enable_ws:
chrome_options.add_argument("--disable-web-security")
if "linux" in PLATFORM or not undetectable:
if "linux" in PLATFORM or not is_using_uc(undetectable, browser_name):
chrome_options.add_argument("--no-sandbox")
else:
# Opera Chromium only!
Expand Down Expand Up @@ -940,7 +947,7 @@ def get_driver(
headless = True
if uc_subprocess and not undetectable:
undetectable = True
if undetectable and mobile_emulator:
if is_using_uc(undetectable, browser_name) and mobile_emulator:
mobile_emulator = False
user_agent = None
proxy_auth = False
Expand Down Expand Up @@ -2060,7 +2067,21 @@ def get_local_driver(
edge_options.add_experimental_option(
"mobileEmulation", emulator_settings
)
if user_data_dir and not undetectable:
if headless or headless2:
edge_options.add_argument(
"--window-size=%s,%s" % (
settings.HEADLESS_START_WIDTH,
settings.HEADLESS_START_HEIGHT,
)
)
else:
edge_options.add_argument(
"--window-size=%s,%s" % (
settings.CHROME_START_WIDTH,
settings.CHROME_START_HEIGHT,
)
)
if user_data_dir and not is_using_uc(undetectable, browser_name):
abs_path = os.path.abspath(user_data_dir)
edge_options.add_argument("user-data-dir=%s" % abs_path)
if extension_zip:
Expand Down Expand Up @@ -2144,7 +2165,7 @@ def get_local_driver(
edge_options.add_argument("--allow-running-insecure-content")
if user_agent:
edge_options.add_argument("--user-agent=%s" % user_agent)
if "linux" in PLATFORM or not undetectable:
if "linux" in PLATFORM or not is_using_uc(undetectable, browser_name):
edge_options.add_argument("--no-sandbox")
if remote_debug:
# To access the Remote Debugger, go to: http://localhost:9222
Expand Down Expand Up @@ -2298,7 +2319,8 @@ def get_local_driver(
# Skip if multithreaded
raise Exception("Can't run Safari tests in multithreaded mode!")
warnings.simplefilter("ignore", category=DeprecationWarning)
return webdriver.safari.webdriver.WebDriver(quiet=False)
service = SafariService(quiet=False)
return webdriver.safari.webdriver.WebDriver(service=service)
elif browser_name == constants.Browser.OPERA:
try:
if LOCAL_OPERADRIVER and os.path.exists(LOCAL_OPERADRIVER):
Expand Down Expand Up @@ -2635,7 +2657,7 @@ def get_local_driver(
if selenium4_or_newer:
if headless and "linux" not in PLATFORM:
undetectable = False # No support for headless
if undetectable:
if is_using_uc(undetectable, browser_name):
from seleniumbase import undetected
from urllib.error import URLError

Expand Down
Loading