Skip to content

Commit 70938f6

Browse files
committed
feat: add use case section
1 parent d99cdf0 commit 70938f6

File tree

1 file changed

+66
-2
lines changed

1 file changed

+66
-2
lines changed

README.md

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,67 @@ Each captured flow includes the method, URL, headers, and parsed JSON request/re
197197

198198
---
199199

200-
## 🙌 Contributions
200+
## 📚 Use Cases
201+
202+
### ✅ Automated Network Testing for Android & iOS
201203

202-
Feel free to extend this tool with more proxy automation, better cert handling, or a simple UI for the control endpoints.
204+
You can integrate `mitmproxy` recording into your mobile test lifecycle to verify network behavior during test execution.
205+
206+
---
207+
208+
### 🔁 Example Flow:
209+
210+
1. **Start mitmproxy with the addon** (before your test suite):
211+
212+
```bash
213+
mitmdump -p 8080 -s proxy-session-controller.py
214+
```
215+
216+
2. **Start recording flows** (before your test begins):
217+
218+
```bash
219+
curl http://localhost:9999/start_recording
220+
```
221+
222+
3. **Run your UI/E2E test** that performs network requests from the Android emulator or iOS simulator.
223+
224+
4. **Stop recording after the test is finished**:
225+
226+
```bash
227+
curl http://localhost:9999/stop_recording
228+
```
229+
230+
5. **Validate the output** in `flows.json` using a custom validation script.
231+
232+
---
233+
234+
### 🧪 Example: Test Validation Script (Python)
235+
236+
```python
237+
import json
238+
239+
with open("flows.json") as f:
240+
flows = json.load(f)
241+
242+
expected_url = "https://api.example.com/data"
243+
matched = any(flow["request"]["url"] == expected_url for flow in flows)
244+
245+
assert matched, f"Expected request to {expected_url} not found!"
246+
print("[✓] Network request verified.")
247+
```
248+
249+
---
250+
251+
### 💡 Use With Your Test Framework
252+
253+
In your test framework (e.g., XCTest for iOS, Espresso or UIAutomator for Android), you can:
254+
255+
- Trigger `/start_recording` in the test setup phase
256+
- Run the UI interaction
257+
- Trigger `/stop_recording` in the test teardown
258+
- Run a validation script after the test completes
259+
260+
This allows you to **assert that expected network calls were made**, validate request payloads, and check response data without needing to modify your app code.
203261

204262
---
205263

@@ -219,3 +277,9 @@ networksetup -listallnetworkservices | tail +2 | while read -r interface; do
219277
networksetup -setsecurewebproxystate "$interface" off
220278
done
221279
```
280+
281+
---
282+
283+
## 🙌 Contributions
284+
285+
Feel free to extend this tool with more proxy automation, better cert handling, or a simple UI for the control endpoints.

0 commit comments

Comments
 (0)