Skip to content

Commit 553f13a

Browse files
authored
Revise solution for wait_for_new_window_open_async (#39)
1 parent abfebc8 commit 553f13a

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

Examples/browser-demo.robot

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ Example switch window and check window title
1111
Maximize Browser Window
1212
${title} = Get title
1313
${location} = Get location
14-
${window count} = Get Window Count
1514
Run Async Keywords
16-
... Wait for new window open ${window count} 5s AND
15+
... Wait for new window open 5s AND
1716
... Click Element id=readdocs
1817
Switch Window NEW
1918
${Title} = Get Title

Examples/timeout-demo.robot

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ ${HOME_PAGE_URL} http://127.0.0.1:7272
1111
*** Test Cases ***
1212
Set default timeout
1313
Set Timeout 3s
14-
${window count} = Get Window Count
15-
Run Keyword And Expect Error No new page has been open.* Wait for new window open ${window count}
14+
Run Keyword And Expect Error No new page has been open.* Wait for new window open
1615

1716
Timeout wait for new window open
1817
${window count} = Get Window Count
1918
Run Async Keywords
20-
... Wait for new window open ${window count} 5s AND
19+
... Wait for new window open 5s AND
2120
... Click Element id:readdocs
2221

2322
*** Keywords ***

PuppeteerLibrary/keywords/browsermanagement.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def get_window_count(self):
164164
return self.loop.run_until_complete(self.async_func.get_window_count_async())
165165

166166
@keyword
167-
def wait_for_new_window_open(self, current_page_count=1, timeout=None):
167+
def wait_for_new_window_open(self, timeout=None):
168168
"""
169169
Waits until new page or tab opens.
170170
@@ -173,7 +173,7 @@ def wait_for_new_window_open(self, current_page_count=1, timeout=None):
173173
| Run Async Keywords | Click Element | id:view_conditions | AND |
174174
| ... | `Wait For New Window Open` | | |
175175
"""
176-
self.loop.run_until_complete(self.async_func.wait_for_new_window_open_async(current_page_count, timeout))
176+
self.loop.run_until_complete(self.async_func.wait_for_new_window_open_async(timeout))
177177

178178
@keyword
179179
def switch_window(self, locator='MAIN'):

PuppeteerLibrary/keywords/browsermanagement_async.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@ class BrowserManagementKeywordsAsync(LibraryComponent):
1010
async def get_window_count_async(self):
1111
pages = await self.ctx.get_browser().pages()
1212
for page in pages:
13-
await page.title() # workaround for force pages re-cache
13+
# Workaround: for force pages re-cache
14+
await page.title()
1415
return len(await self.ctx.get_browser().pages())
1516

1617
@keyword
17-
async def wait_for_new_window_open_async(self, current_page_count=1, timeout=None):
18+
async def wait_for_new_window_open_async(self, timeout=None):
1819
page_len = 0
19-
pre_page_len = int(current_page_count)
20+
# Workaround:
21+
# We get length without force reset. For ensure that when we count page length.
22+
# Page length still not update / same as before open new window
23+
pre_page_len = len(await self.ctx.get_browser().pages())
2024
timeout = self.timestr_to_secs_for_default_timeout(timeout)
2125
timer = 0
2226
while timer < timeout:

0 commit comments

Comments
 (0)