Skip to content

Commit eec585b

Browse files
authored
Hot fix open new playwright only if server has been stop (#120)
* Add fix library context * Force set current context when call open browser Co-authored-by: atthaboon.s <atthaboon.s@qahive.com>
1 parent 0f5c86d commit eec585b

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

PuppeteerLibrary/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ async def set_current_library_context(self, context_name) -> iLibraryContext:
158158

159159
@not_keyword
160160
def get_library_context_by_name(self, alias: str) -> iLibraryContext:
161-
return self.library_contexts[alias]
161+
if alias in self.library_contexts:
162+
return self.library_contexts[alias]
163+
return None
162164

163165
@not_keyword
164166
def get_all_library_context(self) -> List[iLibraryContext]:

PuppeteerLibrary/keywords/browsermanagement.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ def open_browser(self, url, browser="chrome", alias=None, options={}):
4545
options = {}
4646

4747
self.info(url)
48-
library_context = self.ctx.create_library_context(alias, browser)
48+
library_context = self.ctx.get_library_context_by_name(alias)
49+
if library_context is None:
50+
library_context = self.ctx.create_library_context(alias, browser)
51+
self.loop.run_until_complete(self.ctx.set_current_library_context(alias))
4952
self.loop.run_until_complete(library_context.start_server(options))
5053
self.loop.run_until_complete(library_context.create_new_page(options))
5154
self.loop.run_until_complete(self.get_async_keyword_group().go_to(url))
@@ -75,7 +78,7 @@ def close_all_browser(self):
7578

7679
@keyword
7780
def close_puppeteer(self):
78-
library_contexts_dict = self.ctx.get_all_library_context_dict()
81+
library_contexts_dict = self.ctx.get_all_library_context_dict()
7982
for key in list(library_contexts_dict.keys()):
8083
self.loop.run_until_complete(library_contexts_dict[key].stop_server())
8184
self.ctx.remove_library_context(key)

PuppeteerLibrary/playwright/playwright_context.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ async def start_server(self, options: dict={}):
5959
elif key in ['slowMo']:
6060
merged_options[key] = str2int(merged_options[key])
6161

62-
self.playwright = await async_playwright().start()
62+
# Only start new Playwright server. If server didn't start before
63+
if self.playwright is None:
64+
self.playwright = await async_playwright().start()
65+
6366
if self.browser_type == "pwchrome":
6467
self.browser = await self.playwright.chromium.launch(
6568
headless=merged_options['headless'])

0 commit comments

Comments
 (0)