expect
BaseRequestExpectation
Base class for handling request and response expectations. This class provides a context manager to wait for specific network requests and responses based on a URL pattern. It sets up handlers for request and response events and provides properties to access the request, response, and response body.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tab
|
Connection
|
The Tab instance to monitor. |
required |
url_pattern
|
Union[str, Pattern[str]]
|
The URL pattern to match requests and responses. |
required |
Source code in zendriver/core/expect.py
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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
loading_finished_future: asyncio.Future[cdp.network.LoadingFinished] = asyncio.Future()
instance-attribute
request: cdp.network.Request
async
property
Get the matched request.
Returns:
| Type | Description |
|---|---|
cdp.network.Request
|
The matched request. |
request_future: asyncio.Future[cdp.network.RequestWillBeSent] = asyncio.Future()
instance-attribute
request_id: Union[cdp.network.RequestId, None] = None
instance-attribute
response: cdp.network.Response
async
property
Get the matched response.
Returns:
| Type | Description |
|---|---|
cdp.network.Response
|
The matched response. |
response_body: tuple[str, bool]
async
property
Get the body of the matched response.
Returns:
| Type | Description |
|---|---|
str
|
The response body. |
response_future: asyncio.Future[cdp.network.ResponseReceived] = asyncio.Future()
instance-attribute
tab = tab
instance-attribute
url_pattern = url_pattern
instance-attribute
__aenter__()
async
__aexit__(*args)
async
__init__(tab, url_pattern)
Source code in zendriver/core/expect.py
reset()
async
Resets the internal state, allowing the expectation to be reused.
Source code in zendriver/core/expect.py
DownloadExpectation
Source code in zendriver/core/expect.py
default_behavior = self.tab._download_behavior[0] if self.tab._download_behavior else 'default'
instance-attribute
download_path = self.tab._download_behavior[1] if self.tab._download_behavior and len(self.tab._download_behavior) > 1 else None
instance-attribute
future: asyncio.Future[cdp.browser.DownloadWillBegin] = asyncio.Future()
instance-attribute
tab = tab
instance-attribute
value: cdp.browser.DownloadWillBegin
async
property
__aenter__()
async
Enter the context manager, adding download handler, set download behavior to deny.
Source code in zendriver/core/expect.py
__aexit__(*args)
async
Exit the context manager, removing handler, set download behavior to default.
Source code in zendriver/core/expect.py
__init__(tab)
Source code in zendriver/core/expect.py
RequestExpectation
Bases: BaseRequestExpectation
Class for handling request expectations.
This class extends BaseRequestExpectation and provides a property to access the matched request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tab
|
Connection
|
The Tab instance to monitor. |
required |
url_pattern
|
Union[str, Pattern[str]]
|
The URL pattern to match requests. |
required |
Source code in zendriver/core/expect.py
value: cdp.network.RequestWillBeSent
async
property
Get the matched request event.
Returns:
| Type | Description |
|---|---|
cdp.network.RequestWillBeSent
|
The matched request event. |
ResponseExpectation
Bases: BaseRequestExpectation
Class for handling response expectations.
This class extends BaseRequestExpectation and provides a property to access the matched response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tab
|
Connection
|
The Tab instance to monitor. |
required |
url_pattern
|
Union[str, Pattern[str]]
|
The URL pattern to match responses. |
required |
Source code in zendriver/core/expect.py
value: cdp.network.ResponseReceived
async
property
Get the matched response event.
Returns:
| Type | Description |
|---|---|
cdp.network.ResponseReceived
|
The matched response event. |