Skip to content

Commit 181c2fd

Browse files
authored
Add Enable debug mode (#31)
* Add enable and disable debug mode * Add disable debug mode * Add exclude tag when run test
1 parent 2256cd8 commit 181c2fd

File tree

6 files changed

+61
-7
lines changed

6 files changed

+61
-7
lines changed

.github/workflows/pythonpackage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ jobs:
3333
python setup.py install
3434
pip install -r demoapp/requirements.txt
3535
python demoapp/server.py &
36-
robot -v HEADLESS:True Examples
36+
robot -v HEADLESS:True -e Ignore Examples

Examples/quick-start.robot

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Example login form submit
2020
... Click Link partial link:logout AND
2121
... Wait For Response Url http://127.0.0.1:7272/
2222

23-
Control browser example
23+
Example Control browser
2424
${HEADLESS} Get variable value ${HEADLESS} ${False}
2525
&{options} = create dictionary headless=${HEADLESS}
2626
Open browser http://127.0.0.1:7272 options=${options}
@@ -30,6 +30,14 @@ Control browser example
3030
Reload page
3131
${header} = Get Text css:h1
3232
Should Be Equal Login Page ${header}
33+
34+
Example Debug mode
35+
[Tags] Ignore
36+
Enable Debug Mode
37+
Open browser http://127.0.0.1:7272
38+
Input text id:username_field demo
39+
Input text id:password_field mode
40+
3341

3442
*** Keywords ***
3543
Test Teardown

PuppeteerLibrary/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ class PuppeteerLibrary(DynamicCore):
8181
current_context_name = None
8282
current_page = None
8383

84+
debug_mode = False
85+
debug_mode_options = {
86+
'slowMo': 200,
87+
'devtools': False
88+
}
89+
8490
def __init__(self):
8591
try:
8692
self.loop = asyncio.get_event_loop()

PuppeteerLibrary/base/context.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ def __init__(self, ctx):
1515
print('Warning: Asyncio not supported')
1616
self.ctx = ctx
1717
self.ctx.timeout = 30
18+

PuppeteerLibrary/keywords/browsermanagement.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,29 @@ async def open_browser_async():
4141
if self.ctx.browser is None:
4242
default_args = []
4343
default_options = {
44+
'slowMo': 0,
4445
'headless': True,
46+
'devtools': False,
4547
'width': 1366,
4648
'height': 768
4749
}
48-
merged_options = None
49-
if options is None:
50-
merged_options = default_options
51-
else:
52-
merged_options = {**default_options, **options}
50+
51+
merged_options = default_options
52+
53+
if options is not None:
54+
merged_options = {**merged_options, **options}
55+
56+
if self.ctx.debug_mode is True:
57+
merged_options = {**merged_options, **self.ctx.debug_mode_options}
5358

5459
if 'win' not in sys.platform.lower():
5560
default_args = ['--no-sandbox', '--disable-setuid-sandbox']
5661

5762
self.info(('Open browser to ' + url + '\n' +
5863
str(merged_options)))
5964
self.ctx.browser = await launch(
65+
slowMo=merged_options['slowMo'],
66+
devtools=merged_options['devtools'],
6067
headless=merged_options['headless'],
6168
defaultViewport={
6269
'width': merged_options['width'],

PuppeteerLibrary/keywords/utility.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,35 @@ async def _run_async_keywords(self, iterable):
3232
return await asyncio.gather(*statements)
3333
except Exception as err:
3434
raise Exception(err)
35+
36+
@keyword
37+
def enable_debug_mode(self, slowMo=150, devtools=True):
38+
"""Enable debug mode.
39+
40+
The ``slowMo`` argument specifies delay for each test step.
41+
The ``devtools`` argument specifies enable devtools or not.
42+
43+
Example:
44+
45+
| Enable Debug Mode | | |
46+
| Open browser | http://127.0.0.1:7272 | |
47+
| Input text | id:username_field | demo |
48+
| Input text | id:password_field | mode |
49+
50+
"""
51+
self.ctx.debug_mode = True
52+
self.ctx.debug_mode_options['headless'] = False
53+
self.ctx.debug_mode_options['slowMo'] = slowMo
54+
self.ctx.debug_mode_options['devtools'] = devtools
55+
56+
@keyword
57+
def disable_debug_mode(self):
58+
"""Disable debug mode. This keyword will close all browser and reset debug mode to False.
59+
"""
60+
async def disable_debug_mode_async():
61+
await self.ctx.browser.close()
62+
63+
self.loop.run_until_complete(disable_debug_mode_async())
64+
self.ctx.debug_mode = False
65+
self.ctx.clear_browser()
66+

0 commit comments

Comments
 (0)