|
| 1 | +from seleniumbase import BaseCase |
| 2 | + |
| 3 | + |
| 4 | +class MyTestClass(BaseCase): |
| 5 | + |
| 6 | + def test_demo_site(self): |
| 7 | + self.open("https://seleniumbase.io/demo_page") |
| 8 | + |
| 9 | + # Assert the title of the current web page |
| 10 | + self.assert_title("Web Testing Page") |
| 11 | + |
| 12 | + # Assert that the element is visible on the page |
| 13 | + self.assert_element("tbody#tbodyId") |
| 14 | + |
| 15 | + # Assert that the text appears within a given element |
| 16 | + self.assert_text("Demo Page", "h1") |
| 17 | + |
| 18 | + # Type/update text in text fields on the page |
| 19 | + self.type("#myTextInput", "This is Automated") |
| 20 | + self.type("textarea.area1", "Testing Time!\n") |
| 21 | + self.type('[name="preText2"]', "Typing Text!") |
| 22 | + |
| 23 | + # Verify that a hover dropdown link changes page text |
| 24 | + self.assert_text("Automation Practice", "h3") |
| 25 | + self.hover_and_click("#myDropdown", "#dropOption2") |
| 26 | + self.assert_text("Link Two Selected", "h3") |
| 27 | + |
| 28 | + # Verify that a button click changes text on the page |
| 29 | + self.assert_text("This Text is Green", "#pText") |
| 30 | + self.click("#myButton") |
| 31 | + self.assert_text("This Text is Purple", "#pText") |
| 32 | + |
| 33 | + # Assert that the given SVG is visible on the page |
| 34 | + self.assert_element('svg[name="svgName"]') |
| 35 | + |
| 36 | + # Verify that a slider control updates a progrss bar |
| 37 | + self.assert_element('progress[value="50"]') |
| 38 | + self.press_right_arrow("#myslider", times=5) |
| 39 | + self.assert_element('progress[value="100"]') |
| 40 | + |
| 41 | + # Verify that a "select" option updates a meter bar |
| 42 | + self.assert_element('meter[value="0.25"]') |
| 43 | + self.select_option_by_text("#mySelect", "Set to 75%") |
| 44 | + self.assert_element('meter[value="0.75"]') |
| 45 | + |
| 46 | + # Assert an element located inside an iFrame |
| 47 | + self.assert_false(self.is_element_visible("img")) |
| 48 | + self.switch_to_frame("#myFrame1") |
| 49 | + self.assert_true(self.is_element_visible("img")) |
| 50 | + self.switch_to_default_content() |
| 51 | + |
| 52 | + # Assert text located inside an iFrame |
| 53 | + self.assert_false(self.is_text_visible("iFrame Text")) |
| 54 | + self.switch_to_frame("#myFrame2") |
| 55 | + self.assert_true(self.is_text_visible("iFrame Text")) |
| 56 | + self.switch_to_default_content() |
| 57 | + |
| 58 | + # Verify that clicking a radio button selects it |
| 59 | + self.assert_false(self.is_selected("#radioButton2")) |
| 60 | + self.click("#radioButton2") |
| 61 | + self.assert_true(self.is_selected("#radioButton2")) |
| 62 | + |
| 63 | + # Verify that clicking a checkbox makes it selected |
| 64 | + self.assert_false(self.is_selected("#checkBox1")) |
| 65 | + self.click("#checkBox1") |
| 66 | + self.assert_true(self.is_selected("#checkBox1")) |
| 67 | + |
| 68 | + # Verify clicking on multiple elements with one call |
| 69 | + self.assert_false(self.is_selected("#checkBox2")) |
| 70 | + self.assert_false(self.is_selected("#checkBox3")) |
| 71 | + self.assert_false(self.is_selected("#checkBox4")) |
| 72 | + self.click_visible_elements("input.checkBoxClassB") |
| 73 | + self.assert_true(self.is_selected("#checkBox2")) |
| 74 | + self.assert_true(self.is_selected("#checkBox3")) |
| 75 | + self.assert_true(self.is_selected("#checkBox4")) |
| 76 | + |
| 77 | + # Verify that clicking an iFrame checkbox selects it |
| 78 | + self.assert_false(self.is_element_visible(".fBox")) |
| 79 | + self.switch_to_frame("#myFrame3") |
| 80 | + self.assert_true(self.is_element_visible(".fBox")) |
| 81 | + self.assert_false(self.is_selected(".fBox")) |
| 82 | + self.click(".fBox") |
| 83 | + self.assert_true(self.is_selected(".fBox")) |
| 84 | + self.switch_to_default_content() |
| 85 | + |
| 86 | + # Assert link text |
| 87 | + self.assert_link_text("seleniumbase.com") |
| 88 | + self.assert_link_text("SeleniumBase on GitHub") |
| 89 | + self.assert_link_text("seleniumbase.io") |
| 90 | + |
| 91 | + # Click link text |
| 92 | + self.click_link_text("SeleniumBase Demo Page") |
| 93 | + |
| 94 | + # Assert exact text |
| 95 | + self.assert_exact_text("Demo Page", "h1") |
| 96 | + |
| 97 | + # Assert no broken links (Can be slow if many links) |
| 98 | + # self.assert_no_404_errors() |
| 99 | + |
| 100 | + # Assert no JavaScript errors (Can also detect 404s) |
| 101 | + self.assert_no_js_errors() |
0 commit comments