Skip to content

Commit ba799e5

Browse files
authored
Add support set view port keywords (#112)
* Add support set view port keywords * Fix unstable test Co-authored-by: atthaboon.s <[email protected]>
1 parent 34ee135 commit ba799e5

File tree

6 files changed

+42
-2
lines changed

6 files changed

+42
-2
lines changed

Examples/browser-management/open-close-browser.robot

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,9 @@ Close browser before task finished should not throw error message
8787
Click Element id=open-new-tab
8888
Click Element id=open-new-tab
8989

90+
Set view port
91+
${BROWSER} = Get variable value ${BROWSER} ${DEFAULT_BROWSER}
92+
${HEADLESS} = Get variable value ${HEADLESS} ${False}
93+
&{options} = create dictionary headless=${HEADLESS}
94+
Open browser http://127.0.0.1:7272/basic-html-elements.html browser=${BROWSER} options=${options}
95+
Set View Port Size 200 200

Examples/browser-management/webkit-newpage-limitation.robot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Webkit new page cause exception require ignore waiting
1111
${HEADLESS} = Get variable value ${HEADLESS} ${False}
1212
&{options} = create dictionary headless=${HEADLESS}
1313
Open browser https://www.w3schools.com/html/html_forms.asp browser=${BROWSER} options=${options}
14-
Wait Until Element Is Visible css=a.w3schools-logo
14+
Wait Until Element Is Visible id=fname
1515
Input Text id=fname 123
1616
Input Text id=lname 123
1717
Click Element xpath=(//input[@value="Submit"])[1] ${True}

PuppeteerLibrary/ikeywords/ibrowsermanagement_async.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ async def wait_for_new_window_open(self, timeout=None):
2828
async def switch_window(self, locator='MAIN'):
2929
pass
3030

31+
##############################
32+
# Page
33+
##############################
34+
@abstractmethod
35+
async def set_view_port_size(self, width, height):
36+
pass
37+
3138
##############################
3239
# iFrame
3340
##############################

PuppeteerLibrary/keywords/browsermanagement.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,13 @@ def enable_emulate_mode(self, emulate_name):
159159
"""
160160
return self.loop.run_until_complete(self.get_async_keyword_group().enable_emulate_mode_async(emulate_name))
161161

162+
##############################
163+
# Page
164+
##############################
165+
@keyword
166+
def set_view_port_size(self, width, height):
167+
return self.loop.run_until_complete(self.get_async_keyword_group().set_view_port_size(width, height))
168+
162169
##############################
163170
# iFrame
164171
##############################

PuppeteerLibrary/playwright/async_keywords/playwright_browsermanagement.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from PuppeteerLibrary.utils.device_descriptors import DEVICE_DESCRIPTORS
55
from PuppeteerLibrary.ikeywords.ibrowsermanagement_async import iBrowserManagementAsync
66
from PuppeteerLibrary.utils.coverter import str2str
7+
from PuppeteerLibrary.utils.coverter import str2int
78

89

910
class PlaywrightBrowserManagement(iBrowserManagementAsync):
@@ -78,6 +79,15 @@ async def switch_window(self, locator='MAIN'):
7879
raise Exception('Sorry Switch window support only NEW, MAIN, title and url')
7980
raise Exception('Can\'t find specify page locator.')
8081

82+
##############################
83+
# Page
84+
##############################
85+
async def set_view_port_size(self, width, height):
86+
await self.library_ctx.get_current_page().get_page().set_viewport_size({
87+
"width": str2int(width),
88+
"height": str2int(height)
89+
})
90+
8191
##############################
8292
# iFrame
8393
##############################

PuppeteerLibrary/puppeteer/async_keywords/puppeteer_browsermanagement.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from PuppeteerLibrary.utils.coverter import str2str
1+
from PuppeteerLibrary.utils.coverter import str2str
2+
from PuppeteerLibrary.utils.coverter import str2int
23
import asyncio
34
import re
45
import time
@@ -87,6 +88,15 @@ async def switch_window(self, locator='MAIN'):
8788
raise Exception('Sorry Switch window support only NEW, MAIN, title and url')
8889
raise Exception('Can\'t find specify page locator.')
8990

91+
##############################
92+
# Page
93+
##############################
94+
async def set_view_port_size(self, width, height):
95+
await self.library_ctx.get_current_page().get_page().setViewport({
96+
"width": str2int(width),
97+
"height": str2int(height)
98+
})
99+
90100
##############################
91101
# iFrame
92102
##############################

0 commit comments

Comments
 (0)