|
1 | | -"""Example of using various CDP Mode commands via sb.cdp""" |
| 1 | +"""Example of using various CDP Mode commands.""" |
2 | 2 | from seleniumbase import SB |
3 | 3 |
|
4 | 4 | with SB(uc=True, test=True) as sb: |
5 | 5 | sb.activate_cdp_mode() |
6 | | - sb.cdp.goto("https://seleniumbase.io/demo_page") |
| 6 | + sb.goto("https://seleniumbase.io/demo_page") |
7 | 7 |
|
8 | 8 | # Assert various things |
9 | | - sb.cdp.assert_title("Web Testing Page") |
10 | | - sb.cdp.assert_element("tbody#tbodyId") |
11 | | - sb.cdp.assert_text("Demo Page", "h1") |
| 9 | + sb.assert_title("Web Testing Page") |
| 10 | + sb.assert_element("tbody#tbodyId") |
| 11 | + sb.assert_text("Demo Page", "h1") |
12 | 12 |
|
13 | 13 | # Type text into various text fields and then assert |
14 | | - sb.cdp.type("#myTextInput", "This is Automated") |
15 | | - sb.cdp.type("textarea.area1", "Testing Time!\n") |
16 | | - sb.cdp.type('[name="preText2"]', "Typing Text!") |
17 | | - sb.cdp.assert_text("This is Automated", "#myTextInput") |
18 | | - sb.cdp.assert_text("Testing Time!\n", "textarea.area1") |
19 | | - sb.cdp.assert_text("Typing Text!", '[name="preText2"]') |
| 14 | + sb.type("#myTextInput", "This is Automated") |
| 15 | + sb.type("textarea.area1", "Testing Time!\n") |
| 16 | + sb.type('[name="preText2"]', "Typing Text!") |
| 17 | + sb.assert_text("This is Automated", "#myTextInput") |
| 18 | + sb.assert_text("Testing Time!\n", "textarea.area1") |
| 19 | + sb.assert_text("Typing Text!", '[name="preText2"]') |
20 | 20 |
|
21 | 21 | # Hover & click a dropdown element and assert results |
22 | | - sb.cdp.assert_text("Automation Practice", "h3") |
23 | | - sb.cdp.hover_and_click("#myDropdown", "#dropOption2") |
24 | | - sb.cdp.assert_text("Link Two Selected", "h3") |
| 22 | + sb.assert_text("Automation Practice", "h3") |
| 23 | + sb.hover_and_click("#myDropdown", "#dropOption2") |
| 24 | + sb.assert_text("Link Two Selected", "h3") |
25 | 25 |
|
26 | 26 | # Click a button and then verify the expected results |
27 | | - sb.cdp.assert_text("This Text is Green", "#pText") |
28 | | - sb.cdp.click('button:contains("Click Me")') |
29 | | - sb.cdp.assert_text("This Text is Purple", "#pText") |
| 27 | + sb.assert_text("This Text is Green", "#pText") |
| 28 | + sb.click('button:contains("Click Me")') |
| 29 | + sb.assert_text("This Text is Purple", "#pText") |
30 | 30 |
|
31 | 31 | # Verify that a slider control updates a progress bar |
32 | | - sb.cdp.assert_element('progress[value="50"]') |
33 | | - sb.cdp.set_value("input#mySlider", "100") |
34 | | - sb.cdp.assert_element('progress[value="100"]') |
| 32 | + sb.assert_element('progress[value="50"]') |
| 33 | + sb.set_value("input#mySlider", "100") |
| 34 | + sb.assert_element('progress[value="100"]') |
35 | 35 |
|
36 | 36 | # Verify that a "select" option updates a meter bar |
37 | | - sb.cdp.assert_element('meter[value="0.25"]') |
38 | | - sb.cdp.select_option_by_text("#mySelect", "Set to 75%") |
39 | | - sb.cdp.assert_element('meter[value="0.75"]') |
| 37 | + sb.assert_element('meter[value="0.25"]') |
| 38 | + sb.select_option_by_text("#mySelect", "Set to 75%") |
| 39 | + sb.assert_element('meter[value="0.75"]') |
40 | 40 |
|
41 | 41 | # Verify that clicking a radio button selects it |
42 | | - sb.cdp.assert_false(sb.cdp.is_selected("#radioButton2")) |
43 | | - sb.cdp.click("#radioButton2") |
44 | | - sb.cdp.assert_true(sb.cdp.is_selected("#radioButton2")) |
| 42 | + sb.assert_false(sb.is_selected("#radioButton2")) |
| 43 | + sb.click("#radioButton2") |
| 44 | + sb.assert_true(sb.is_selected("#radioButton2")) |
45 | 45 |
|
46 | 46 | # Verify that clicking a checkbox makes it selected |
47 | | - sb.cdp.assert_element_not_visible("img#logo") |
48 | | - sb.cdp.assert_false(sb.cdp.is_selected("#checkBox1")) |
49 | | - sb.cdp.click("#checkBox1") |
50 | | - sb.cdp.assert_true(sb.cdp.is_selected("#checkBox1")) |
51 | | - sb.cdp.assert_element("img#logo") |
| 47 | + sb.assert_element_not_visible("img#logo") |
| 48 | + sb.assert_false(sb.is_selected("#checkBox1")) |
| 49 | + sb.click("#checkBox1") |
| 50 | + sb.assert_true(sb.is_selected("#checkBox1")) |
| 51 | + sb.assert_element("img#logo") |
52 | 52 |
|
53 | 53 | # Verify clicking on multiple elements with one call |
54 | | - sb.cdp.assert_false(sb.cdp.is_selected("#checkBox2")) |
55 | | - sb.cdp.assert_false(sb.cdp.is_selected("#checkBox3")) |
56 | | - sb.cdp.assert_false(sb.cdp.is_selected("#checkBox4")) |
57 | | - sb.cdp.click_visible_elements("input.checkBoxClassB") |
58 | | - sb.cdp.assert_true(sb.cdp.is_selected("#checkBox2")) |
59 | | - sb.cdp.assert_true(sb.cdp.is_selected("#checkBox3")) |
60 | | - sb.cdp.assert_true(sb.cdp.is_selected("#checkBox4")) |
| 54 | + sb.assert_false(sb.is_selected("#checkBox2")) |
| 55 | + sb.assert_false(sb.is_selected("#checkBox3")) |
| 56 | + sb.assert_false(sb.is_selected("#checkBox4")) |
| 57 | + sb.click_visible_elements("input.checkBoxClassB") |
| 58 | + sb.assert_true(sb.is_selected("#checkBox2")) |
| 59 | + sb.assert_true(sb.is_selected("#checkBox3")) |
| 60 | + sb.assert_true(sb.is_selected("#checkBox4")) |
61 | 61 |
|
62 | 62 | # Verify Drag and Drop |
63 | | - sb.cdp.assert_element_not_visible("div#drop2 img#logo") |
64 | | - sb.cdp.gui_drag_and_drop("img#logo", "div#drop2") |
65 | | - sb.cdp.assert_element("div#drop2 img#logo") |
| 63 | + sb.assert_element_not_visible("div#drop2 img#logo") |
| 64 | + sb.gui_drag_and_drop("img#logo", "div#drop2") |
| 65 | + sb.assert_element("div#drop2 img#logo") |
66 | 66 |
|
67 | 67 | # Click inside an iframe and test highlighting |
68 | | - sb.cdp.flash("iframe#myFrame3") |
69 | | - sb.cdp.sleep(1) |
70 | | - sb.cdp.nested_click("iframe#myFrame3", ".fBox") |
71 | | - sb.cdp.sleep(0.5) |
72 | | - sb.cdp.highlight("iframe#myFrame3") |
| 68 | + sb.flash("iframe#myFrame3") |
| 69 | + sb.sleep(1) |
| 70 | + sb.nested_click("iframe#myFrame3", ".fBox") |
| 71 | + sb.sleep(0.5) |
| 72 | + sb.highlight("iframe#myFrame3") |
0 commit comments