@@ -11,13 +11,17 @@ class PlaywrightWaiting(iWaitingAsync):
1111 def __init__ (self , library_ctx ):
1212 super ().__init__ (library_ctx )
1313
14+ async def wait_for_network_idle (self , timeout = None ):
15+ await self .library_ctx .get_current_page ().get_page ().wait_for_load_state ('networkidle' , timeout = self .timestr_to_secs_for_default_timeout (timeout ) * 1000 )
16+
1417 async def wait_for_request_url (self , url , method = 'GET' , body = None , timeout = None ):
1518 url = str2str (url )
1619 method = str2str (method )
1720 req = await self .library_ctx .get_current_page ().get_page ().wait_for_event (
18- "request" ,
19- predicate = lambda request : re .search (url , request .url ) is not None and request .method == method ,
20- timeout = self .timestr_to_secs_for_default_timeout (timeout ) * 1000
21+ "request" ,
22+ predicate = lambda request : re .search (
23+ url , request .url ) is not None and request .method == method ,
24+ timeout = self .timestr_to_secs_for_default_timeout (timeout ) * 1000
2125 )
2226 try :
2327 pos_data = (await req .postData ())
@@ -30,7 +34,8 @@ async def wait_for_request_url(self, url, method='GET', body=None, timeout=None)
3034 log_str + '\n ' + pos_data
3135 self .info (log_str )
3236 else :
33- raise Exception ('Can\' t match request body with ' + body + ' \n ' + pos_data )
37+ raise Exception ('Can\' t match request body with ' +
38+ body + ' \n ' + pos_data )
3439
3540 return DotDict ({
3641 'url' : req .url ,
@@ -42,21 +47,23 @@ async def wait_for_response_url(self, url, status=200, body=None, timeout=None):
4247 url = str2str (url )
4348 status = str2int (status )
4449 res = await self .library_ctx .get_current_page ().get_page ().wait_for_event (
45- "response" ,
46- predicate = lambda response : re .search (url , response .url ) is not None and response .status == status ,
47- timeout = self .timestr_to_secs_for_default_timeout (timeout ) * 1000
50+ "response" ,
51+ predicate = lambda response : re .search (
52+ url , response .url ) is not None and response .status == status ,
53+ timeout = self .timestr_to_secs_for_default_timeout (timeout ) * 1000
4854 )
4955 try :
5056 res_text = (await res .text ())
5157 except :
5258 res_text = ''
53- if body is None or re .search (body , res_text .replace ('\n ' ,'' )):
59+ if body is None or re .search (body , res_text .replace ('\n ' , '' )):
5460 log_str = 'Wait for request url: ' + res .url
5561 if res_text != '' :
5662 log_str += '\n ' + res_text
5763 self .info (log_str )
5864 else :
59- raise Exception ('Can\' t match response body with ' + body + ' \n ' + res_text )
65+ raise Exception (
66+ 'Can\' t match response body with ' + body + ' \n ' + res_text )
6067 return DotDict ({
6168 'url' : res .url ,
6269 'status' : res .status ,
@@ -65,8 +72,8 @@ async def wait_for_response_url(self, url, status=200, body=None, timeout=None):
6572
6673 async def wait_for_navigation (self , timeout = None ):
6774 return await self .library_ctx .get_current_page ().get_page ().wait_for_event (
68- 'load' ,
69- predicate = None ,
75+ 'load' ,
76+ predicate = None ,
7077 timeout = self .timestr_to_secs_for_default_timeout (timeout ) * 1000 )
7178
7279 async def wait_until_page_contains_element (self , locator , timeout = None ):
@@ -95,15 +102,17 @@ async def wait_until_element_contains(self, locator, text, timeout=None):
95102
96103 async def wait_until_element_does_not_contains (self , locator , text , timeout = None ):
97104 text = str2str (text )
105+
98106 async def validate_element_contains_text ():
99- return (text not in (await (await ( await self .library_ctx .get_current_page ().
100- querySelector_with_selenium_locator (locator )).get_property ('textContent' )).json_value ()))
107+ return (text not in (await (await (await self .library_ctx .get_current_page ().
108+ querySelector_with_selenium_locator (locator )).get_property ('textContent' )).json_value ()))
101109 return await self ._wait_until_worker (
102110 validate_element_contains_text ,
103111 self .timestr_to_secs_for_default_timeout (timeout ))
104112
105113 async def wait_until_location_contains (self , expected , timeout = None ):
106114 expected = str2str (expected )
115+
107116 async def validate_url_contains_text ():
108117 return expected in self .library_ctx .get_current_page ().get_page ().url
109118 return await self ._wait_until_worker (
@@ -112,6 +121,7 @@ async def validate_url_contains_text():
112121
113122 async def wait_until_location_does_not_contains (self , expected , timeout = None ):
114123 expected = str2str (expected )
124+
115125 async def validate_url_not_contains_text ():
116126 return expected not in self .library_ctx .get_current_page ().get_page ().url
117127 return await self ._wait_until_worker (
@@ -129,7 +139,8 @@ async def validate_is_enabled():
129139 'Element ' + locator + ' was not enabled.' )
130140
131141 async def wait_until_element_finished_animating (self , locator , timeout = None ):
132- prev_rect_tmp = { 'value' : None }
142+ prev_rect_tmp = {'value' : None }
143+
133144 async def check_finished_animating ():
134145 await self .wait_until_element_is_visible (locator )
135146 element = await self .library_ctx .get_current_page ().querySelector_with_selenium_locator (locator )
@@ -151,7 +162,7 @@ async def check_finished_animating():
151162 async def _wait_for_selenium_selector (self , selenium_locator , timeout = None , visible = False , hidden = False ):
152163 timeout = self .timestr_to_secs_for_default_timeout (timeout )
153164 return await self .library_ctx .get_current_page ().waitForSelector_with_selenium_locator (selenium_locator , timeout , visible , hidden )
154-
165+
155166 async def _wait_until_worker (self , condition , timeout , error = None ):
156167 max_time = time .time () + timeout
157168 not_found = None
0 commit comments