Update example tests
This commit is contained in:
parent
0d2a645611
commit
a5aefa4764
|
@ -19,6 +19,6 @@ class MyTestClass(BaseCase):
|
|||
self.assert_element("div#login_button_container")
|
||||
|
||||
|
||||
if __name__ == "__main__": # Use "python" to call "pytest"
|
||||
if __name__ == "__main__":
|
||||
from pytest import main
|
||||
main([__file__])
|
||||
main([__file__, "-s"])
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
"""Use SeleniumBase to test a Coffee Cart App."""
|
||||
from seleniumbase import BaseCase
|
||||
BaseCase.main(__name__, __file__)
|
||||
|
||||
|
||||
class CoffeeCartTests(BaseCase):
|
||||
def test_buy_one_cappuccino(self):
|
||||
self.open("https://seleniumbase.io/coffee/")
|
||||
self.click('div[data-test="Cappuccino"]')
|
||||
self.assert_exact_text("cart (1)", 'a[aria-label="Cart page"]')
|
||||
self.click('a[aria-label="Cart page"]')
|
||||
self.assert_exact_text("Total: $19.00", 'button[data-test="checkout"]')
|
||||
self.click('button[data-test="checkout"]')
|
||||
self.type("input#name", "Selenium Coffee")
|
||||
self.type("input#email", "test@test.test")
|
||||
self.click("button#submit-payment")
|
||||
self.assert_text("Thanks for your purchase.", "div#app div.success")
|
||||
self.assert_exact_text("cart (0)", 'a[aria-label="Cart page"]')
|
||||
self.assert_exact_text("Total: $0.00", 'button[data-test="checkout"]')
|
||||
|
||||
def test_coffee_promo_with_preview(self):
|
||||
self.open("https://seleniumbase.io/coffee/")
|
||||
self.click('div[data-test="Espresso"]')
|
||||
self.click('div[data-test="Americano"]')
|
||||
self.click('div[data-test="Cafe_Latte"]')
|
||||
self.assert_exact_text("cart (3)", 'a[aria-label="Cart page"]')
|
||||
self.assert_text("Get an extra cup of Mocha for $4.", "div.promo")
|
||||
self.click("div.promo button.yes")
|
||||
self.assert_exact_text("cart (4)", 'a[aria-label="Cart page"]')
|
||||
self.hover('button[data-test="checkout"]')
|
||||
self.assert_text("(Discounted) Mocha", "ul.cart-preview")
|
||||
self.assert_exact_text("Total: $37.00", 'button[data-test="checkout"]')
|
||||
self.click('button[data-test="checkout"]')
|
||||
self.type("input#name", "Selenium Coffee")
|
||||
self.type("input#email", "test@test.test")
|
||||
self.click("button#submit-payment")
|
||||
self.assert_text("Thanks for your purchase.", "div#app div.success")
|
||||
|
||||
def test_context_click_add_coffee(self):
|
||||
self.open("https://seleniumbase.io/coffee/")
|
||||
self.context_click('div[data-test="Espresso_Macchiato"]')
|
||||
self.click('form button:contains("Yes")')
|
||||
self.assert_exact_text("cart (1)", 'a[aria-label="Cart page"]')
|
||||
self.click('a[aria-label="Cart page"]')
|
||||
self.assert_exact_text("Total: $12.00", 'button[data-test="checkout"]')
|
||||
self.click('button[data-test="checkout"]')
|
||||
self.type("input#name", "Selenium Coffee")
|
||||
self.type("input#email", "test@test.test")
|
||||
self.click("button#submit-payment")
|
||||
self.assert_text("Thanks for your purchase.", "div#app div.success")
|
||||
|
||||
def test_remove_added_coffee(self):
|
||||
self.open("https://seleniumbase.io/coffee/")
|
||||
self.assert_exact_text("cart (0)", 'a[aria-label="Cart page"]')
|
||||
self.assert_exact_text("Total: $0.00", "button.pay")
|
||||
self.click_visible_elements('div[class="cup-body"]', limit=6)
|
||||
self.assert_exact_text("cart (6)", 'a[aria-label="Cart page"]')
|
||||
self.assert_exact_text("Total: $74.00", 'button[data-test="checkout"]')
|
||||
self.click('a[aria-label="Cart page"]')
|
||||
self.click_visible_elements("button.delete")
|
||||
self.assert_text("No coffee, go add some.", "div#app")
|
||||
self.click('a[aria-label="Menu page"]')
|
||||
self.assert_exact_text("cart (0)", 'a[aria-label="Cart page"]')
|
||||
self.assert_exact_text("Total: $0.00", 'button[data-test="checkout"]')
|
|
@ -28,9 +28,10 @@ class MyTestClass(BaseCase):
|
|||
self.assert_element("div#login_button_container")
|
||||
|
||||
|
||||
if __name__ == "__main__": # Use "python" to call "pytest"
|
||||
if __name__ == "__main__": # If "python", run pytest
|
||||
from pytest import main
|
||||
main([__file__])
|
||||
from sys import argv
|
||||
main([*argv, "-s"]) # Run pytest using same args
|
||||
|
||||
|
||||
#######################################################################
|
||||
|
|
|
@ -4,5 +4,5 @@ Two examples: pytest.main() and subprocess.call()."""
|
|||
import pytest
|
||||
import subprocess
|
||||
|
||||
pytest.main(["test_mfa_login.py", "--chrome", "-v"])
|
||||
pytest.main(["test_coffee_cart.py", "--chrome", "-v"])
|
||||
subprocess.call(["pytest", "test_mfa_login.py", "--chrome", "-v"])
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
"""Call a file with "python" instead of using "pytest" directly.
|
||||
To run, use: "python raw_file_call.py".
|
||||
Works by using pytest.main([__file__])."""
|
||||
On newer version of SeleniumBase, use:
|
||||
BaseCase.main(__name__, __file__)"""
|
||||
from seleniumbase import BaseCase
|
||||
|
||||
if __name__ == "__main__": # Use "python" to call "pytest"
|
||||
if __name__ == "__main__": # If "python", run pytest
|
||||
from pytest import main
|
||||
main([__file__])
|
||||
main([__file__, "-s"])
|
||||
|
||||
|
||||
class TinyMceTest(BaseCase):
|
||||
|
@ -19,5 +20,5 @@ class TinyMceTest(BaseCase):
|
|||
with self.frame_switch("iframe"):
|
||||
self.add_text("#tinymce", "SeleniumBase!")
|
||||
self.highlight("#tinymce")
|
||||
self.post_message("SeleniumBase is fast!")
|
||||
self.post_message("And SeleniumBase is fun!")
|
||||
self.post_message("SeleniumBase is fast!", duration=1.5)
|
||||
self.post_message("And SeleniumBase is fun!", duration=1.5)
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
"""Call a file with "python" instead of using "pytest" directly.
|
||||
To run, type: "python raw_main_call.py"."""
|
||||
from seleniumbase import BaseCase
|
||||
BaseCase.main(__name__, __file__)
|
||||
|
||||
|
||||
class TinyMceTest(BaseCase):
|
||||
def test_tinymce(self):
|
||||
self.open("https://seleniumbase.io/tinymce/")
|
||||
self.wait_for_element("div.mce-container-body")
|
||||
self.click('span:contains("File")')
|
||||
self.click('span:contains("New document")')
|
||||
self.click('span:contains("Paragraph")')
|
||||
self.click('span:contains("Heading 1")')
|
||||
with self.frame_switch("iframe"):
|
||||
self.add_text("#tinymce", "SeleniumBase!")
|
||||
self.highlight("#tinymce")
|
||||
self.post_message("SeleniumBase is fast!", duration=1.5)
|
||||
self.post_message("And SeleniumBase is fun!", duration=1.5)
|
|
@ -15,6 +15,6 @@ class CalculatorTests(BaseCase):
|
|||
self.assert_exact_text("54", "input#output")
|
||||
|
||||
|
||||
if __name__ == "__main__": # Use "python" to call "pytest"
|
||||
if __name__ == "__main__":
|
||||
from pytest import main
|
||||
main([__file__])
|
||||
main([__file__, "-s"])
|
||||
|
|
|
@ -1,22 +1,23 @@
|
|||
"""Use SeleniumBase to test a Coffee Cart App."""
|
||||
"""Use SeleniumBase to test the Coffee Cart App."""
|
||||
from seleniumbase import BaseCase
|
||||
|
||||
|
||||
class CoffeeCartTest(BaseCase):
|
||||
def test_coffee_cart(self):
|
||||
self.open("https://coffee-cart.netlify.app/")
|
||||
self.click('div[data-test="Cappuccino"]')
|
||||
self.click('div[data-test="Cafe_Latte"]')
|
||||
self.click('div[data-test="Cafe_Breve"]')
|
||||
self.open("https://seleniumbase.io/coffee/")
|
||||
self.click('div[data-sb="Cappuccino"]')
|
||||
self.click('div[data-sb="Flat-White"]')
|
||||
self.click('div[data-sb="Cafe-Latte"]')
|
||||
self.click('a[aria-label="Cart page"]')
|
||||
self.assert_exact_text("Total: $50.00", 'button[data-test="checkout"]')
|
||||
self.click('button[data-test="checkout"]')
|
||||
self.assert_exact_text("Total: $53.00", 'button.pay')
|
||||
self.click('button.pay')
|
||||
self.type("input#name", "Selenium Coffee")
|
||||
self.type("input#email", "test@test.test")
|
||||
self.click("button#submit-payment")
|
||||
self.assert_text("Thanks for your purchase.", "div#app div")
|
||||
self.assert_text("Thanks for your purchase.", "#app .success")
|
||||
|
||||
|
||||
if __name__ == "__main__": # Use "python" to call "pytest"
|
||||
if __name__ == "__main__": # If "python", run pytest
|
||||
from pytest import main
|
||||
main([__file__])
|
||||
from sys import argv
|
||||
main([*argv, "-s"]) # Run pytest using same args
|
||||
|
|
|
@ -119,4 +119,4 @@ class DemoSiteTests(BaseCase):
|
|||
|
||||
if __name__ == "__main__":
|
||||
from pytest import main
|
||||
main([__file__])
|
||||
main([__file__, "-s"])
|
||||
|
|
|
@ -53,4 +53,4 @@ class DownloadImages(BaseCase):
|
|||
|
||||
if __name__ == "__main__":
|
||||
from pytest import main
|
||||
main([__file__])
|
||||
main([__file__, "-s"])
|
||||
|
|
|
@ -16,6 +16,7 @@ class TestMFALogin(BaseCase):
|
|||
self.assert_exact_text("You have been signed out!", "#top_message")
|
||||
|
||||
|
||||
if __name__ == "__main__": # Use "python" to call "pytest"
|
||||
if __name__ == "__main__": # If "python", run pytest
|
||||
from pytest import main
|
||||
main([__file__])
|
||||
from sys import argv
|
||||
main([*argv, "-s"]) # Run pytest using same args
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
""" This test suite contains 2 passing tests and 2 failing tests. """
|
||||
|
||||
"""This test suite contains 2 passing tests and 2 failing tests."""
|
||||
import pytest
|
||||
from seleniumbase import BaseCase
|
||||
|
||||
|
|
|
@ -80,6 +80,7 @@ class SwagLabsTests(BaseCase):
|
|||
super(SwagLabsTests, self).tearDown()
|
||||
|
||||
|
||||
if __name__ == "__main__": # Use "python" to call "pytest"
|
||||
if __name__ == "__main__": # If "python", run pytest
|
||||
from pytest import main
|
||||
main([__file__])
|
||||
from sys import argv
|
||||
main([*argv, "-s"]) # Run pytest using same args
|
||||
|
|
|
@ -5,7 +5,7 @@ To evade detection, add --uc as a pytest command-line option.
|
|||
"""
|
||||
from seleniumbase import BaseCase
|
||||
|
||||
if __name__ == "__main__": # Use "python" to call "pytest"
|
||||
if __name__ == "__main__": # If "python", use "pytest"
|
||||
from pytest import main
|
||||
main([__file__, "--uc"])
|
||||
|
||||
|
|
|
@ -96,6 +96,6 @@ class WordleTests(BaseCase):
|
|||
self.sleep(3)
|
||||
|
||||
|
||||
if __name__ == "__main__": # Use "python" to call "pytest"
|
||||
if __name__ == "__main__":
|
||||
from pytest import main
|
||||
main([__file__])
|
||||
main([__file__, "-s"])
|
||||
|
|
Loading…
Reference in New Issue