|
| 1 | +import os |
| 2 | +import pytest |
| 3 | +from seleniumbase import BaseCase |
| 4 | +BaseCase.main(__name__, __file__) |
| 5 | + |
| 6 | + |
| 7 | +@pytest.mark.offline # Can be run with: "pytest -m offline" |
| 8 | +class OfflineTests(BaseCase): |
| 9 | + def test_extended_driver(self): |
| 10 | + # Load a local html file into the web browser |
| 11 | + dir_path = os.path.dirname(os.path.abspath(__file__)) |
| 12 | + file_path = os.path.join(dir_path, "demo_page.html") |
| 13 | + self.load_html_file(file_path) |
| 14 | + |
| 15 | + # Get the raw driver |
| 16 | + driver = self.driver |
| 17 | + |
| 18 | + # Assert that an element is visible on the page |
| 19 | + driver.assert_element("tbody#tbodyId") |
| 20 | + |
| 21 | + # Assert that a text substring appears in an element |
| 22 | + driver.assert_text("Demo Page", "h1") |
| 23 | + |
| 24 | + # Type text into various text fields and then assert |
| 25 | + driver.type("#myTextInput", "This is Automated") |
| 26 | + driver.type("textarea.area1", "Testing Time!\n") |
| 27 | + driver.type('[name="preText2"]', "Typing Text!") |
| 28 | + driver.assert_text("This is Automated", "#myTextInput") |
| 29 | + driver.assert_text("Testing Time!\n", "textarea.area1") |
| 30 | + driver.assert_text("Typing Text!", '[name="preText2"]') |
| 31 | + |
| 32 | + # Hover & click a dropdown element and assert results |
| 33 | + driver.assert_text("Automation Practice", "h3") |
| 34 | + driver.js_click("#dropOption2") |
| 35 | + driver.assert_text("Link Two Selected", "h3") |
| 36 | + |
| 37 | + # Click a button and then verify the expected results |
| 38 | + driver.assert_text("This Text is Green", "#pText") |
| 39 | + driver.click('button:contains("Click Me")') |
| 40 | + driver.assert_text("This Text is Purple", "#pText") |
| 41 | + |
| 42 | + # Assert that the given SVG is visible on the page |
| 43 | + driver.assert_element('svg[name="svgName"]') |
| 44 | + |
| 45 | + # Assert an element located inside an iframe |
| 46 | + self.assert_false(driver.is_element_visible("img")) |
| 47 | + driver.switch_to.frame("myFrame1") |
| 48 | + self.assert_true(driver.is_element_visible("img")) |
| 49 | + driver.switch_to.default_content() |
| 50 | + |
| 51 | + # Assert text located inside an iframe |
| 52 | + self.assert_false(driver.is_text_visible("iFrame Text")) |
| 53 | + driver.switch_to.frame("myFrame2") |
| 54 | + self.assert_true(driver.is_text_visible("iFrame Text")) |
| 55 | + driver.switch_to.default_content() |
| 56 | + |
| 57 | + # Assert exact text |
| 58 | + driver.assert_exact_text("Demo Page", "h1") |
| 59 | + |
| 60 | + # Highlight a page element (Also asserts visibility) |
| 61 | + driver.highlight("h2") |
0 commit comments