Skip to content

Light refactoring #2616

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 2 commits into from
Mar 16, 2024
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
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.24.10"
__version__ = "4.24.11"
15 changes: 7 additions & 8 deletions seleniumbase/core/detect_b_ver.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,29 +231,28 @@ def get_binary_location(browser_type, prefer_chromium=False):

def get_browser_version_from_binary(binary_location):
try:
if not os.path.exists(binary_location):
return None
path = binary_location
pattern = r"\d+\.\d+\.\d+"
quad_pattern = r"\d+\.\d+\.\d+\.\d+"
if os_name() == OSType.WIN and os.path.exists(path):
if os_name() == OSType.WIN:
path = path.replace(r"\ ", r" ").replace("\\", "\\\\")
cmd_mapping = (
'''powershell -command "&{(Get-Command '%s')'''
'''.Version.ToString()}"''' % path
'''powershell -command "&{(Get-Item -Path '%s')'''
'''.VersionInfo.FileVersion}"''' % path
)
quad_version = read_version_from_cmd(cmd_mapping, quad_pattern)
if quad_version and len(str(quad_version)) >= 9: # Eg. 122.0.0.0
return quad_version
version = read_version_from_cmd(cmd_mapping, pattern)
if version and len(str(version)) >= 7: # Eg. 122.0.0
return version
return read_version_from_cmd(cmd_mapping, pattern)
if binary_location.count(r"\ ") != binary_location.count(" "):
binary_location = binary_location.replace(" ", r"\ ")
cmd_mapping = binary_location + " --version"
quad_version = read_version_from_cmd(cmd_mapping, quad_pattern)
if quad_version and len(str(quad_version)) >= 9:
return quad_version
version = read_version_from_cmd(cmd_mapping, pattern)
return version
return read_version_from_cmd(cmd_mapping, pattern)
except Exception:
return None

Expand Down
27 changes: 9 additions & 18 deletions seleniumbase/fixtures/base_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -1310,14 +1310,12 @@ def get_title(self):
return self.get_page_title()

def get_user_agent(self):
user_agent = self.execute_script("return navigator.userAgent;")
return user_agent
return self.execute_script("return navigator.userAgent;")

def get_locale_code(self):
locale_code = self.execute_script(
return self.execute_script(
"return navigator.language || navigator.languages[0];"
)
return locale_code

def go_back(self):
self.__check_scope()
Expand Down Expand Up @@ -2161,10 +2159,9 @@ def find_visible_elements(self, selector, by="css selector", limit=0):
selector, by = self.__recalculate_selector(selector, by)
self.wait_for_ready_state_complete()
time.sleep(0.05)
v_elems = page_actions.find_visible_elements(
return page_actions.find_visible_elements(
self.driver, selector, by, limit
)
return v_elems

def click_visible_elements(
self, selector, by="css selector", limit=0, timeout=None
Expand Down Expand Up @@ -6450,8 +6447,7 @@ def get_beautiful_soup(self, source=None):
except Exception:
pass
source = self.get_page_source()
soup = BeautifulSoup(source, "html.parser")
return soup
return BeautifulSoup(source, "html.parser")

def get_unique_links(self):
"""Get all unique links in the html of the page source.
Expand All @@ -6473,8 +6469,7 @@ def get_unique_links(self):
time.sleep(0.123)
soup = self.get_beautiful_soup(self.get_page_source())
page_url = self.get_current_url()
links = page_utils._get_unique_links(page_url, soup)
return links
return page_utils._get_unique_links(page_url, soup)

def get_link_status_code(
self,
Expand All @@ -6493,13 +6488,12 @@ def get_link_status_code(
timeout = self.__requests_timeout
if timeout < 1:
timeout = 1
status_code = page_utils._get_link_status_code(
return page_utils._get_link_status_code(
link,
allow_redirects=allow_redirects,
timeout=timeout,
verify=verify,
)
return status_code

def assert_link_status_code_is_not_404(self, link):
status_code = str(self.get_link_status_code(link))
Expand Down Expand Up @@ -6735,8 +6729,7 @@ def get_pdf_text(
pdf_text = self.__fix_unicode_conversion(pdf_text)
if wrap:
pdf_text = pdf_text.replace(" \n", " ")
pdf_text = pdf_text.strip() # Remove leading and trailing whitespace
return pdf_text
return pdf_text.strip()

def assert_pdf_text(
self,
Expand Down Expand Up @@ -7741,8 +7734,7 @@ def is_valid_url(self, url):

def is_online(self):
"""Return True if connected to the Internet."""
online = self.execute_script("return navigator.onLine;")
return online
return self.execute_script("return navigator.onLine;")

def is_chromium(self):
"""Return True if the browser is Chrome or Edge."""
Expand Down Expand Up @@ -13210,8 +13202,7 @@ def __jquery_click(self, selector, by="css selector"):

def __get_major_browser_version(self):
version = self.driver.__dict__["caps"]["browserVersion"]
major_browser_version = version.split(".")[0]
return major_browser_version
return version.split(".")[0]

def __get_href_from_link_text(self, link_text, hard_fail=True):
href = self.get_link_attribute(link_text, "href", hard_fail)
Expand Down