|
| 1 | +<h3 align="left"><img src="https://seleniumbase.io/cdn/img/sb_logo_b.png" alt="SeleniumBase" width="320" /></h3> |
| 2 | + |
| 3 | +<h2><img src="https://seleniumbase.io/img/logo6.png" title="SeleniumBase" width="32" /> 🛂 Dialog Boxes 🛂</h2> |
| 4 | + |
| 5 | +SeleniumBase Dialog Boxes let your users provide input in the middle of automation scripts. |
| 6 | + |
| 7 | +* This feature utilizes the [jquery-confirm](https://craftpip.github.io/jquery-confirm/) library. |
| 8 | +* A Python API is used to call the JavaScript API. |
| 9 | + |
| 10 | +<img src="https://seleniumbase.io/cdn/img/emoji_sports_dialog.png" alt="SeleniumBase" width="440" /> |
| 11 | + |
| 12 | +<h4>↕️ (<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/dialog_boxes/dialog_box_tour.py">Example: dialog_box_tour.py</a>) ↕️</h4> |
| 13 | + |
| 14 | +<img src="https://seleniumbase.io/cdn/gif/sports_dialog.gif" alt="SeleniumBase" width="440" /> |
| 15 | + |
| 16 | +<h4>Here's how to run that example:</h4> |
| 17 | + |
| 18 | +```bash |
| 19 | +cd examples/dialog_boxes |
| 20 | +pytest test_dialog_boxes.py |
| 21 | +``` |
| 22 | + |
| 23 | +<h4>Here's a code snippet from that:</h4> |
| 24 | + |
| 25 | +```python |
| 26 | +self.open("https://xkcd.com/1920/") |
| 27 | +skip_button = ["SKIP", "red"] # Can be a [text, color] list or tuple. |
| 28 | +buttons = ["Fencing", "Football", "Metaball", "Go/Chess", skip_button] |
| 29 | +message = "Choose a sport:" |
| 30 | +choice = self.get_jqc_button_input(message, buttons) |
| 31 | +if choice == "Fencing": |
| 32 | + self.open("https://xkcd.com/1424/") |
| 33 | +``` |
| 34 | + |
| 35 | +* You can create forms that include buttons and input fields. |
| 36 | + |
| 37 | +<h4>Here's a simple form with only buttons as input:</h4> |
| 38 | + |
| 39 | +```python |
| 40 | +choice = self.get_jqc_button_input("Ready?", ["YES", "NO"]) |
| 41 | +print(choice) # This prints "YES" or "NO" |
| 42 | + |
| 43 | +# You may want to customize the color of buttons: |
| 44 | +buttons = [("YES", "green"), ("NO", "red")] |
| 45 | +choice = self.get_jqc_button_input("Ready?", buttons) |
| 46 | +``` |
| 47 | + |
| 48 | +<h4>Here's a simple form with an input field:</h4> |
| 49 | + |
| 50 | +```python |
| 51 | +text = self.get_jqc_text_input("Enter text:", ["Search"]) |
| 52 | +print(text) # This prints the text entered |
| 53 | +``` |
| 54 | + |
| 55 | +<h4>This form has an input field and buttons:</h4> |
| 56 | + |
| 57 | +```python |
| 58 | +message = "Type your name and choose a language:" |
| 59 | +buttons = ["Python", "JavaScript"] |
| 60 | +text, choice = self.get_jqc_form_inputs(message, buttons) |
| 61 | +print("Your name is: %s" % text) |
| 62 | +print("You picked %s!" % choice) |
| 63 | +``` |
| 64 | + |
| 65 | +<h4>You can customize options if you want:</h4> |
| 66 | + |
| 67 | +```python |
| 68 | +# Themes: bootstrap, modern, material, supervan, light, dark, seamless |
| 69 | +options = [("theme", "modern"), ("width", "50%")] |
| 70 | +self.get_jqc_text_input("You Won!", ["OK"], options) |
| 71 | +``` |
| 72 | + |
| 73 | +<h4>Default options can be set with <code>set_jqc_theme()</code>:</h4> |
| 74 | + |
| 75 | +```python |
| 76 | +self.set_jqc_theme("light", color="green", width="38%") |
| 77 | + |
| 78 | +# To reset jqc theme settings to factory defaults: |
| 79 | +self.reset_jqc_theme() |
| 80 | +``` |
| 81 | + |
| 82 | +<h3>All methods for Dialog Boxes:</h3> |
| 83 | + |
| 84 | +```python |
| 85 | +self.get_jqc_button_input(message, buttons, options=None) |
| 86 | + |
| 87 | +self.get_jqc_text_input(message, button=None, options=None) |
| 88 | + |
| 89 | +self.get_jqc_form_inputs(message, buttons, options=None) |
| 90 | + |
| 91 | +self.set_jqc_theme(theme, color=None, width=None) |
| 92 | + |
| 93 | +self.reset_jqc_theme() |
| 94 | + |
| 95 | +self.activate_jquery_confirm() # Automatic for jqc methods |
| 96 | +``` |
| 97 | + |
| 98 | +<h3>Detailed method summaries for Dialog Boxes:</h3> |
| 99 | + |
| 100 | +```python |
| 101 | +self.get_jqc_button_input(message, buttons, options=None) |
| 102 | +""" |
| 103 | +Pop up a jquery-confirm box and return the text of the button clicked. |
| 104 | +If running in headless mode, the last button text is returned. |
| 105 | +@Params |
| 106 | +message: The message to display in the jquery-confirm dialog. |
| 107 | +buttons: A list of tuples for text and color. |
| 108 | + Example: [("Yes!", "green"), ("No!", "red")] |
| 109 | + Available colors: blue, green, red, orange, purple, default, dark. |
| 110 | + A simple text string also works: "My Button". (Uses default color.) |
| 111 | +options: A list of tuples for options to set. |
| 112 | + Example: [("theme", "bootstrap"), ("width", "450px")] |
| 113 | + Available theme options: bootstrap, modern, material, supervan, |
| 114 | + light, dark, and seamless. |
| 115 | + Available colors: (For the BORDER color, NOT the button color.) |
| 116 | + "blue", "default", "green", "red", "purple", "orange", "dark". |
| 117 | + Example option for changing the border color: ("color", "default") |
| 118 | + Width can be set using percent or pixels. Eg: "36.0%", "450px". |
| 119 | +""" |
| 120 | + |
| 121 | +self.get_jqc_text_input(message, button=None, options=None) |
| 122 | +""" |
| 123 | +Pop up a jquery-confirm box and return the text submitted by the input. |
| 124 | +If running in headless mode, the text returned is "" by default. |
| 125 | +@Params |
| 126 | +message: The message to display in the jquery-confirm dialog. |
| 127 | +button: A 2-item list or tuple for text and color. Or just the text. |
| 128 | + Example: ["Submit", "blue"] -> (default button if not specified) |
| 129 | + Available colors: blue, green, red, orange, purple, default, dark. |
| 130 | + A simple text string also works: "My Button". (Uses default color.) |
| 131 | +options: A list of tuples for options to set. |
| 132 | + Example: [("theme", "bootstrap"), ("width", "450px")] |
| 133 | + Available theme options: bootstrap, modern, material, supervan, |
| 134 | + light, dark, and seamless. |
| 135 | + Available colors: (For the BORDER color, NOT the button color.) |
| 136 | + "blue", "default", "green", "red", "purple", "orange", "dark". |
| 137 | + Example option for changing the border color: ("color", "default") |
| 138 | + Width can be set using percent or pixels. Eg: "36.0%", "450px". |
| 139 | +""" |
| 140 | + |
| 141 | +self.get_jqc_form_inputs(message, buttons, options=None) |
| 142 | +""" |
| 143 | +Pop up a jquery-confirm box and return the input/button texts as tuple. |
| 144 | +If running in headless mode, returns the ("", buttons[-1][0]) tuple. |
| 145 | +@Params |
| 146 | +message: The message to display in the jquery-confirm dialog. |
| 147 | +buttons: A list of tuples for text and color. |
| 148 | + Example: [("Yes!", "green"), ("No!", "red")] |
| 149 | + Available colors: blue, green, red, orange, purple, default, dark. |
| 150 | + A simple text string also works: "My Button". (Uses default color.) |
| 151 | +options: A list of tuples for options to set. |
| 152 | + Example: [("theme", "bootstrap"), ("width", "450px")] |
| 153 | + Available theme options: bootstrap, modern, material, supervan, |
| 154 | + light, dark, and seamless. |
| 155 | + Available colors: (For the BORDER color, NOT the button color.) |
| 156 | + "blue", "default", "green", "red", "purple", "orange", "dark". |
| 157 | + Example option for changing the border color: ("color", "default") |
| 158 | + Width can be set using percent or pixels. Eg: "36.0%", "450px". |
| 159 | +""" |
| 160 | + |
| 161 | +self.set_jqc_theme(theme, color=None, width=None) |
| 162 | +""" Sets the default jquery-confirm theme and width (optional). |
| 163 | +Available themes: "bootstrap", "modern", "material", "supervan", |
| 164 | + "light", "dark", and "seamless". |
| 165 | +Available colors: (This sets the BORDER color, NOT the button color.) |
| 166 | + "blue", "default", "green", "red", "purple", "orange", "dark". |
| 167 | +Width can be set using percent or pixels. Eg: "36.0%", "450px". |
| 168 | +""" |
| 169 | + |
| 170 | +self.reset_jqc_theme() |
| 171 | +""" Resets the jqc theme settings to factory defaults. """ |
| 172 | + |
| 173 | +self.activate_jquery_confirm() # Automatic for jqc methods |
| 174 | +""" See https://craftpip.github.io/jquery-confirm/ for usage. """ |
| 175 | +``` |
| 176 | + |
| 177 | +-------- |
| 178 | + |
| 179 | +<h4>✅ 🛂 Automated/Manual Hybrid Mode (MasterQA)</h4> |
| 180 | +<p><b><a href="https://seleniumbase.io/seleniumbase/masterqa/ReadMe/">MasterQA</a></b> uses <b>SeleniumBase Dialog Boxes</b> to speed up manual testing by having automation perform all the browser actions while the manual tester handles validation. See <a href="https://github.com/seleniumbase/SeleniumBase/tree/master/examples/master_qa">the MasterQA GitHub page</a> for examples.</p> |
0 commit comments