|
| 1 | +from seleniumbase import BaseCase |
| 2 | + |
| 3 | + |
| 4 | +class DialogBoxTests(BaseCase): |
| 5 | + def test_dialog_boxes(self): |
| 6 | + self.open("https://xkcd.com/1920/") |
| 7 | + self.assert_element('img[alt="Emoji Sports"]') |
| 8 | + self.highlight("#comic img") |
| 9 | + |
| 10 | + skip_button = ["SKIP", "red"] # Can be a [text, color] list or tuple. |
| 11 | + buttons = ["Fencing", "Football", "Metaball", "Go/Chess", skip_button] |
| 12 | + message = "Choose a sport:" |
| 13 | + choice = None |
| 14 | + while choice != "STOP": |
| 15 | + choice = self.get_jqc_button_input(message, buttons) |
| 16 | + if choice == "Fencing": |
| 17 | + self.open("https://xkcd.com/1424/") |
| 18 | + buttons.remove("Fencing") |
| 19 | + elif choice == "Football": |
| 20 | + self.open("https://xkcd.com/1107/") |
| 21 | + buttons.remove("Football") |
| 22 | + elif choice == "Metaball": |
| 23 | + self.open("https://xkcd.com/1507/") |
| 24 | + buttons.remove("Metaball") |
| 25 | + elif choice == "Go/Chess": |
| 26 | + self.open("https://xkcd.com/1287/") |
| 27 | + buttons.remove("Go/Chess") |
| 28 | + else: |
| 29 | + break |
| 30 | + self.highlight("#comic img") |
| 31 | + if len(buttons) == 2: |
| 32 | + message = "One Sport Remaining:" |
| 33 | + if len(buttons) == 1: |
| 34 | + message = "Part One Complete. You saw all 4 sports!" |
| 35 | + btn_text_1 = "NEXT Tutorial Please!" |
| 36 | + btn_text_2 = "WAIT, Go/Chess is a sport?" |
| 37 | + buttons = [(btn_text_1, "green"), (btn_text_2, "purple")] |
| 38 | + choice_2 = self.get_jqc_button_input(message, buttons) |
| 39 | + if choice_2 == btn_text_2: |
| 40 | + self.open("https://xkcd.com/1287/") |
| 41 | + message = "Brain sports count as sports!<br /><br />" |
| 42 | + message += "Are you ready for more?" |
| 43 | + self.get_jqc_button_input(message, ["Let's Go!"]) |
| 44 | + break |
| 45 | + |
| 46 | + self.open("https://xkcd.com/1117/") |
| 47 | + sb_banner_logo = "//seleniumbase.io/cdn/img/sb_logo_cs.png" |
| 48 | + self.set_attributes("#news img", "src", sb_banner_logo) |
| 49 | + options = [("theme", "material"), ("width", "52%")] |
| 50 | + message = 'With one button, you can press "Enter/Return", "Y", or "1".' |
| 51 | + self.get_jqc_button_input(message, ["OK"], options) |
| 52 | + |
| 53 | + self.open("https://xkcd.com/556/") |
| 54 | + self.set_attributes("#news img", "src", sb_banner_logo) |
| 55 | + options = [("theme", "bootstrap"), ("width", "52%")] |
| 56 | + message = 'If the lowercase button text is "yes" or "no", ' |
| 57 | + message += '<br><br>you can use the "Y" or "N" keys as shortcuts. ' |
| 58 | + message += '<br><br><br>Other shortcuts include: <br><br>' |
| 59 | + message += '"1": 1st button, "2": 2nd button, etc. Got it?' |
| 60 | + buttons = [("YES", "green"), ("NO", "red")] |
| 61 | + choice = self.get_jqc_button_input(message, buttons, options) |
| 62 | + |
| 63 | + message = 'You said "%s"! <br><br>' % choice |
| 64 | + if choice == "YES": |
| 65 | + message += "Wonderful! Let's continue with the next example..." |
| 66 | + else: |
| 67 | + message += "You can learn more from SeleniumBase Docs..." |
| 68 | + choice = self.get_jqc_button_input(message, ["OK"], options) |
| 69 | + |
| 70 | + self.open("https://seleniumbase.io") |
| 71 | + self.set_jqc_theme("light", color="green", width="38%") |
| 72 | + message = "<b>This is the SeleniumBase Docs website!</b><br /><br />" |
| 73 | + message += "What would you like to search for?<br />" |
| 74 | + text = self.get_jqc_text_input(message, ["Search"]) |
| 75 | + self.update_text('input[aria-label="Search"]', text + "\n") |
| 76 | + self.wait_for_ready_state_complete() |
| 77 | + self.set_jqc_theme("bootstrap", color="red", width="32%") |
| 78 | + if self.is_text_visible("No matching documents", ".md-search-result"): |
| 79 | + self.get_jqc_button_input("Your search had no results!", ["OK"]) |
| 80 | + elif self.is_element_visible("a.md-search-result__link"): |
| 81 | + self.click("a.md-search-result__link") |
| 82 | + self.set_jqc_theme("bootstrap", color="green", width="32%") |
| 83 | + self.get_jqc_button_input("You found search results!", ["OK"]) |
| 84 | + elif self.is_text_visible("Type to start searching", "div.md-search"): |
| 85 | + self.get_jqc_button_input("You did not do a search!", ["OK"]) |
| 86 | + else: |
| 87 | + self.get_jqc_button_input("We're not sure what happened.", ["OK"]) |
| 88 | + |
| 89 | + self.open("https://seleniumbase.io/help_docs/ReadMe/") |
| 90 | + self.highlight("h1") |
| 91 | + self.highlight_click('a:contains("Running Example Tests")') |
| 92 | + self.highlight("h1") |
| 93 | + |
| 94 | + self.set_jqc_theme("bootstrap", color="green", width="52%") |
| 95 | + message = 'See the "SeleniumBase/examples" section for more info!' |
| 96 | + self.get_jqc_button_input(message, ["OK"]) |
| 97 | + |
| 98 | + self.set_jqc_theme("bootstrap", color="purple", width="56%") |
| 99 | + message = "Now let's combine form inputs with multiple button options!" |
| 100 | + message += "<br /><br />" |
| 101 | + message += "Pick something to search. Then pick the site to search on." |
| 102 | + buttons = ["XKCD.com", "Wikipedia.org"] |
| 103 | + text, choice = self.get_jqc_form_inputs(message, buttons) |
| 104 | + if choice == "XKCD.com": |
| 105 | + self.open("https://relevant-xkcd.github.io/") |
| 106 | + else: |
| 107 | + self.open("https://en.wikipedia.org/wiki/Main_Page") |
| 108 | + self.highlight_update_text('input[name="search"]', text + "\n") |
| 109 | + self.wait_for_ready_state_complete() |
| 110 | + self.highlight("body") |
| 111 | + self.reset_jqc_theme() |
| 112 | + self.get_jqc_button_input("<b>Here are your results.</b>", ["OK"]) |
| 113 | + message = "<h3>You've reached the end of this tutorial!</h3><br />" |
| 114 | + message += "Thanks for learning about SeleniumBase Dialog Boxes!<br />" |
| 115 | + message += "<br />Check out the SeleniumBase page on GitHub for more!" |
| 116 | + self.set_jqc_theme("modern", color="purple", width="56%") |
| 117 | + self.get_jqc_button_input(message, ["Goodbye!"]) |
0 commit comments