-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_route.py
More file actions
69 lines (47 loc) · 1.86 KB
/
test_route.py
File metadata and controls
69 lines (47 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import json
from playwright.sync_api import Route, Request
# read more https://playwright.dev/python/docs/network
def test_review(alice):
# use list as reference object to transfer data from handler to test
request_data = list()
def handler(route: Route, request: Request):
request_data.append(request.post_data_json)
route.continue_()
# can be done in context manager
alice.goto('/tests/')
alice.route('**/status', handler)
alice.click('tbody tr >> nth=0 >> .passBtn')
alice.unroute('**/status', handler)
assert request_data[0] == {'status': 'PASS'}
def test_fulfill(alice):
def handler(route: Route, request: Request):
route.fulfill(status=200, body=json.dumps({"runId": 1000}))
# can be done in context manager
alice.goto('/tests/')
alice.click('tbody tr >> nth=0 >> .passBtn')
alice.route('**/status', handler)
alice.click('tbody tr >> nth=0 >> .failBtn')
alice.unroute('**/status', handler)
alice.reload()
assert alice.text_content('.testRow_1 .ttStatus') == 'PASS'
def test_modify(alice):
def handler(route: Route, request: Request):
route.continue_(post_data=json.dumps({'status': 'FAIL'}))
# can be done in context manager
alice.goto('/tests/')
alice.route('**/status', handler)
alice.click('tbody tr >> nth=0 >> .passBtn')
alice.unroute('**/status', handler)
alice.reload()
assert alice.text_content('.testRow_1 .ttStatus') == 'FAIL'
def test_abort(alice):
def handler(route: Route, request: Request):
route.abort()
# can be done in context manager
alice.goto('/tests/')
alice.click('.testRow_1 .passBtn')
alice.route('**/status', handler)
alice.click('tbody tr >> nth=0 >> .failBtn')
alice.unroute('**/status', handler)
alice.reload()
assert alice.text_content('.testRow_1 .ttStatus') == 'PASS'