Skip to content

Commit d152e35

Browse files
authored
Merge pull request #109 from MarketSquare/feature/switch-browser-context-page
Feature/switch browser context page
2 parents 2a014e4 + ec9c2f5 commit d152e35

22 files changed

+242
-130
lines changed

Browser/keywords/browser_state.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def close_browser(self):
5959
self.info(response.log)
6060

6161
@keyword
62-
def new_browser(
62+
def create_browser(
6363
self, browser_type=SupportedBrowsers.chromium, **kwargs,
6464
):
6565
"""Create a new playwright Browser with specified options. A Browser is the Playwright object that controls a single Browser process.
@@ -69,13 +69,13 @@ def new_browser(
6969

7070
with self.playwright.grpc_channel() as stub:
7171
options = json.dumps(kwargs)
72-
response = stub.NewBrowser(
73-
Request().NewBrowser(browser=browser_type.name, rawOptions=options)
72+
response = stub.CreateBrowser(
73+
Request().Browser(browser=browser_type.name, rawOptions=options)
7474
)
7575
self.info(response.log)
7676

7777
@keyword
78-
def new_context(
78+
def create_context(
7979
self, **kwargs,
8080
):
8181
"""Create a new BrowserContext with specified options. A BrowserContext is the Playwright object that controls a single browser profile.
@@ -88,33 +88,51 @@ def new_context(
8888
with self.playwright.grpc_channel() as stub:
8989
options = json.dumps(kwargs)
9090
self.info(options)
91-
response = stub.NewContext(Request().NewContext(rawOptions=options))
91+
response = stub.CreateContext(Request().Context(rawOptions=options))
9292
self.info(response.log)
9393

9494
@keyword
95-
def new_page(self, url: Optional[str] = None):
95+
def create_page(self, url: Optional[str] = None):
9696
"""Open a new Page. A Page is the Playwright equivalent to a tab.
9797
9898
If ``url`` parameter is specified will open the new page to the specified URL.
9999
"""
100100

101101
with self.playwright.grpc_channel() as stub:
102-
response = stub.NewPage(Request().Url(url=url))
102+
response = stub.CreatePage(Request().Url(url=url))
103103
self.info(response.log)
104104

105105
@keyword
106-
def switch_active_page(self, index: int):
106+
def switch_page(self, index: int):
107107
"""Switches the active browser page to another open page by ``index``.
108108
109109
Newly opened pages get appended to the end of the list
110110
"""
111111
with self.playwright.grpc_channel() as stub:
112-
response = stub.SwitchActivePage(Request().Index(index=index))
112+
response = stub.SwitchPage(Request().Index(index=index))
113113
self.info(response.log)
114114

115115
@keyword
116116
def auto_activate_pages(self):
117-
"""Toggles automatically changing active page to latest opened page """
117+
"""Toggles automatically changing active page to latest opened page."""
118118
with self.playwright.grpc_channel() as stub:
119119
response = stub.AutoActivatePages(Request().Empty())
120120
self.info(response.log)
121+
122+
@keyword
123+
def switch_browser(self, index: int):
124+
""" UNSTABLE AND NOT USE-READY
125+
126+
Switches the currently active Browser to another open Browser.
127+
"""
128+
with self.playwright.grpc_channel() as stub:
129+
response = stub.SwitchBrowser(Request().Index(index=index))
130+
self.info(response.log)
131+
132+
@keyword
133+
def switch_context(self, index: int):
134+
""" Switches the active BrowserContext to another open context.
135+
"""
136+
with self.playwright.grpc_channel() as stub:
137+
response = stub.SwitchContext(Request().Index(index=index))
138+
self.info(response.log)

atest/test/01_Browser_Management/goto.robot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ No Open Browser Throws
1010
Run KeyWord and Expect Error *details = "Tried to do playwright action 'goto', but no open page."* GoTo "about:blank"
1111

1212
Open GoTo GoBack GoForward
13-
[Setup] New Page ${LOGIN URL}
13+
[Setup] Create Page ${LOGIN URL}
1414
Go To ${WELCOME URL}
1515
Get Url == ${WELCOME URL}
1616
Go To ${ERROR URL}
Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,64 @@
11
*** Settings ***
22
Resource imports.resource
3+
Suite Setup No Operation
4+
Test Setup No Operation
35
Test Teardown Close Browser
46

57
*** Keywords ***
68
Open Browser and assert Login Page
79
[Arguments] ${local_browser}
8-
New Browser browser=${local_browser} headless=${HEADLESS}
9-
New Page url=${LOGIN URL}
10+
Open Browser To Login Page
1011
Get Text h1 == Login Page
1112

13+
Create Page Form
14+
Create Page ${FORM URL}
15+
Get Title == prefilled_email_form.html
16+
17+
Create Page Login
18+
Create Page ${LOGIN URL}
19+
Get Title matches (?i)login
20+
1221
*** Test Cases ***
1322
Open Firefox
1423
Open Browser and assert Login Page firefox
1524

1625
Open Chrome
1726
Open Browser and assert Login Page chromium
1827

19-
New Browser does not open a page
20-
New Browser
28+
Create Browser does not open a page
29+
Create Browser
2130
Run Keyword And Expect Error *"Tried to do playwright action 'goto', but no open page."* Go To ${LOGIN URL}
2231

23-
New Browser does not create a context
32+
Create Browser does not create a context
33+
Create Browser
2434
# Use Switch context to test that no context exists here
25-
Pass Execution Not Implemented yet
26-
[Teardown] Pass Execution Not Implemented yet
27-
Switch Context
35+
Run Keyword And Expect Error *No context for index 0.* Switch Context 0
2836

29-
New Context does not open a page
30-
New Context
37+
Create Context does not open a page
38+
Create Context
3139
Run Keyword And Expect Error *"Tried to do playwright action 'goto', but no open page."* Go To ${LOGIN URL}
3240

3341
Switch Browser
34-
Pass Execution Not Implemented yet
35-
[Teardown] Pass Execution Not Implemented yet
36-
New Browser chromium
37-
New Browser firefox
38-
Switch Browser
42+
Create Browser chromium
43+
Pass Execution Switch Browser doesn't work yet
44+
Create Page Login
45+
Create Browser firefox
46+
Create Page Form
47+
Switch Browser 0
48+
Get Title matches (?i)login
3949

4050
Switch Context
41-
Pass Execution Not Implemented yet
42-
[Teardown] Pass Execution Not Implemented yet
43-
New Context
44-
New Context
45-
Switch Context
51+
Create Context
52+
Create Page ${LOGIN URL}
53+
Get Title matches (?i)login
54+
Create Context
55+
Create Page ${FORM URL}
56+
Get Title == prefilled_email_form.html
57+
Switch Context 0
58+
Get Title matches (?i)login
4659

47-
New Page can create context and browser
48-
New Page ${LOGIN URL}
60+
Create Page can create context and browser
61+
Create Page ${LOGIN URL}
4962
Get Text h1 == Login Page
5063

5164
Focus Next Page on popup
@@ -56,10 +69,10 @@ Focus Next Page on popup
5669
Sleep 1s
5770
Wait For Elements State "Popped Up!"
5871

59-
Switch Active Page after popup
72+
Switch Page after popup
6073
Open Browser and assert Login Page chromium
6174
Click button#pops_up
62-
Switch Active Page 1
75+
Switch Page 1
6376
Wait For Elements State "Popped Up!"
64-
Switch Active Page 0
77+
Switch Page 0
6578
Wait For Elements State button#pops_up
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
*** Settings ***
22
Resource imports.resource
3-
Suite Setup Run Keywords New Browser browser=${BROWSER} headless=${HEADLESS} AND New Page
3+
Suite Setup Open Browser To no page
44
Suite Teardown Close Browser

atest/test/02_Content_Keywords/basic-getters.robot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
*** Settings ***
22
Resource imports.resource
3-
Suite Setup Go To ${LOGIN URL}
3+
Test Setup Create Page ${LOGIN URL}
44

55
*** Variables ***
66
${UserNameLabel}= label[for="username_field"]

atest/test/02_Content_Keywords/checkbox.robot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
*** Settings ***
22
Resource imports.resource
3-
Suite Setup New Page ${FORM_URL}
3+
Test Setup Create Page ${FORM_URL}
44

55
*** Test Cases ***
66
Get Checkbox State Checked

atest/test/02_Content_Keywords/click.robot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
*** Settings ***
22
Resource imports.resource
3-
Test Setup New Page ${LOGIN URL}
3+
Test Setup Create Page ${LOGIN URL}
44

55
*** Test Cases ***
66
Click Button

atest/test/02_Content_Keywords/invalid_assertions.robot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
*** Settings ***
22
Resource imports.resource
3-
Suite Setup New Page ${LOGIN URL}
3+
Test Setup Create Page ${LOGIN URL}
44

55
*** Test Cases ***
66
Invalids will raise error directly from Robot Framework

atest/test/02_Content_Keywords/keypress.robot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
*** Settings ***
22
Resource imports.resource
3-
Suite Setup New Page ${FORM_URL}
3+
Test Setup Create Page ${FORM URL}
44

55
*** Test Cases ***
66
Press Keys Generate Characters

atest/test/02_Content_Keywords/screenshot.robot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
*** Settings ***
22
Resource imports.resource
3-
Suite Setup New Page ${LOGIN URL}
3+
Test Setup Create Page ${LOGIN URL}
44

55
*** Variables ***
66
${failure_screnshot} ${OUTPUT_DIR}${/}Test_screenshotting_failing_test_FAILURE_SCREENSHOT.png

atest/test/02_Content_Keywords/select-lists.robot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
*** Settings ***
22
Resource imports.resource
3-
Suite Setup New Page ${FORM_URL}
3+
Test Setup Create Page ${FORM URL}
44
Test Timeout 10s
55

66
*** Test Cases ***

atest/test/02_Content_Keywords/text_keywords.robot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
*** Settings ***
22
Resource imports.resource
3-
Suite Setup Go To ${LOGIN URL}
3+
Test Setup Create Page ${LOGIN URL}
44

55
*** Test Cases ***
66
Type Text with Clearing

atest/test/02_Content_Keywords/title_should_be.robot

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ Resource imports.resource
33

44
*** Test Cases ***
55
test server title
6-
Go To ${LOGIN URL}/
6+
Create Page ${LOGIN URL}/
77
Get Title == Login Page
88

99
about:blank title
10-
Go To about:blank
10+
Create Page about:blank
1111
Get Title == ${EMPTY}

atest/test/03_Waiting/__init__.robot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
*** Settings ***
22
Resource imports.resource
3-
Suite Setup Run Keywords New Browser browser=${BROWSER} headless=${HEADLESS} AND New Page
3+
Suite Setup Open Browser To No Page
44
Suite Teardown Close Browser

atest/test/03_Waiting/wait_for_element_state.robot

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*** Settings ***
22
Resource imports.resource
3-
Test Setup New Page ${LOGIN URL}
3+
Suite Setup Open Browser To No Page
4+
Test Setup Create Page ${LOGIN URL}
45

56
*** Test Cases ***
67
Wait For Elements State to hide

atest/test/keywords.resource

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,20 @@ Resource variables.resource
77
${PLAYWRIGHT TIMEOUT} 1 second
88

99
*** Keywords ***
10+
Open Browser To No Page
11+
Create Browser ${BROWSER} headless=${HEADLESS}
12+
1013
Open Browser To Frame Page
11-
New Browser ${BROWSER} headless=${HEADLESS}
12-
New Page ${FRAMES URL}
14+
Create Browser ${BROWSER} headless=${HEADLESS}
15+
Create Page ${FRAMES URL}
1316

17+
Open Browser To Form Page
18+
Create Browser ${BROWSER} headless=${HEADLESS}
19+
Create Page ${FORM_URL}
1420

1521
Open Browser To Login Page
16-
New Browser ${BROWSER} headless=${HEADLESS}
17-
New Page ${LOGIN URL}
22+
Create Browser ${BROWSER} headless=${HEADLESS}
23+
Create Page ${LOGIN URL}
1824
# Set Selenium Speed ${DELAY}
1925
Login Page Should Be Open
2026

atest/test/on_page_js.robot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
*** Settings ***
22
Library Browser
33
Resource keywords.resource
4-
Test Setup New Page ${LOGIN URL}
4+
Test Setup Create Page ${LOGIN URL}
55
Test Teardown Close Browser
66

77
*** Test Cases ***

docs/Browser.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

node/.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ module.exports = {
1414
// Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
1515
// e.g. "@typescript-eslint/explicit-function-return-type": "off",
1616
}
17-
};
17+
};

0 commit comments

Comments
 (0)