Skip to content

Commit e4abd8e

Browse files
authored
Merge pull request #2616 from seleniumbase/light-refactoring
Light refactoring
2 parents 36cfb20 + f806c4b commit e4abd8e

File tree

3 files changed

+17
-27
lines changed

3 files changed

+17
-27
lines changed

seleniumbase/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# seleniumbase package
2-
__version__ = "4.24.10"
2+
__version__ = "4.24.11"

seleniumbase/core/detect_b_ver.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -231,29 +231,28 @@ def get_binary_location(browser_type, prefer_chromium=False):
231231

232232
def get_browser_version_from_binary(binary_location):
233233
try:
234+
if not os.path.exists(binary_location):
235+
return None
234236
path = binary_location
235237
pattern = r"\d+\.\d+\.\d+"
236238
quad_pattern = r"\d+\.\d+\.\d+\.\d+"
237-
if os_name() == OSType.WIN and os.path.exists(path):
239+
if os_name() == OSType.WIN:
238240
path = path.replace(r"\ ", r" ").replace("\\", "\\\\")
239241
cmd_mapping = (
240-
'''powershell -command "&{(Get-Command '%s')'''
241-
'''.Version.ToString()}"''' % path
242+
'''powershell -command "&{(Get-Item -Path '%s')'''
243+
'''.VersionInfo.FileVersion}"''' % path
242244
)
243245
quad_version = read_version_from_cmd(cmd_mapping, quad_pattern)
244246
if quad_version and len(str(quad_version)) >= 9: # Eg. 122.0.0.0
245247
return quad_version
246-
version = read_version_from_cmd(cmd_mapping, pattern)
247-
if version and len(str(version)) >= 7: # Eg. 122.0.0
248-
return version
248+
return read_version_from_cmd(cmd_mapping, pattern)
249249
if binary_location.count(r"\ ") != binary_location.count(" "):
250250
binary_location = binary_location.replace(" ", r"\ ")
251251
cmd_mapping = binary_location + " --version"
252252
quad_version = read_version_from_cmd(cmd_mapping, quad_pattern)
253253
if quad_version and len(str(quad_version)) >= 9:
254254
return quad_version
255-
version = read_version_from_cmd(cmd_mapping, pattern)
256-
return version
255+
return read_version_from_cmd(cmd_mapping, pattern)
257256
except Exception:
258257
return None
259258

seleniumbase/fixtures/base_case.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,14 +1310,12 @@ def get_title(self):
13101310
return self.get_page_title()
13111311

13121312
def get_user_agent(self):
1313-
user_agent = self.execute_script("return navigator.userAgent;")
1314-
return user_agent
1313+
return self.execute_script("return navigator.userAgent;")
13151314

13161315
def get_locale_code(self):
1317-
locale_code = self.execute_script(
1316+
return self.execute_script(
13181317
"return navigator.language || navigator.languages[0];"
13191318
)
1320-
return locale_code
13211319

13221320
def go_back(self):
13231321
self.__check_scope()
@@ -2161,10 +2159,9 @@ def find_visible_elements(self, selector, by="css selector", limit=0):
21612159
selector, by = self.__recalculate_selector(selector, by)
21622160
self.wait_for_ready_state_complete()
21632161
time.sleep(0.05)
2164-
v_elems = page_actions.find_visible_elements(
2162+
return page_actions.find_visible_elements(
21652163
self.driver, selector, by, limit
21662164
)
2167-
return v_elems
21682165

21692166
def click_visible_elements(
21702167
self, selector, by="css selector", limit=0, timeout=None
@@ -6450,8 +6447,7 @@ def get_beautiful_soup(self, source=None):
64506447
except Exception:
64516448
pass
64526449
source = self.get_page_source()
6453-
soup = BeautifulSoup(source, "html.parser")
6454-
return soup
6450+
return BeautifulSoup(source, "html.parser")
64556451

64566452
def get_unique_links(self):
64576453
"""Get all unique links in the html of the page source.
@@ -6473,8 +6469,7 @@ def get_unique_links(self):
64736469
time.sleep(0.123)
64746470
soup = self.get_beautiful_soup(self.get_page_source())
64756471
page_url = self.get_current_url()
6476-
links = page_utils._get_unique_links(page_url, soup)
6477-
return links
6472+
return page_utils._get_unique_links(page_url, soup)
64786473

64796474
def get_link_status_code(
64806475
self,
@@ -6493,13 +6488,12 @@ def get_link_status_code(
64936488
timeout = self.__requests_timeout
64946489
if timeout < 1:
64956490
timeout = 1
6496-
status_code = page_utils._get_link_status_code(
6491+
return page_utils._get_link_status_code(
64976492
link,
64986493
allow_redirects=allow_redirects,
64996494
timeout=timeout,
65006495
verify=verify,
65016496
)
6502-
return status_code
65036497

65046498
def assert_link_status_code_is_not_404(self, link):
65056499
status_code = str(self.get_link_status_code(link))
@@ -6735,8 +6729,7 @@ def get_pdf_text(
67356729
pdf_text = self.__fix_unicode_conversion(pdf_text)
67366730
if wrap:
67376731
pdf_text = pdf_text.replace(" \n", " ")
6738-
pdf_text = pdf_text.strip() # Remove leading and trailing whitespace
6739-
return pdf_text
6732+
return pdf_text.strip()
67406733

67416734
def assert_pdf_text(
67426735
self,
@@ -7741,8 +7734,7 @@ def is_valid_url(self, url):
77417734

77427735
def is_online(self):
77437736
"""Return True if connected to the Internet."""
7744-
online = self.execute_script("return navigator.onLine;")
7745-
return online
7737+
return self.execute_script("return navigator.onLine;")
77467738

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

1321113203
def __get_major_browser_version(self):
1321213204
version = self.driver.__dict__["caps"]["browserVersion"]
13213-
major_browser_version = version.split(".")[0]
13214-
return major_browser_version
13205+
return version.split(".")[0]
1321513206

1321613207
def __get_href_from_link_text(self, link_text, hard_fail=True):
1321713208
href = self.get_link_attribute(link_text, "href", hard_fail)

0 commit comments

Comments
 (0)