Skip to content

Commit 6747285

Browse files
authored
Switching Browser, Context and Pages brings page to front (MarketSquare#2993)
Signed-off-by: René <[email protected]>
1 parent 941f6f0 commit 6747285

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

Browser/keywords/webapp_state.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def local_storage_get_item(
5353
| ``assertion_operator`` | Assertion operator to use. See `Assertions` for more information. |
5454
| ``assertion_expected`` | Expected value to compare with. |
5555
| ``message`` | Custom error message to use. |
56-
| ``frame_selector`` | If this selector points to an element inside an iframe, the LocalStorage of that frame is used. Example: `iframe[name="test"] >>> body` |
56+
| ``frame_selector`` | If this selector points to an element inside an iframe, the LocalStorage of that frame is used. Example: ``iframe[name="test"] >>> body`` |
5757
5858
5959
See `Assertions` for further details for the assertion arguments. Defaults to None.
@@ -85,7 +85,7 @@ def local_storage_set_item(
8585
| =Arguments= | =Description= |
8686
| ``key`` | The name of the key under which it should be saved. |
8787
| ``value`` | The value which shall be saved as a string. |
88-
| ``frame_selector`` | If this selector points to an element inside an iframe, the LocalStorage of that frame is used. Example: `iframe[name="test"] >>> body` |
88+
| ``frame_selector`` | If this selector points to an element inside an iframe, the LocalStorage of that frame is used. Example: ``iframe[name="test"] >>> body`` |
8989
9090
9191
Example:
@@ -104,7 +104,7 @@ def local_storage_remove_item(self, key: str, frame_selector: Optional[str] = No
104104
105105
| =Arguments= | =Description= |
106106
| ``key`` | The name of the item which shall be deleted. |
107-
| ``frame_selector`` | If this selector points to an element inside an iframe, the LocalStorage of that frame is used. Example: `iframe[name="test"] >>> body` |
107+
| ``frame_selector`` | If this selector points to an element inside an iframe, the LocalStorage of that frame is used. Example: ``iframe[name="test"] >>> body`` |
108108
109109
Example:
110110
| `Local Storage Set Item` Foo bar
@@ -124,7 +124,7 @@ def local_storage_clear(self, frame_selector: Optional[str] = None):
124124
"""Remove all saved data from the local storage.
125125
126126
| =Arguments= | =Description= |
127-
| ``frame_selector`` | If this selector points to an element inside an iframe, the LocalStorage of that frame is used. Example: `iframe[name="test"] >>> body` |
127+
| ``frame_selector`` | If this selector points to an element inside an iframe, the LocalStorage of that frame is used. Example: ``iframe[name="test"] >>> body`` |
128128
129129
Example:
130130
| `Local Storage Set Item` Foo bar
@@ -156,7 +156,7 @@ def session_storage_get_item(
156156
| ``assertion_operator`` | Assertion operator to use. See `Assertions` for more information. |
157157
| ``assertion_expected`` | Expected value to compare with. |
158158
| ``message`` | Custom error message to use. |
159-
| ``frame_selector`` | If this selector points to an element inside an iframe, the SessionStorage of that frame is used. Example: `iframe[name="test"] >>> body` |
159+
| ``frame_selector`` | If this selector points to an element inside an iframe, the SessionStorage of that frame is used. Example: ``iframe[name="test"] >>> body`` |
160160
161161
Example:
162162
| `SessionStorage Set Item` key2 value2
@@ -188,7 +188,7 @@ def session_storage_set_item(
188188
| =Arguments= | =Description= |
189189
| ``key`` | The name of the key under which it should be saved. |
190190
| ``value`` | The value which shall be saved as a string. |
191-
| ``frame_selector`` | If this selector points to an element inside an iframe, the SessionStorage of that frame is used. Example: `iframe[name="test"] >>> body` |
191+
| ``frame_selector`` | If this selector points to an element inside an iframe, the SessionStorage of that frame is used. Example: ``iframe[name="test"] >>> body`` |
192192
193193
Example:
194194
| `SessionStorage Set Item` key2 value2
@@ -209,7 +209,7 @@ def session_storage_remove_item(
209209
210210
| =Arguments= | =Description= |
211211
| ``key`` | The name of the item which shall be deleted. |
212-
| ``frame_selector`` | If this selector points to an element inside an iframe, the SessionStorage of that frame is used. Example: `iframe[name="test"] >>> body` |
212+
| ``frame_selector`` | If this selector points to an element inside an iframe, the SessionStorage of that frame is used. Example: ``iframe[name="test"] >>> body`` |
213213
214214
Example:
215215
| `SessionStorage Set Item` mykey2 myvalue2
@@ -228,7 +228,7 @@ def session_storage_clear(self, frame_selector: Optional[str] = None):
228228
"""Remove all saved data from the session storage.
229229
230230
| =Arguments= | =Description= |
231-
| ``frame_selector`` | If this selector points to an element inside an iframe, the SessionStorage of that frame is used. Example: `iframe[name="test"] >>> body` |
231+
| ``frame_selector`` | If this selector points to an element inside an iframe, the SessionStorage of that frame is used. Example: ``iframe[name="test"] >>> body`` |
232232
233233
Example:
234234
| `SessionStorage Set Item` mykey3 myvalue3

node/playwright-wrapper/playwright-state.ts

+14-9
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,7 @@ export async function switchPage(
726726
const id = request.getId();
727727
if (id === 'CURRENT') {
728728
const previous = browserState.page?.id || 'NO PAGE OPEN';
729+
browserState.page?.p.bringToFront();
729730
return stringResponse(previous, 'Returned active page id');
730731
} else if (id === 'NEW') {
731732
const previous = browserState.page?.id || 'NO PAGE OPEN';
@@ -769,27 +770,31 @@ export async function switchContext(request: Request.Index, browserState: Browse
769770
if (id === 'CURRENT') {
770771
if (!previous) {
771772
return stringResponse('NO CONTEXT OPEN', 'Returned info that no contexts are open');
772-
} else {
773-
return stringResponse(previous, 'Returned active context id');
774773
}
774+
} else {
775+
await _switchContext(id, browserState);
775776
}
776-
777-
await _switchContext(id, browserState);
778777
const page = browserState.page;
779778
if (page !== undefined) {
780779
await _switchPage(page.id, browserState);
781780
}
782-
return stringResponse(previous, 'Successfully changed active context');
781+
return stringResponse(
782+
previous,
783+
id === 'CURRENT' ? 'Returned active context id' : 'Successfully changed active context',
784+
);
783785
}
784786

785787
export async function switchBrowser(request: Request.Index, openBrowsers: PlaywrightState): Promise<Response.String> {
786788
const id = request.getIndex();
787789
const previous = openBrowsers.activeBrowser;
788-
if (id === 'CURRENT') {
789-
return stringResponse(previous?.id || 'NO BROWSER OPEN', 'Active context id');
790+
if (id !== 'CURRENT') {
791+
openBrowsers.switchTo(id);
790792
}
791-
openBrowsers.switchTo(id);
792-
return stringResponse(previous?.id || '', 'Successfully changed active browser');
793+
openBrowsers.getActivePage()?.bringToFront();
794+
return stringResponse(
795+
previous?.id || 'NO BROWSER OPEN',
796+
id === 'CURRENT' ? 'Returned active browser id' : 'Successfully changed active browser',
797+
);
793798
}
794799

795800
export async function getBrowserCatalog(openBrowsers: PlaywrightState): Promise<Response.Json> {

0 commit comments

Comments
 (0)