@@ -20,8 +20,16 @@ def __init__(self, loop, page, driver):
20
20
self .driver = driver
21
21
22
22
def __slow_mode_pause_if_set (self ):
23
- if hasattr (sb_config , "slow_mode" ) and sb_config .slow_mode :
24
- time .sleep (0.16 )
23
+ if (
24
+ (hasattr (sb_config , "demo_mode" ) and sb_config .demo_mode )
25
+ or "--demo" in sys .argv
26
+ ):
27
+ time .sleep (0.48 )
28
+ elif (
29
+ (hasattr (sb_config , "slow_mode" ) and sb_config .slow_mode )
30
+ or "--slow" in sys .argv
31
+ ):
32
+ time .sleep (0.24 )
25
33
26
34
def __add_light_pause (self ):
27
35
time .sleep (0.007 )
@@ -543,7 +551,7 @@ def click_visible_elements(self, selector, limit=0):
543
551
if (width != 0 or height != 0 ):
544
552
element .click ()
545
553
click_count += 1
546
- time .sleep (0.0375 )
554
+ time .sleep (0.042 )
547
555
self .__slow_mode_pause_if_set ()
548
556
self .loop .run_until_complete (self .page .wait ())
549
557
except Exception :
@@ -660,10 +668,10 @@ def press_keys(self, selector, text, timeout=settings.SMALL_TIMEOUT):
660
668
text = text [:- 1 ]
661
669
for key in text :
662
670
element .send_keys (key )
663
- time .sleep (0.0375 )
671
+ time .sleep (0.042 )
664
672
if submit :
665
673
element .send_keys ("\r \n " )
666
- time .sleep (0.0375 )
674
+ time .sleep (0.042 )
667
675
self .__slow_mode_pause_if_set ()
668
676
self .loop .run_until_complete (self .page .wait ())
669
677
@@ -733,7 +741,7 @@ def maximize(self):
733
741
return
734
742
elif self .get_window ()[1 ].window_state .value == "minimized" :
735
743
self .loop .run_until_complete (self .page .maximize ())
736
- time .sleep (0.0375 )
744
+ time .sleep (0.042 )
737
745
return self .loop .run_until_complete (self .page .maximize ())
738
746
739
747
def minimize (self ):
@@ -743,7 +751,7 @@ def minimize(self):
743
751
def medimize (self ):
744
752
if self .get_window ()[1 ].window_state .value == "minimized" :
745
753
self .loop .run_until_complete (self .page .medimize ())
746
- time .sleep (0.0375 )
754
+ time .sleep (0.042 )
747
755
return self .loop .run_until_complete (self .page .medimize ())
748
756
749
757
def set_window_rect (self , x , y , width , height ):
@@ -752,7 +760,7 @@ def set_window_rect(self, x, y, width, height):
752
760
self .page .set_window_size (
753
761
left = x , top = y , width = width , height = height )
754
762
)
755
- time .sleep (0.0375 )
763
+ time .sleep (0.042 )
756
764
return self .loop .run_until_complete (
757
765
self .page .set_window_size (
758
766
left = x , top = y , width = width , height = height )
@@ -1117,7 +1125,7 @@ def gui_press_key(self, key):
1117
1125
)
1118
1126
with gui_lock :
1119
1127
pyautogui .press (key )
1120
- time .sleep (0.0375 )
1128
+ time .sleep (0.042 )
1121
1129
self .__slow_mode_pause_if_set ()
1122
1130
self .loop .run_until_complete (self .page .wait ())
1123
1131
@@ -1131,7 +1139,7 @@ def gui_press_keys(self, keys):
1131
1139
with gui_lock :
1132
1140
for key in keys :
1133
1141
pyautogui .press (key )
1134
- time .sleep (0.0375 )
1142
+ time .sleep (0.042 )
1135
1143
self .__slow_mode_pause_if_set ()
1136
1144
self .loop .run_until_complete (self .page .wait ())
1137
1145
@@ -1472,25 +1480,53 @@ def is_element_visible(self, selector):
1472
1480
return True
1473
1481
return False
1474
1482
1483
+ def wait_for_element_visible (
1484
+ self , selector , timeout = settings .SMALL_TIMEOUT
1485
+ ):
1486
+ try :
1487
+ self .select (selector , timeout = timeout )
1488
+ except Exception :
1489
+ raise Exception ("Element {%s} was not found!" % selector )
1490
+ for i in range (30 ):
1491
+ if self .is_element_visible (selector ):
1492
+ return self .select (selector )
1493
+ time .sleep (0.1 )
1494
+ raise Exception ("Element {%s} was not visible!" % selector )
1495
+
1475
1496
def assert_element (self , selector , timeout = settings .SMALL_TIMEOUT ):
1497
+ """Same as assert_element_visible()"""
1476
1498
try :
1477
1499
self .select (selector , timeout = timeout )
1478
1500
except Exception :
1479
- raise Exception ("Element {%s} not found!" % selector )
1501
+ raise Exception ("Element {%s} was not found!" % selector )
1480
1502
for i in range (30 ):
1481
1503
if self .is_element_visible (selector ):
1482
1504
return True
1483
1505
time .sleep (0.1 )
1484
- raise Exception ("Element {%s} not visible!" % selector )
1506
+ raise Exception ("Element {%s} was not visible!" % selector )
1507
+
1508
+ def assert_element_visible (self , selector , timeout = settings .SMALL_TIMEOUT ):
1509
+ """Same as assert_element()"""
1510
+ try :
1511
+ self .select (selector , timeout = timeout )
1512
+ except Exception :
1513
+ raise Exception ("Element {%s} was not found!" % selector )
1514
+ for i in range (30 ):
1515
+ if self .is_element_visible (selector ):
1516
+ return True
1517
+ time .sleep (0.1 )
1518
+ raise Exception ("Element {%s} was not visible!" % selector )
1485
1519
1486
1520
def assert_element_present (self , selector , timeout = settings .SMALL_TIMEOUT ):
1521
+ """Assert element is present in the DOM. (Visibility NOT required)"""
1487
1522
try :
1488
1523
self .select (selector , timeout = timeout )
1489
1524
except Exception :
1490
- raise Exception ("Element {%s} not found!" % selector )
1525
+ raise Exception ("Element {%s} was not found!" % selector )
1491
1526
return True
1492
1527
1493
1528
def assert_element_absent (self , selector , timeout = settings .SMALL_TIMEOUT ):
1529
+ """Assert element is not present in the DOM."""
1494
1530
start_ms = time .time () * 1000.0
1495
1531
stop_ms = start_ms + (timeout * 1000.0 )
1496
1532
for i in range (int (timeout * 10 )):
@@ -1511,6 +1547,7 @@ def assert_element_absent(self, selector, timeout=settings.SMALL_TIMEOUT):
1511
1547
def assert_element_not_visible (
1512
1548
self , selector , timeout = settings .SMALL_TIMEOUT
1513
1549
):
1550
+ """Assert element is not visible on page. (May still be in DOM)"""
1514
1551
start_ms = time .time () * 1000.0
1515
1552
stop_ms = start_ms + (timeout * 1000.0 )
1516
1553
for i in range (int (timeout * 10 )):
@@ -1530,6 +1567,21 @@ def assert_element_not_visible(
1530
1567
% (selector , timeout , plural )
1531
1568
)
1532
1569
1570
+ def assert_element_attribute (self , selector , attribute , value = None ):
1571
+ attributes = self .get_element_attributes (selector )
1572
+ if attribute not in attributes :
1573
+ raise Exception (
1574
+ "Attribute {%s} was not found in element {%s}!"
1575
+ % (attribute , selector )
1576
+ )
1577
+ if value and attributes [attribute ] != value :
1578
+ raise Exception (
1579
+ "Expected value {%s} of attribute {%s} "
1580
+ "was not found in element {%s}! "
1581
+ "(Actual value was {%s})"
1582
+ % (value , attribute , selector , attributes [attribute ])
1583
+ )
1584
+
1533
1585
def assert_title (self , title ):
1534
1586
expected = title .strip ()
1535
1587
actual = self .get_title ().strip ()
@@ -1541,11 +1593,55 @@ def assert_title(self, title):
1541
1593
raise Exception (error % (expected , actual ))
1542
1594
except Exception :
1543
1595
time .sleep (2 )
1544
- expected = title .strip ()
1545
1596
actual = self .get_title ().strip ()
1546
1597
if expected != actual :
1547
1598
raise Exception (error % (expected , actual ))
1548
1599
1600
+ def assert_title_contains (self , substring ):
1601
+ expected = substring .strip ()
1602
+ actual = self .get_title ().strip ()
1603
+ error = (
1604
+ "Expected title substring [%s] does not appear "
1605
+ "in the actual page title [%s]!"
1606
+ )
1607
+ try :
1608
+ if expected not in actual :
1609
+ raise Exception (error % (expected , actual ))
1610
+ except Exception :
1611
+ time .sleep (2 )
1612
+ actual = self .get_title ().strip ()
1613
+ if expected not in actual :
1614
+ raise Exception (error % (expected , actual ))
1615
+
1616
+ def assert_url (self , url ):
1617
+ expected = url .strip ()
1618
+ actual = self .get_current_url ().strip ()
1619
+ error = "Expected URL [%s] does not match the actual URL [%s]!"
1620
+ try :
1621
+ if expected != actual :
1622
+ raise Exception (error % (expected , actual ))
1623
+ except Exception :
1624
+ time .sleep (2 )
1625
+ actual = self .get_current_url ().strip ()
1626
+ if expected != actual :
1627
+ raise Exception (error % (expected , actual ))
1628
+
1629
+ def assert_url_contains (self , substring ):
1630
+ expected = substring .strip ()
1631
+ actual = self .get_current_url ().strip ()
1632
+ error = (
1633
+ "Expected URL substring [%s] does not appear "
1634
+ "in the full URL [%s]!"
1635
+ )
1636
+ try :
1637
+ if expected not in actual :
1638
+ raise Exception (error % (expected , actual ))
1639
+ except Exception :
1640
+ time .sleep (2 )
1641
+ actual = self .get_current_url ().strip ()
1642
+ if expected not in actual :
1643
+ raise Exception (error % (expected , actual ))
1644
+
1549
1645
def assert_text (
1550
1646
self , text , selector = "html" , timeout = settings .SMALL_TIMEOUT
1551
1647
):
0 commit comments