Skip to content

Commit dd159d1

Browse files
xylixFinalrykku
andauthored
Fixed click with options bugs, improved tests(#280)
* updated cpm check for windows compatibility * Start adding support for context and browser parameters to close page * Added tests for click with options and add styles * Start moving to Close Specific _ * Corrected assertion in click with options * Move Close Specific in playwright-state.ts * Added missing tests to functions: Mouse Button, Focus, Keyboard Input Updated some incorrect tests. * Implement current / all support logic on python side * Add support for switching context / browser in Switch keywords * Clean up app.tsx function and variable names, change virtual_mouse.robot to not use hard coded cooardinates * Run robot linter * Improve Click With Options debug print, use correct protobuf call in python side * Add Not-Implemented tag to skip buggy tests for now * Undo shell=True change Co-authored-by: Finalrykku <[email protected]>
1 parent 6c93069 commit dd159d1

File tree

9 files changed

+139
-4
lines changed

9 files changed

+139
-4
lines changed

Browser/entry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def rfbrowser_init():
4444
print("Installing rfbrowser node dependencies at {}".format(installation_dir))
4545

4646
try:
47-
subprocess.run(["npm", "-v"], stdout=DEVNULL, check=True)
47+
subprocess.run(["npm", "-v"], stdout=DEVNULL, check=True, shell=False)
4848
except (CalledProcessError, FileNotFoundError, PermissionError) as exception:
4949
print(
5050
"Couldn't execute npm. Please ensure you have node.js and npm installed and in PATH."

Browser/keywords/interaction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def click_with_options(
200200
options["modifiers"] = [m.name for m in modifiers]
201201
options_json = json.dumps(options)
202202
logger.debug(f"Click Options are: {options_json}")
203-
response = stub.Click(
203+
response = stub.ClickWithOptions(
204204
Request().ElementSelectorWithOptions(
205205
selector=selector, options=options_json
206206
)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
*** Settings ***
2+
Resource imports.resource
3+
Test Setup New Page ${LOGIN_URL}
4+
5+
*** Test Cases ***
6+
Click Count
7+
Click With Options \#clickWithOptions click_count=10
8+
Get Text \#click_count == 10
9+
# When delay is set raises Could not find element with selector `#clickWithOptions` within timeout. error
10+
11+
Delay Click
12+
[Tags] Not-Implemented
13+
Click With Options \#clickWithOptions delay=1100
14+
Get Text \#mouse_delay_time validate int(value) > 1000
15+
16+
Second Delay click
17+
[Tags] Not-Implemented
18+
Click With Options \#clickWithOptions delay=1
19+
Get Text \#mouse_delay_time validate int(value) > 1000
20+
Fail
21+
22+
Left Right and Middle Click
23+
Click With Options \#clickWithOptions right
24+
Get Text \#mouse_button == right
25+
Click With Options \#clickWithOptions middle
26+
Get Text \#mouse_button == middle
27+
Click With Options \#clickWithOptions left
28+
Get Text \#mouse_button == left
29+
# Invalid usage since coordinates are usually return as centre.
30+
# When we go to x=1, y=1 we are at top left of element, not 1, 1 pixels off the centre
31+
32+
Click with Coordinates
33+
[Tags] Not-Implemented
34+
Click With Options \#clickWithOptions
35+
${x}= Get Text \#coordinatesX
36+
${y}= Get Text \#coordinatesY
37+
Click With Options \#clickWithOptions position_x=1 position_y=1
38+
Get Text \#coordinatesX validate int(${x}+1)==int(value)
39+
Get Text \#coordinatesY validate int(${y}+1)==int(value)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*** Settings ***
2+
Resource imports.resource
3+
Test Setup New Page ${LOGIN_URL}
4+
5+
*** Test Cases ***
6+
Add Style
7+
Add Style Tag \#username_field:focus {background-color: aqua;}
8+
Focus \#username_field
9+
Get Style \#username_field background-color == rgb(0, 255, 255)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
*** Settings ***
2+
Resource imports.resource
3+
Test Setup New Page ${LOGIN_URL}
4+
5+
*** Test Cases ***
6+
Keyboard Inputtype type
7+
Focus \#username_field
8+
Keyboard Input type 0123456789
9+
Get Textfield Value \#username_field == 0123456789
10+
Get Text \#countKeyPress == 10
11+
12+
Keyboard Inputtype insertText
13+
Focus \#username_field
14+
Keyboard Input insertText 0123456789
15+
Get Textfield Value \#username_field == 0123456789
16+
Get Text \#countKeyPress == 1
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
*** Settings ***
2+
Resource imports.resource
3+
Test Setup New Page ${LOGIN_URL}
4+
5+
*** Test Cases ***
6+
Add Style
7+
Add Style Tag \#goes_hidden{color:aqua}
8+
9+
Verify Style
10+
Add Style Tag \#goes_hidden{color:aqua}
11+
Get Style \#goes_hidden color == rgb(0, 255, 255)

atest/test/02_Content_Keywords/virtual_mouse.robot

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,22 @@ Move In Circle
1313
Mouse Move 0 400
1414
Mouse Move 400 0
1515
Mouse Move 0 0
16+
17+
Click Count
18+
${xy}= Get Boundingbox \#clickWithOptions x y
19+
Mouse Button click &{xy} clickCount=10
20+
Get Text \#click_count == 10
21+
22+
Delay click
23+
${xy}= Get Boundingbox \#clickWithOptions x y
24+
Mouse Button click &{xy} delay=1000
25+
Get Text \#mouse_delay_time validate int(value) > 1000
26+
27+
Left Right and Middle Click
28+
${xy}= Get Boundingbox \#clickWithOptions x y
29+
Mouse Button click &{xy} button=right
30+
Get Text \#mouse_button == right
31+
Mouse Button click &{xy} button=middle
32+
Get Text \#mouse_button == middle
33+
Mouse Button click &{xy} button=left
34+
Get Text \#mouse_button == left

node/dynamic-test-app/src/app.tsx

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { ChangeEvent, useRef, useState } from 'react';
1+
import React, { ChangeEvent, FocusEvent, useRef, useState } from 'react';
22

33
function goesInvisible(event: React.MouseEvent<HTMLButtonElement>) {
44
event.persist();
@@ -83,13 +83,44 @@ export default function Site() {
8383
const uploadResult = React.createRef<HTMLDivElement>();
8484
const promptResult = React.createRef<HTMLDivElement>();
8585
const networkPinger = React.createRef<HTMLDivElement>();
86+
const mouseDelayDiv = React.createRef<HTMLDivElement>();
87+
const clickCount = React.createRef<HTMLDivElement>();
88+
const mouseButton = React.createRef<HTMLDivElement>();
89+
const coordinatesDivX = React.createRef<HTMLDivElement>();
90+
const coordinatesDivY = React.createRef<HTMLDivElement>();
91+
const keypresses = React.createRef<HTMLDivElement>();
92+
93+
let mouseDelay: number;
94+
let mouseDownTime: number;
95+
let click_Count = 0;
96+
let countKeyPress = 0;
97+
98+
function eventMouseDown(e: any) {
99+
mouseDownTime = new Date().getTime();
100+
mouseButton.current!.innerHTML = '';
101+
if (e.button == 0) mouseButton.current!.innerHTML = 'left';
102+
if (e.button == 1) mouseButton.current!.innerHTML = 'middle';
103+
if (e.button == 2) mouseButton.current!.innerHTML = 'right';
104+
coordinatesDivX.current!.innerHTML = e.pageX.toString();
105+
coordinatesDivY.current!.innerHTML = e.pageY.toString();
106+
}
107+
108+
function eventMouseUp() {
109+
const mouseupTime = new Date().getTime();
110+
mouseDelay = mouseupTime - mouseDownTime;
111+
click_Count += 1;
112+
clickCount.current!.innerHTML = click_Count.toString();
113+
mouseDelayDiv.current!.innerHTML = mouseDelay.toString();
114+
}
86115

87116
const handleSubmit = () => {
88117
setSubmit(true);
89118
};
90119

91120
function usernameChange(event: ChangeEvent<HTMLInputElement>) {
92121
username.current = event.target.value;
122+
countKeyPress += 1;
123+
keypresses.current!.innerHTML = countKeyPress.toString();
93124
}
94125

95126
function passwordChange(event: ChangeEvent<HTMLInputElement>) {
@@ -174,7 +205,17 @@ export default function Site() {
174205
<button className="pure-button">Doesn't do anything</button>
175206
<button className="pure-button">Doesn't do anything</button>
176207
<button className="pure-button">Doesn't do anything</button>
208+
<button id="clickWithOptions" onMouseDown={eventMouseDown} onMouseUp={eventMouseUp}>
209+
Click with Options
210+
</button>
177211
<div id="upload_result" ref={uploadResult}></div>
212+
<div id="mouse_delay_time" ref={mouseDelayDiv}></div>
213+
<div id="click_count" ref={clickCount}></div>
214+
<div id="mouse_button" ref={mouseButton}></div>
215+
<div id="coordinatesX" ref={coordinatesDivX}></div>
216+
<div id="coordinatesY" ref={coordinatesDivY}></div>
217+
<div id="countKeyPress" ref={keypresses}></div>
218+
178219
<input
179220
type="file"
180221
id="file_chooser"

node/playwright-wrapper/interaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export async function clickWithOptions(
118118
const selector = call.request.getSelector();
119119
const options = call.request.getOptions();
120120
await invokePlaywrightMethod(state, callback, 'click', selector, JSON.parse(options));
121-
callback(null, emptyWithLog('Clicked element: ' + selector + ' \nWith options: ' + options));
121+
callback(null, emptyWithLog(`Clicked element: '${selector}' With options: '${options}'`));
122122
}
123123

124124
export async function focus(

0 commit comments

Comments
 (0)