@@ -30,12 +30,9 @@ def test_anything(self):
30
30
import time
31
31
import unittest
32
32
import uuid
33
- from bs4 import BeautifulSoup
34
33
from seleniumbase import config as sb_config
35
34
from seleniumbase .common import decorators
36
35
from seleniumbase .config import settings
37
- from seleniumbase .core .application_manager import ApplicationManager
38
- from seleniumbase .core .testcase_manager import ExecutionQueryPayload
39
36
from seleniumbase .core .testcase_manager import TestcaseDataPayload
40
37
from seleniumbase .core .testcase_manager import TestcaseManager
41
38
from seleniumbase .core import download_helper
@@ -196,9 +193,7 @@ def is_link_text_present(self, link_text):
196
193
""" Returns True if the link text appears in the HTML of the page.
197
194
The element doesn't need to be visible,
198
195
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 ()
202
197
html_links = soup .find_all ('a' )
203
198
for html_link in html_links :
204
199
if html_link .text .strip () == link_text .strip ():
@@ -209,9 +204,7 @@ def get_link_attribute(self, link_text, attribute, hard_fail=True):
209
204
""" Finds a link by link text and then returns the attribute's value.
210
205
If the link text or attribute cannot be found, an exception will
211
206
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 ()
215
208
html_links = soup .find_all ('a' )
216
209
for html_link in html_links :
217
210
if html_link .text .strip () == link_text .strip ():
@@ -340,8 +333,7 @@ def click_partial_link_text(self, partial_link_text,
340
333
element = self .wait_for_partial_link_text (partial_link_text )
341
334
element .click ()
342
335
return
343
- source = self .get_page_source ()
344
- soup = BeautifulSoup (source , "html.parser" )
336
+ soup = self .get_beautiful_soup ()
345
337
html_links = soup .fetch ('a' )
346
338
for html_link in html_links :
347
339
if partial_link_text in html_link .text :
@@ -701,8 +693,7 @@ def is_element_in_an_iframe(self, selector, by=By.CSS_SELECTOR):
701
693
selector , by = self .__recalculate_selector (selector , by )
702
694
if self .is_element_present (selector , by = by ):
703
695
return False
704
- source = self .get_page_source ()
705
- soup = BeautifulSoup (source , "html.parser" )
696
+ soup = self .get_beautiful_soup ()
706
697
iframe_list = soup .select ('iframe' )
707
698
for iframe in iframe_list :
708
699
iframe_identifier = None
@@ -727,8 +718,7 @@ def switch_to_frame_of_element(self, selector, by=By.CSS_SELECTOR):
727
718
selector , by = self .__recalculate_selector (selector , by )
728
719
if self .is_element_present (selector , by = by ):
729
720
return None
730
- source = self .get_page_source ()
731
- soup = BeautifulSoup (source , "html.parser" )
721
+ soup = self .get_beautiful_soup ()
732
722
iframe_list = soup .select ('iframe' )
733
723
for iframe in iframe_list :
734
724
iframe_identifier = None
@@ -1438,12 +1428,15 @@ def slow_scroll_to(self, selector, by=By.CSS_SELECTOR,
1438
1428
selector , by = by , timeout = timeout )
1439
1429
self .__slow_scroll_to_element (element )
1440
1430
1431
+ @decorators .deprecated ("Use self.click() - It now scrolls before clicking" )
1441
1432
def scroll_click (self , selector , by = By .CSS_SELECTOR ):
1442
1433
# 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
1444
1435
self .click (selector , by = by )
1445
1436
1446
1437
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.
1447
1440
self .click (xpath , by = By .XPATH )
1448
1441
1449
1442
def js_click (self , selector , by = By .CSS_SELECTOR ):
@@ -1552,13 +1545,24 @@ def ad_block(self):
1552
1545
except Exception :
1553
1546
pass # Don't fail test if ad_blocking fails
1554
1547
1548
+ @decorators .deprecated ("Use re.escape() instead! It does what you want!" )
1555
1549
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!
1557
1551
return js_utils ._jq_format (code )
1558
1552
1559
1553
def get_domain_url (self , url ):
1560
1554
return page_utils .get_domain_url (url )
1561
1555
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
+
1562
1566
def safe_execute_script (self , script ):
1563
1567
""" When executing a script that contains a jQuery command,
1564
1568
it's important that the jQuery library has been loaded first.
@@ -1611,6 +1615,18 @@ def assert_downloaded_file(self, file):
1611
1615
""" Asserts that the file exists in the Downloads Folder. """
1612
1616
assert os .path .exists (self .get_path_of_downloaded_file (file ))
1613
1617
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
+
1614
1630
def assert_no_js_errors (self ):
1615
1631
""" Asserts that there are no JavaScript "SEVERE"-level page errors.
1616
1632
Works ONLY for Chrome (non-headless) and Chrome-based browsers.
@@ -1885,39 +1901,6 @@ def select_option_by_value(self, dropdown_selector, option,
1885
1901
dropdown_by = dropdown_by , option_by = "value" ,
1886
1902
timeout = timeout )
1887
1903
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
-
1921
1904
############
1922
1905
1923
1906
def generate_referral (self , start_page , destination_page ):
@@ -2495,12 +2478,6 @@ def delayed_assert_element(self, selector, by=By.CSS_SELECTOR,
2495
2478
self .__add_delayed_assert_failure ()
2496
2479
return False
2497
2480
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
-
2504
2481
def delayed_assert_text (self , text , selector = "html" , by = By .CSS_SELECTOR ,
2505
2482
timeout = settings .MINI_TIMEOUT ):
2506
2483
""" 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,
2522
2499
self .__add_delayed_assert_failure ()
2523
2500
return False
2524
2501
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
-
2531
2502
def process_delayed_asserts (self , print_only = False ):
2532
2503
""" To be used with any test that uses delayed_asserts, which are
2533
2504
non-terminating verifications that only raise exceptions
@@ -2552,11 +2523,6 @@ def process_delayed_asserts(self, print_only=False):
2552
2523
else :
2553
2524
raise Exception (exception_output )
2554
2525
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
-
2560
2526
############
2561
2527
2562
2528
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):
2606
2572
2607
2573
def __click_dropdown_link_text (self , link_text , link_css ):
2608
2574
""" 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 ()
2611
2576
drop_down_list = soup .select ('[class*=dropdown]' )
2612
2577
for item in soup .select ('[class*=HeaderMenu]' ):
2613
2578
drop_down_list .append (item )
@@ -2769,6 +2734,10 @@ def setUp(self):
2769
2734
# Use Selenium Grid (Use --server=127.0.0.1 for localhost Grid)
2770
2735
self .use_grid = True
2771
2736
if self .with_db_reporting :
2737
+ from seleniumbase .core .application_manager import (
2738
+ ApplicationManager )
2739
+ from seleniumbase .core .testcase_manager import (
2740
+ ExecutionQueryPayload )
2772
2741
import getpass
2773
2742
self .execution_guid = str (uuid .uuid4 ())
2774
2743
self .testcase_guid = None
0 commit comments