Skip to content

Commit efbef6a

Browse files
committed
make minor changes
1 parent 743fb53 commit efbef6a

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

docs/end-to-end-testing.qmd

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ Imagine you've built a beautiful, interactive Shiny app. You want to make sure
2222
* **Time saver:** Instead of manually clicking through your app every time you make a change, tests automate the process.
2323
* **Peace of mind:** Know that your app is working reliably, so you can focus on building new features.
2424

25-
### Introducing Playwright: Your Automated Testing Buddy
25+
### Introducing Playwright: A Comprehensive Automated Testing Solution for Web Applications
2626

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.
2828

2929
**Why Playwright is perfect for Shiny:**
3030

@@ -86,6 +86,7 @@ def test_basic_app(page: Page, local_app: ShinyAppProc) -> None:
8686
# Navigate to the app URL when it's ready
8787
page.goto(local_app.url)
8888

89+
# Controller objects for interacting with specific Shiny components
8990
txt = controller.OutputText(page, "txt")
9091
slider = controller.InputSlider(page, "n")
9192

@@ -97,42 +98,38 @@ def test_basic_app(page: Page, local_app: ShinyAppProc) -> None:
9798
txt.expect_value("n*2 is 110")
9899
```
99100

100-
1. **Understanding Fixtures**
101-
- `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.
102105

103-
2. **Code Breakdown:** Let's go through the code line by line:
106+
- **Understand role of Controllers**
104107

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:
106109

107-
* `from shiny.run import ShinyAppProc`: This imports `ShinyAppProc` (which represents our running Shiny app)
110+
- 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
108114

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:
110116

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.
120117

121118
![](assets/end-to-end-test-workflow.png)
122119

123120
#### Step 4: Run Your Test!
124121

125122
Before you run the test, you need to install a couple of things:
126123

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:
128125

129126
```bash
130127
pip install pytest pytest-playwright
131128
```
132129

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`.
134131

135-
3. **Run the test:** Type the following command and press Enter:
132+
3. **Run the test**: Type the following command and press Enter:
136133

137134
```bash
138135
pytest

0 commit comments

Comments
 (0)