@@ -30,12 +30,9 @@ def test_anything(self):
3030import time
3131import unittest
3232import uuid
33- from bs4 import BeautifulSoup
3433from seleniumbase import config as sb_config
3534from seleniumbase .common import decorators
3635from seleniumbase .config import settings
37- from seleniumbase .core .application_manager import ApplicationManager
38- from seleniumbase .core .testcase_manager import ExecutionQueryPayload
3936from seleniumbase .core .testcase_manager import TestcaseDataPayload
4037from seleniumbase .core .testcase_manager import TestcaseManager
4138from seleniumbase .core import download_helper
@@ -196,9 +193,7 @@ def is_link_text_present(self, link_text):
196193 """ Returns True if the link text appears in the HTML of the page.
197194 The element doesn't need to be visible,
198195 such as elements hidden inside a dropdown selection. """
199- self .wait_for_ready_state_complete ()
200- source = self .get_page_source ()
201- soup = BeautifulSoup (source , "html.parser" )
196+ soup = self .get_beautiful_soup ()
202197 html_links = soup .find_all ('a' )
203198 for html_link in html_links :
204199 if html_link .text .strip () == link_text .strip ():
@@ -209,9 +204,7 @@ def get_link_attribute(self, link_text, attribute, hard_fail=True):
209204 """ Finds a link by link text and then returns the attribute's value.
210205 If the link text or attribute cannot be found, an exception will
211206 get raised if hard_fail is True (otherwise None is returned). """
212- self .wait_for_ready_state_complete ()
213- source = self .get_page_source ()
214- soup = BeautifulSoup (source , "html.parser" )
207+ soup = self .get_beautiful_soup ()
215208 html_links = soup .find_all ('a' )
216209 for html_link in html_links :
217210 if html_link .text .strip () == link_text .strip ():
@@ -340,8 +333,7 @@ def click_partial_link_text(self, partial_link_text,
340333 element = self .wait_for_partial_link_text (partial_link_text )
341334 element .click ()
342335 return
343- source = self .get_page_source ()
344- soup = BeautifulSoup (source , "html.parser" )
336+ soup = self .get_beautiful_soup ()
345337 html_links = soup .fetch ('a' )
346338 for html_link in html_links :
347339 if partial_link_text in html_link .text :
@@ -701,8 +693,7 @@ def is_element_in_an_iframe(self, selector, by=By.CSS_SELECTOR):
701693 selector , by = self .__recalculate_selector (selector , by )
702694 if self .is_element_present (selector , by = by ):
703695 return False
704- source = self .get_page_source ()
705- soup = BeautifulSoup (source , "html.parser" )
696+ soup = self .get_beautiful_soup ()
706697 iframe_list = soup .select ('iframe' )
707698 for iframe in iframe_list :
708699 iframe_identifier = None
@@ -727,8 +718,7 @@ def switch_to_frame_of_element(self, selector, by=By.CSS_SELECTOR):
727718 selector , by = self .__recalculate_selector (selector , by )
728719 if self .is_element_present (selector , by = by ):
729720 return None
730- source = self .get_page_source ()
731- soup = BeautifulSoup (source , "html.parser" )
721+ soup = self .get_beautiful_soup ()
732722 iframe_list = soup .select ('iframe' )
733723 for iframe in iframe_list :
734724 iframe_identifier = None
@@ -1438,12 +1428,15 @@ def slow_scroll_to(self, selector, by=By.CSS_SELECTOR,
14381428 selector , by = by , timeout = timeout )
14391429 self .__slow_scroll_to_element (element )
14401430
1431+ @decorators .deprecated ("Use self.click() - It now scrolls before clicking" )
14411432 def scroll_click (self , selector , by = By .CSS_SELECTOR ):
14421433 # DEPRECATED - self.click() now scrolls to the element before clicking
1443- # self.scroll_to(selector, by=by)
1434+ # self.scroll_to(selector, by=by) # Redundant
14441435 self .click (selector , by = by )
14451436
14461437 def click_xpath (self , xpath ):
1438+ # Technically self.click() will automatically detect an xpath selector,
1439+ # so self.click_xpath() is just a longer name for the same action.
14471440 self .click (xpath , by = By .XPATH )
14481441
14491442 def js_click (self , selector , by = By .CSS_SELECTOR ):
@@ -1552,13 +1545,24 @@ def ad_block(self):
15521545 except Exception :
15531546 pass # Don't fail test if ad_blocking fails
15541547
1548+ @decorators .deprecated ("Use re.escape() instead! It does what you want!" )
15551549 def jq_format (self , code ):
1556- # DEPRECATED - Use re.escape() instead, which does the action you want.
1550+ # DEPRECATED - re.escape() already does that thing you want!
15571551 return js_utils ._jq_format (code )
15581552
15591553 def get_domain_url (self , url ):
15601554 return page_utils .get_domain_url (url )
15611555
1556+ def get_beautiful_soup (self , source = None ):
1557+ """ BeautifulSoup is a toolkit for dissecting an HTML document
1558+ and extracting what you need. It's great for screen-scraping! """
1559+ from bs4 import BeautifulSoup
1560+ if not source :
1561+ self .wait_for_ready_state_complete ()
1562+ source = self .get_page_source ()
1563+ soup = BeautifulSoup (source , "html.parser" )
1564+ return soup
1565+
15621566 def safe_execute_script (self , script ):
15631567 """ When executing a script that contains a jQuery command,
15641568 it's important that the jQuery library has been loaded first.
@@ -1611,6 +1615,18 @@ def assert_downloaded_file(self, file):
16111615 """ Asserts that the file exists in the Downloads Folder. """
16121616 assert os .path .exists (self .get_path_of_downloaded_file (file ))
16131617
1618+ def assert_true (self , expr , msg = None ):
1619+ self .assertTrue (expr , msg = None )
1620+
1621+ def assert_false (self , expr , msg = None ):
1622+ self .assertFalse (expr , msg = None )
1623+
1624+ def assert_equal (self , first , second , msg = None ):
1625+ self .assertEqual (first , second , msg = None )
1626+
1627+ def assert_not_equal (self , first , second , msg = None ):
1628+ self .assertNotEqual (first , second , msg = None )
1629+
16141630 def assert_no_js_errors (self ):
16151631 """ Asserts that there are no JavaScript "SEVERE"-level page errors.
16161632 Works ONLY for Chrome (non-headless) and Chrome-based browsers.
@@ -1885,39 +1901,6 @@ def select_option_by_value(self, dropdown_selector, option,
18851901 dropdown_by = dropdown_by , option_by = "value" ,
18861902 timeout = timeout )
18871903
1888- @decorators .deprecated ("Use self.select_option_by_text() instead!" )
1889- def pick_select_option_by_text (self , dropdown_selector , option ,
1890- dropdown_by = By .CSS_SELECTOR ,
1891- timeout = settings .SMALL_TIMEOUT ):
1892- """ Selects an HTML <select> option by option text. """
1893- if self .timeout_multiplier and timeout == settings .SMALL_TIMEOUT :
1894- timeout = self .__get_new_timeout (timeout )
1895- self .__select_option (dropdown_selector , option ,
1896- dropdown_by = dropdown_by , option_by = "text" ,
1897- timeout = timeout )
1898-
1899- @decorators .deprecated ("Use self.select_option_by_index() instead!" )
1900- def pick_select_option_by_index (self , dropdown_selector , option ,
1901- dropdown_by = By .CSS_SELECTOR ,
1902- timeout = settings .SMALL_TIMEOUT ):
1903- """ Selects an HTML <select> option by option index. """
1904- if self .timeout_multiplier and timeout == settings .SMALL_TIMEOUT :
1905- timeout = self .__get_new_timeout (timeout )
1906- self .__select_option (dropdown_selector , option ,
1907- dropdown_by = dropdown_by , option_by = "index" ,
1908- timeout = timeout )
1909-
1910- @decorators .deprecated ("Use self.select_option_by_value() instead!" )
1911- def pick_select_option_by_value (self , dropdown_selector , option ,
1912- dropdown_by = By .CSS_SELECTOR ,
1913- timeout = settings .SMALL_TIMEOUT ):
1914- """ Selects an HTML <select> option by option value. """
1915- if self .timeout_multiplier and timeout == settings .SMALL_TIMEOUT :
1916- timeout = self .__get_new_timeout (timeout )
1917- self .__select_option (dropdown_selector , option ,
1918- dropdown_by = dropdown_by , option_by = "value" ,
1919- timeout = timeout )
1920-
19211904 ############
19221905
19231906 def generate_referral (self , start_page , destination_page ):
@@ -2495,12 +2478,6 @@ def delayed_assert_element(self, selector, by=By.CSS_SELECTOR,
24952478 self .__add_delayed_assert_failure ()
24962479 return False
24972480
2498- @decorators .deprecated ("Use self.delayed_assert_element() instead!" )
2499- def check_assert_element (self , selector , by = By .CSS_SELECTOR ,
2500- timeout = settings .MINI_TIMEOUT ):
2501- """ DEPRECATED - Use self.delayed_assert_element() instead. """
2502- return self .delayed_assert_element (selector , by = by , timeout = timeout )
2503-
25042481 def delayed_assert_text (self , text , selector = "html" , by = By .CSS_SELECTOR ,
25052482 timeout = settings .MINI_TIMEOUT ):
25062483 """ A non-terminating assertion for text from an element on a page.
@@ -2522,12 +2499,6 @@ def delayed_assert_text(self, text, selector="html", by=By.CSS_SELECTOR,
25222499 self .__add_delayed_assert_failure ()
25232500 return False
25242501
2525- @decorators .deprecated ("Use self.delayed_assert_text() instead!" )
2526- def check_assert_text (self , text , selector = "html" , by = By .CSS_SELECTOR ,
2527- timeout = settings .MINI_TIMEOUT ):
2528- """ DEPRECATED - Use self.delayed_assert_text() instead. """
2529- return self .delayed_assert_text (text , selector , by = by , timeout = timeout )
2530-
25312502 def process_delayed_asserts (self , print_only = False ):
25322503 """ To be used with any test that uses delayed_asserts, which are
25332504 non-terminating verifications that only raise exceptions
@@ -2552,11 +2523,6 @@ def process_delayed_asserts(self, print_only=False):
25522523 else :
25532524 raise Exception (exception_output )
25542525
2555- @decorators .deprecated ("Use self.process_delayed_asserts() instead!" )
2556- def process_checks (self , print_only = False ):
2557- """ DEPRECATED - Use self.process_delayed_asserts() instead. """
2558- self .process_delayed_asserts (print_only = print_only )
2559-
25602526 ############
25612527
25622528 def __js_click (self , selector , by = By .CSS_SELECTOR ):
@@ -2606,8 +2572,7 @@ def __get_href_from_link_text(self, link_text, hard_fail=True):
26062572
26072573 def __click_dropdown_link_text (self , link_text , link_css ):
26082574 """ When a link may be hidden under a dropdown menu, use this. """
2609- source = self .get_page_source ()
2610- soup = BeautifulSoup (source , "html.parser" )
2575+ soup = self .get_beautiful_soup ()
26112576 drop_down_list = soup .select ('[class*=dropdown]' )
26122577 for item in soup .select ('[class*=HeaderMenu]' ):
26132578 drop_down_list .append (item )
@@ -2769,6 +2734,10 @@ def setUp(self):
27692734 # Use Selenium Grid (Use --server=127.0.0.1 for localhost Grid)
27702735 self .use_grid = True
27712736 if self .with_db_reporting :
2737+ from seleniumbase .core .application_manager import (
2738+ ApplicationManager )
2739+ from seleniumbase .core .testcase_manager import (
2740+ ExecutionQueryPayload )
27722741 import getpass
27732742 self .execution_guid = str (uuid .uuid4 ())
27742743 self .testcase_guid = None
0 commit comments