You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/end-to-end-testing.qmd
+17-20Lines changed: 17 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -22,9 +22,9 @@ Imagine you've built a beautiful, interactive Shiny app. You want to make sure
22
22
***Time saver:** Instead of manually clicking through your app every time you make a change, tests automate the process.
23
23
***Peace of mind:** Know that your app is working reliably, so you can focus on building new features.
24
24
25
-
### Introducing Playwright: Your Automated Testing Buddy
25
+
### Introducing Playwright: A Comprehensive Automated Testing Solution for Web Applications
26
26
27
-
Playwright is a fantastic, free tool (made by Microsoft) that lets you automate web browsers. Think of it as a robot that can control Chrome, Firefox, or Safari and interact with your Shiny app just like a human would.
27
+
***Playwright*** is a robust, open-source automation framework developed by Microsoft that enables programmatic control of web browsers. This tool provides developers with the capability to automate interactions with web applications across Chrome, Firefox, and Safari, simulating user behavior in a controlled, reproducible environment.
-`ShinyAppProc` class manages a Shiny web application as a subprocess, handling its lifecycle (startup, monitoring, and shutdown) while providing access to its output streams and status.
101
+
-**Understand role of Fixtures**
102
+
-**ShinyAppProc**: Manages a Shiny application subprocess, handling lifecycle (startup, shutdown) and providing access to output streams.
103
+
-**page**: Playwright object representing the browser tab.
104
+
-**local_app**: Running instance of the Shiny application.
102
105
103
-
2.**Code Breakdown:** Let's go through the code line by line:
106
+
-**Understand role of Controllers**
104
107
105
-
*`from shiny.playwright import controller`: This imports the `controller` module, which gives us tools to interact with Shiny components.
108
+
Controllers such as `OutputText` and `InputSlider` provide abstraction over Playwright's low-level interactions by:
- Automatically handling element waiting and state changes
111
+
- Offering specialized interfaces for specific Shiny component types
112
+
- Managing Shiny-specific behaviors without additional code
113
+
- Providing consistent patterns for testing similar components
108
114
109
-
*`def test_basic_app(page: Page, local_app: ShinyAppProc) -> None:`: This defines our test function. The `page` argument is a Playwright object representing the browser tab, and `local_app` represents our running Shiny app.
115
+
And visually, this is what happens when the test runs:
110
116
111
-
*`page.goto(local_app.url)`: This tells Playwright to open the Shiny app in the browser.
112
-
113
-
*`txt = controller.OutputText(page, "txt")`: This creates an object that lets us interact with the text output (which has the ID "txt" in our app).
114
-
115
-
*`slider = controller.InputSlider(page, "n")`: This creates an object to control the slider (which has the ID "n").
116
-
117
-
*`slider.set("55")`: This moves the slider to the value 55.
118
-
119
-
*`txt.expect_value("n*2 is 110")`: This checks if the text output matches the expected value. If it doesn't, the test will fail.
120
117
121
118

122
119
123
120
#### Step 4: Run Your Test!
124
121
125
122
Before you run the test, you need to install a couple of things:
126
123
127
-
1.**Install pytest and pytest-playwright:** Open your terminal (or command prompt) and type:
124
+
1.**Install pytest and pytest-playwright**: Open your terminal (or command prompt) and type:
128
125
129
126
```bash
130
127
pip install pytest pytest-playwright
131
128
```
132
129
133
-
2.**Navigate to your app's directory:** In the terminal, use the `cd` command to go to the folder where you saved `app.py` and `test_basic_app.py`.
130
+
2.**Navigate to your app's directory**: In the terminal, use the `cd` command to go to the folder where you saved `app.py` and `test_basic_app.py`.
134
131
135
-
3.**Run the test:** Type the following command and press Enter:
132
+
3.**Run the test**: Type the following command and press Enter:
0 commit comments