Update example tests
This commit is contained in:
parent
ab6a47f01b
commit
ac39f5b635
|
@ -0,0 +1,13 @@
|
|||
Feature: SeleniumBase scenarios for the Simple App
|
||||
|
||||
Scenario: Verify Simple App (log in / sign out)
|
||||
Given Open "seleniumbase.io/simple/login"
|
||||
And Clear Session Storage
|
||||
And Type "demo_user" into "#username"
|
||||
And Type "secret_pass" into "#password"
|
||||
And Click 'a:contains("Sign in")'
|
||||
And Assert exact text "Welcome!" in "h1"
|
||||
And Assert element "img#image1"
|
||||
And Highlight "#image1"
|
||||
And Click link "Sign out"
|
||||
And Assert text "signed out" in "#top_message"
|
|
@ -284,12 +284,12 @@ class HackTests(BaseCase):
|
|||
self.open("https://wordpress.com/")
|
||||
zoom_out = "h1.is-page-header{zoom: 0.8;-moz-transform: scale(0.8);}"
|
||||
self.add_css_style(zoom_out)
|
||||
zoom_in = "div.lp-is-cta-blue{zoom: 1.4;-moz-transform: scale(1.4);}"
|
||||
zoom_in = "a.wp-element-button{zoom: 1.4;-moz-transform: scale(1.4);}"
|
||||
self.add_css_style(zoom_in)
|
||||
self.set_text_content("h1.is-page-header", aybabtu)
|
||||
self.set_text_content("main div.lp-is-cta-blue", "Use SeleniumBase!")
|
||||
self.set_text_content("a.wp-element-button", "Use SeleniumBase!")
|
||||
self.highlight("h1.is-page-header", loops=6, scroll=False)
|
||||
self.highlight("main div.lp-is-cta-blue", loops=4, scroll=False)
|
||||
self.highlight("a.wp-element-button", loops=4, scroll=False)
|
||||
|
||||
self.open("https://seleniumbase.com/")
|
||||
self.set_text_content("h1", aybabtu)
|
||||
|
|
|
@ -3,7 +3,7 @@ from seleniumbase import Driver
|
|||
|
||||
driver = Driver(browser="chrome", headless=False)
|
||||
try:
|
||||
driver.get("https://seleniumbase.io/apps/calculator")
|
||||
driver.open("seleniumbase.io/apps/calculator")
|
||||
driver.click('[id="4"]')
|
||||
driver.click('[id="2"]')
|
||||
driver.assert_text("42", "#output")
|
||||
|
@ -13,7 +13,7 @@ finally:
|
|||
|
||||
driver = Driver()
|
||||
try:
|
||||
driver.get("https://seleniumbase.github.io/demo_page")
|
||||
driver.open("seleniumbase.github.io/demo_page")
|
||||
driver.highlight("h2")
|
||||
driver.type("#myTextInput", "Automation")
|
||||
driver.click("#checkBox1")
|
||||
|
|
|
@ -2,18 +2,18 @@
|
|||
from seleniumbase import DriverContext
|
||||
|
||||
with DriverContext() as driver:
|
||||
driver.get("https://seleniumbase.github.io/")
|
||||
driver.open("seleniumbase.github.io/")
|
||||
driver.highlight('img[alt="SeleniumBase"]', loops=6)
|
||||
|
||||
with DriverContext(browser="chrome", incognito=True) as driver:
|
||||
driver.get("https://seleniumbase.io/apps/calculator")
|
||||
driver.open("seleniumbase.io/apps/calculator")
|
||||
driver.click('[id="4"]')
|
||||
driver.click('[id="2"]')
|
||||
driver.assert_text("42", "#output")
|
||||
driver.highlight("#output", loops=6)
|
||||
|
||||
with DriverContext() as driver:
|
||||
driver.get("https://seleniumbase.github.io/demo_page")
|
||||
driver.open("seleniumbase.github.io/demo_page")
|
||||
driver.highlight("h2")
|
||||
driver.type("#myTextInput", "Automation")
|
||||
driver.click("#checkBox1")
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
from seleniumbase import DriverContext
|
||||
|
||||
with DriverContext() as driver:
|
||||
driver.open("seleniumbase.io/simple/login")
|
||||
driver.type("#username", "demo_user")
|
||||
driver.type("#password", "secret_pass")
|
||||
driver.click('a:contains("Sign in")')
|
||||
driver.assert_exact_text("Welcome!", "h1")
|
||||
driver.assert_element("img#image1")
|
||||
driver.highlight("#image1")
|
||||
driver.click_link("Sign out")
|
||||
driver.assert_text("signed out", "#top_message")
|
|
@ -0,0 +1,15 @@
|
|||
from seleniumbase import Driver
|
||||
|
||||
driver = Driver()
|
||||
try:
|
||||
driver.open("seleniumbase.io/simple/login")
|
||||
driver.type("#username", "demo_user")
|
||||
driver.type("#password", "secret_pass")
|
||||
driver.click('a:contains("Sign in")')
|
||||
driver.assert_exact_text("Welcome!", "h1")
|
||||
driver.assert_element("img#image1")
|
||||
driver.highlight("#image1")
|
||||
driver.click_link("Sign out")
|
||||
driver.assert_text("signed out", "#top_message")
|
||||
finally:
|
||||
driver.quit()
|
|
@ -0,0 +1,12 @@
|
|||
from seleniumbase import SB
|
||||
|
||||
with SB() as sb:
|
||||
sb.open("seleniumbase.io/simple/login")
|
||||
sb.type("#username", "demo_user")
|
||||
sb.type("#password", "secret_pass")
|
||||
sb.click('a:contains("Sign in")')
|
||||
sb.assert_exact_text("Welcome!", "h1")
|
||||
sb.assert_element("img#image1")
|
||||
sb.highlight("#image1")
|
||||
sb.click_link("Sign out")
|
||||
sb.assert_text("signed out", "#top_message")
|
|
@ -11,7 +11,7 @@ with SB(uc=True) as sb:
|
|||
if not sb.is_text_visible("OH YEAH, you passed!", "h1"):
|
||||
if sb.is_element_visible('iframe[src*="challenge"]'):
|
||||
with sb.frame_switch('iframe[src*="challenge"]'):
|
||||
sb.click("area")
|
||||
sb.click("span.mark")
|
||||
sb.sleep(4)
|
||||
sb.activate_demo_mode()
|
||||
sb.assert_text("OH YEAH, you passed!", "h1", timeout=3)
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
# "sb" pytest fixture test in a method with no class
|
||||
def test_sb_fixture_with_no_class(sb):
|
||||
sb.open("seleniumbase.io/simple/login")
|
||||
sb.type("#username", "demo_user")
|
||||
sb.type("#password", "secret_pass")
|
||||
sb.click('a:contains("Sign in")')
|
||||
sb.assert_exact_text("Welcome!", "h1")
|
||||
sb.assert_element("img#image1")
|
||||
sb.highlight("#image1")
|
||||
sb.click_link("Sign out")
|
||||
sb.assert_text("signed out", "#top_message")
|
||||
|
||||
|
||||
# "sb" pytest fixture test in a method inside a class
|
||||
class Test_SB_Fixture:
|
||||
def test_sb_fixture_inside_class(self, sb):
|
||||
sb.open("seleniumbase.io/simple/login")
|
||||
sb.type("#username", "demo_user")
|
||||
sb.type("#password", "secret_pass")
|
||||
sb.click('a:contains("Sign in")')
|
||||
sb.assert_exact_text("Welcome!", "h1")
|
||||
sb.assert_element("img#image1")
|
||||
sb.highlight("#image1")
|
||||
sb.click_link("Sign out")
|
||||
sb.assert_text("signed out", "#top_message")
|
|
@ -7,6 +7,7 @@ def sb(request):
|
|||
from selenium import webdriver
|
||||
from seleniumbase import BaseCase
|
||||
from seleniumbase import config as sb_config
|
||||
from seleniumbase.core import session_helper
|
||||
|
||||
class BaseClass(BaseCase):
|
||||
def get_new_driver(self, *args, **kwargs):
|
||||
|
@ -31,6 +32,11 @@ def sb(request):
|
|||
super().tearDown()
|
||||
|
||||
if request.cls:
|
||||
if sb_config.reuse_class_session:
|
||||
the_class = str(request.cls).split(".")[-1].split("'")[0]
|
||||
if the_class != sb_config._sb_class:
|
||||
session_helper.end_reused_class_session_as_needed()
|
||||
sb_config._sb_class = the_class
|
||||
request.cls.sb = BaseClass("base_method")
|
||||
request.cls.sb.setUp()
|
||||
request.cls.sb._needs_tearDown = True
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# "sb" pytest fixture test in a method with no class
|
||||
def test_sb_fixture_with_no_class(sb):
|
||||
sb.open("https://seleniumbase.io/help_docs/install/")
|
||||
sb.open("seleniumbase.io/help_docs/install/")
|
||||
sb.type('input[aria-label="Search"]', "GUI Commander")
|
||||
sb.click('mark:contains("Commander")')
|
||||
sb.assert_title_contains("GUI / Commander")
|
||||
|
@ -9,7 +9,7 @@ def test_sb_fixture_with_no_class(sb):
|
|||
# "sb" pytest fixture test in a method inside a class
|
||||
class Test_SB_Fixture:
|
||||
def test_sb_fixture_inside_class(self, sb):
|
||||
sb.open("https://seleniumbase.io/help_docs/install/")
|
||||
sb.open("seleniumbase.io/help_docs/install/")
|
||||
sb.type('input[aria-label="Search"]', "GUI Commander")
|
||||
sb.click('mark:contains("Commander")')
|
||||
sb.assert_title_contains("GUI / Commander")
|
||||
|
|
|
@ -4,7 +4,7 @@ BaseCase.main(__name__, __file__)
|
|||
|
||||
class ScrapeBingTests(BaseCase):
|
||||
def test_scrape_bing(self):
|
||||
self.open(r"https://www.bing.com/search?q=SeleniumBase%20GitHub")
|
||||
self.open("www.bing.com/search?q=SeleniumBase+GitHub&qs=n&form=QBRE")
|
||||
self.wait_for_element("main h2 a")
|
||||
soup = self.get_beautiful_soup()
|
||||
titles = [item.text for item in soup.select("main h2 a")]
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
from seleniumbase import BaseCase
|
||||
BaseCase.main(__name__, __file__)
|
||||
|
||||
|
||||
class TestSimpleLogin(BaseCase):
|
||||
def test_simple_login(self):
|
||||
self.open("seleniumbase.io/simple/login")
|
||||
self.type("#username", "demo_user")
|
||||
self.type("#password", "secret_pass")
|
||||
self.click('a:contains("Sign in")')
|
||||
self.assert_exact_text("Welcome!", "h1")
|
||||
self.assert_element("img#image1")
|
||||
self.highlight("#image1")
|
||||
self.click_link("Sign out")
|
||||
self.assert_text("signed out", "#top_message")
|
|
@ -34,7 +34,7 @@ class CDPTests(BaseCase):
|
|||
except Exception:
|
||||
if self.is_element_visible('iframe[src*="challenge"]'):
|
||||
with self.frame_switch('iframe[src*="challenge"]'):
|
||||
self.click("area")
|
||||
self.click("span.mark")
|
||||
else:
|
||||
self.fail_me()
|
||||
try:
|
||||
|
|
|
@ -29,7 +29,7 @@ class UndetectedTest(BaseCase):
|
|||
except Exception:
|
||||
if self.is_element_visible('iframe[src*="challenge"]'):
|
||||
with self.frame_switch('iframe[src*="challenge"]'):
|
||||
self.click("area")
|
||||
self.click("span.mark")
|
||||
else:
|
||||
self.fail_me()
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue