Skip to content

Commit 9bc6e02

Browse files
authored
Merge pull request #586 from seleniumbase/many-changes-are-coming
Add/Update translations and more
2 parents 2cf0ba6 + 0eb4696 commit 9bc6e02

27 files changed

+977
-214
lines changed

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -726,29 +726,29 @@ self.click("a.analytics") # Clicks the generated button
726726
```
727727
(Due to popular demand, this traffic generation example has been baked into SeleniumBase with the ``self.generate_referral(start_page, end_page)`` and the ``self.generate_traffic(start_page, end_page, loops)`` methods.)
728728

729-
<h4>Using delayed asserts:</h4>
729+
<h4>Using deferred asserts:</h4>
730730

731-
Let's say you want to verify multiple different elements on a web page in a single test, but you don't want the test to fail until you verified several elements at once so that you don't have to rerun the test to find more missing elements on the same page. That's where delayed asserts come in. Here's the example:
731+
Let's say you want to verify multiple different elements on a web page in a single test, but you don't want the test to fail until you verified several elements at once so that you don't have to rerun the test to find more missing elements on the same page. That's where deferred asserts come in. Here's the example:
732732

733733
```python
734734
from seleniumbase import BaseCase
735735

736736
class MyTestClass(BaseCase):
737737

738-
def test_delayed_asserts(self):
738+
def test_deferred_asserts(self):
739739
self.open('https://xkcd.com/993/')
740740
self.wait_for_element('#comic')
741-
self.delayed_assert_element('img[alt="Brand Identity"]')
742-
self.delayed_assert_element('img[alt="Rocket Ship"]') # Will Fail
743-
self.delayed_assert_element('#comicmap')
744-
self.delayed_assert_text('Fake Item', '#middleContainer') # Will Fail
745-
self.delayed_assert_text('Random', '#middleContainer')
746-
self.delayed_assert_element('a[name="Super Fake !!!"]') # Will Fail
747-
self.process_delayed_asserts()
741+
self.deferred_assert_element('img[alt="Brand Identity"]')
742+
self.deferred_assert_element('img[alt="Rocket Ship"]') # Will Fail
743+
self.deferred_assert_element('#comicmap')
744+
self.deferred_assert_text('Fake Item', '#middleContainer') # Will Fail
745+
self.deferred_assert_text('Random', '#middleContainer')
746+
self.deferred_assert_element('a[name="Super Fake !!!"]') # Will Fail
747+
self.process_deferred_asserts()
748748
```
749749

750-
``delayed_assert_element()`` and ``delayed_assert_text()`` will save any exceptions that would be raised.
751-
To flush out all the failed delayed asserts into a single exception, make sure to call ``self.process_delayed_asserts()`` at the end of your test method. If your test hits multiple pages, you can call ``self.process_delayed_asserts()`` at the end of all your delayed asserts for a single page. This way, the screenshot from your log file will have the location where the delayed asserts were made.
750+
``deferred_assert_element()`` and ``deferred_assert_text()`` will save any exceptions that would be raised.
751+
To flush out all the failed deferred asserts into a single exception, make sure to call ``self.process_deferred_asserts()`` at the end of your test method. If your test hits multiple pages, you can call ``self.process_deferred_asserts()`` before navigating to a new page so that the screenshot from your log files matches the URL where the deferred asserts were made.
752752

753753
<h4>Accessing raw WebDriver</h4>
754754

docs/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
mkdocs==1.1.2
2-
mkdocs-material==5.2.1
2+
mkdocs-material==5.2.2
33
mkdocs-simple-hooks==0.1.1
44
mkdocs-material-extensions==1.0
55
mkdocs-minify-plugin==0.3.0

examples/gui_test_runner.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ def __init__(self, master):
6363
fg="red").pack()
6464
self.title7 = Label(
6565
frame,
66-
text="Run a Failing Test with Delayed Asserts:",
66+
text="Run a Failing Test with Deferred Asserts:",
6767
fg="blue").pack()
6868
self.run7 = Button(
6969
frame, command=self.run_7,
70-
text=("pytest test_delayed_asserts.py --browser=chrome"),
70+
text=("pytest test_deferred_asserts.py --browser=chrome"),
7171
fg="red").pack()
7272
self.end_title = Label(frame, text="", fg="black").pack()
7373
self.quit = Button(frame, text="QUIT", command=frame.quit).pack()
@@ -98,7 +98,7 @@ def run_6(self):
9898

9999
def run_7(self):
100100
os.system(
101-
'pytest test_delayed_asserts.py --browser=chrome')
101+
'pytest test_deferred_asserts.py --browser=chrome')
102102

103103

104104
if __name__ == "__main__":

examples/handle_alert_test.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ class MyTestClass(BaseCase):
66
def test_alerts(self):
77
self.open("about:blank")
88
self.execute_script('window.alert("ALERT!!!")')
9-
self.sleep(1.2) # Not needed (Lets you see the alert pop up)
10-
self.wait_for_and_accept_alert()
11-
self.sleep(0.8) # Not needed (Lets you see the alert go away)
9+
self.sleep(1) # Not needed (Lets you see the alert pop up)
10+
self.accept_alert()
11+
self.sleep(1) # Not needed (Lets you see the alert go away)
1212
self.execute_script('window.prompt("My Prompt","defaultText");')
13-
self.sleep(1.2) # Not needed (Lets you see the alert pop up)
14-
alert = self.wait_for_and_switch_to_alert(timeout=2)
15-
self.assert_equal(alert.text, "My Prompt") # Not the input field
16-
self.wait_for_and_dismiss_alert()
17-
self.sleep(0.8) # Not needed (Lets you see the alert go away)
13+
self.sleep(1) # Not needed (Lets you see the alert pop up)
14+
alert = self.switch_to_alert()
15+
self.assert_equal(alert.text, "My Prompt") # Not input field
16+
self.dismiss_alert()
17+
self.sleep(1) # Not needed (Lets you see the alert go away)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import pytest
2+
from seleniumbase import BaseCase
3+
4+
5+
@pytest.mark.offline # Can be run with: "pytest -m offline"
6+
class OfflineTestClass(BaseCase):
7+
8+
def test_alerts(self):
9+
self.open("data:,")
10+
self.execute_script('window.alert("ALERT!!!")')
11+
self.sleep(1) # Not needed (Lets you see the alert pop up)
12+
self.accept_alert()
13+
self.sleep(1) # Not needed (Lets you see the alert go away)
14+
self.execute_script('window.prompt("My Prompt","defaultText");')
15+
self.sleep(1) # Not needed (Lets you see the alert pop up)
16+
alert = self.switch_to_alert()
17+
self.assert_equal(alert.text, "My Prompt") # Not input field
18+
self.dismiss_alert()
19+
self.sleep(1) # Not needed (Lets you see the alert go away)

examples/offline_examples/test_demo_page.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
class OfflineTestClass(BaseCase):
88

99
def test_demo_page(self):
10-
# Load a local html file into the browser
11-
dir_name = os.path.dirname(os.path.abspath(__file__))
12-
self.load_html_file(dir_name + "/demo_page.html")
10+
# Load a local html file into the web browser
11+
dir_path = os.path.dirname(os.path.abspath(__file__))
12+
file_path = dir_path + "/demo_page.html"
13+
self.load_html_file(file_path)
1314

1415
# Assert the title of the current web page
1516
self.assert_title("Web Testing Page")

examples/test_deferred_asserts.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""
2+
This test demonstrates the use of deferred asserts.
3+
Deferred asserts won't raise exceptions from failures until either
4+
process_deferred_asserts() is called, or the test reaches the tearDown() step.
5+
"""
6+
import pytest
7+
from seleniumbase import BaseCase
8+
9+
10+
class MyTestClass(BaseCase):
11+
12+
@pytest.mark.expected_failure
13+
def test_deferred_asserts(self):
14+
self.open('https://xkcd.com/993/')
15+
self.wait_for_element('#comic')
16+
self.deferred_assert_element('img[alt="Brand Identity"]')
17+
self.deferred_assert_element('img[alt="Rocket Ship"]') # Will Fail
18+
self.deferred_assert_element('#comicmap')
19+
self.deferred_assert_text('Fake Item', '#middleContainer') # Will Fail
20+
self.deferred_assert_text('Random', '#middleContainer')
21+
self.deferred_assert_element('a[name="Super Fake !!!"]') # Will Fail
22+
self.process_deferred_asserts()

examples/test_delayed_asserts.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

examples/translations/french_test_1.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ def test_exemple_1(self):
99
self.vérifier_texte("Wikipédia") # noqa
1010
self.vérifier_élément('[title="Visiter la page d’accueil"]')
1111
self.modifier_texte("#searchInput", "Crème brûlée")
12-
self.cliquez_sur("#searchButton")
12+
self.cliquer("#searchButton")
1313
self.vérifier_texte("Crème brûlée", "#firstHeading")
1414
self.vérifier_élément('img[alt*="Crème brûlée"]')
1515
self.modifier_texte("#searchInput", "Jardin des Tuileries")
16-
self.cliquez_sur("#searchButton")
16+
self.cliquer("#searchButton")
1717
self.vérifier_texte("Jardin des Tuileries", "#firstHeading")
1818
self.vérifier_élément('img[alt*="Jardin des Tuileries"]')
1919
self.retour()

help_docs/method_summary.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -460,23 +460,29 @@ self.assert_text_not_visible(text, selector="html", by=By.CSS_SELECTOR, timeout=
460460

461461
############
462462

463-
self.wait_for_and_accept_alert(timeout=None)
463+
self.accept_alert(timeout=None)
464+
# Duplicates: self.wait_for_and_accept_alert(timeout=None)
464465

465-
self.wait_for_and_dismiss_alert(timeout=None)
466+
self.dismiss_alert(timeout=None)
467+
# Duplicates: self.wait_for_and_dismiss_alert(timeout=None)
466468

467-
self.wait_for_and_switch_to_alert(timeout=None)
469+
self.switch_to_alert(timeout=None)
470+
# Duplicates: self.wait_for_and_switch_to_alert(timeout=None)
468471

469472
############
470473

471474
self.check_window(name="default", level=0, baseline=False)
472475

473476
############
474477

475-
self.delayed_assert_element(selector, by=By.CSS_SELECTOR, timeout=None)
478+
self.deferred_assert_element(selector, by=By.CSS_SELECTOR, timeout=None)
479+
# Duplicates: self.delayed_assert_element(selector, by=By.CSS_SELECTOR, timeout=None)
476480

477-
self.delayed_assert_text(text, selector="html", by=By.CSS_SELECTOR, timeout=None)
481+
self.deferred_assert_text(text, selector="html", by=By.CSS_SELECTOR, timeout=None)
482+
# Duplicates: self.delayed_assert_text(text, selector="html", by=By.CSS_SELECTOR, timeout=None)
478483

479-
self.process_delayed_asserts()
484+
self.process_deferred_asserts(print_only=False)
485+
# Duplicates: self.process_delayed_asserts(print_only=False)
480486

481487
############
482488

0 commit comments

Comments
 (0)