Skip to content

Commit 9466d79

Browse files
authored
Add support selenium element keywords (#60)
* Add 'Press Keys' keyword * Add keyword 'get_element_count' * Add keyword 'Get Element Attribute' * Add keyword 'Get Selected List Label' * Add keyword 'Get Selected List Value' * Add webkit keyword 'Click Element At Coordinate' * Add keywords 'Checkbox' * Add keywors 'Delete All Cookies' * Add keyword 'Close Window' for puppeteer * Add keyword 'Close Window' for playwright * Add keyword 'Get Window Count' * Update default browser * Add keyword 'Scroll Element Into View' * Add keywords 'Set Screenshot Directory'
1 parent 7339d6f commit 9466d79

34 files changed

+587
-42
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ log.html
2222
report.html
2323
/Examples/*.png
2424
*.pdf
25+
Examples/logs/
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
*** Settings ***
2+
Library PuppeteerLibrary
3+
Suite Teardown Close Puppeteer
4+
Test Teardown Close All Browser
5+
6+
*** Variables ***
7+
${DEFAULT_BROWSER} chrome
8+
9+
10+
*** Test Cases ***
11+
Delete all cookies
12+
${BROWSER} = Get variable value ${BROWSER} ${DEFAULT_BROWSER}
13+
${HEADLESS} = Get variable value ${HEADLESS} ${False}
14+
&{options} = create dictionary headless=${HEADLESS}
15+
Open browser http://127.0.0.1:7272/basic-html-elements.html browser=${BROWSER} options=${options}
16+
Delete All Cookies

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

+27-1
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,30 @@ Handle multiple browser
3636
Wait Until Page Contains Login form
3737
Switch Browser Browser 2
3838
Wait Until Page Contains Browser Management
39-
39+
40+
Close current window
41+
[Teardown] Capture Page Screenshot
42+
${BROWSER} = Get variable value ${BROWSER} ${DEFAULT_BROWSER}
43+
${HEADLESS} Get variable value ${HEADLESS} ${False}
44+
&{options} = create dictionary headless=${HEADLESS}
45+
Open browser http://127.0.0.1:7272/basic-html-elements.html browser=${BROWSER} options=${options} alias=Browser 1
46+
Run Async Keywords
47+
... Wait For New Window Open AND
48+
... Click Element id=open-new-tab
49+
Switch Window NEW
50+
Wait Until Page Contains Login form
51+
Close Window
52+
53+
Window count
54+
[Teardown] Capture Page Screenshot
55+
${BROWSER} = Get variable value ${BROWSER} ${DEFAULT_BROWSER}
56+
${HEADLESS} Get variable value ${HEADLESS} ${False}
57+
&{options} = create dictionary headless=${HEADLESS}
58+
Open browser http://127.0.0.1:7272/basic-html-elements.html browser=${BROWSER} options=${options} alias=Browser 1
59+
${no of window} = Get Window Count
60+
Should Be Equal As Numbers 1 ${no of window}
61+
Run Async Keywords
62+
... Wait For New Window Open AND
63+
... Click Element id=open-new-tab
64+
${no of window} = Get Window Count
65+
Should Be Equal As Numbers 2 ${no of window}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
*** Settings ***
2+
Library PuppeteerLibrary
3+
Suite Teardown Close Puppeteer
4+
Test Teardown Close All Browser
5+
6+
*** Variables ***
7+
${DEFAULT_BROWSER} chrome
8+
9+
10+
*** Test Cases ***
11+
Scroll into view
12+
${BROWSER} = Get variable value ${BROWSER} ${DEFAULT_BROWSER}
13+
${HEADLESS} = Get variable value ${HEADLESS} ${False}
14+
&{options} = create dictionary headless=${HEADLESS}
15+
Open browser http://127.0.0.1:7272/basic-html-elements.html browser=${BROWSER} options=${options}
16+
Scroll Element Into View id=click_and_hide
17+
Scroll Element Into View id=get_ajax
18+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
*** Settings ***
2+
Library PuppeteerLibrary
3+
Test Teardown Close All Browser
4+
Suite Teardown Close Puppeteer
5+
6+
*** Variables ***
7+
${DEFAULT_BROWSER} chrome
8+
9+
10+
*** Test Cases ***
11+
Select Checkbox element
12+
Open browser to test page http://127.0.0.1:7272/login-form-example.html
13+
Select Checkbox id=exampleCheck1
14+
Checkbox Should Be Selected id=exampleCheck1
15+
16+
Unselect Checkbox element
17+
Open browser to test page http://127.0.0.1:7272/login-form-example.html
18+
Select Checkbox id=exampleCheck1
19+
Unselect Checkbox id=exampleCheck1
20+
Checkbox Should Not Be Selected id=exampleCheck1
21+
22+
23+
24+
*** Keywords ***
25+
Open browser to test page
26+
[Arguments] ${url}
27+
${BROWSER} = Get variable value ${BROWSER} ${DEFAULT_BROWSER}
28+
${HEADLESS} Get variable value ${HEADLESS} ${False}
29+
&{options} = create dictionary headless=${HEADLESS}
30+
Open browser ${url} browser=${BROWSER} options=${options}
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
*** Settings ***
2+
Library PuppeteerLibrary
3+
Test Teardown Close All Browser
4+
Suite Teardown Close Puppeteer
5+
6+
*** Variables ***
7+
${DEFAULT_BROWSER} chrome
8+
9+
10+
*** Test Cases ***
11+
Click element at coordiator
12+
Open browser to test page http://127.0.0.1:7272/login-form-example.html
13+
Run Async Keywords
14+
... Wait For New Window Open AND
15+
... Click Element At Coordinate css=button[type="submit"] 1 1
16+
17+
18+
*** Keywords ***
19+
Open browser to test page
20+
[Arguments] ${url}
21+
${BROWSER} = Get variable value ${BROWSER} ${DEFAULT_BROWSER}
22+
${HEADLESS} Get variable value ${HEADLESS} ${False}
23+
&{options} = create dictionary headless=${HEADLESS}
24+
Open browser ${url} browser=${BROWSER} options=${options}

Examples/form-handler/dropdown-list.robot

+10
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ Select dropdown list by labels with id
2222

2323
Select dropdown list by labels with xpath
2424
Select From List By Label xpath=//select[@id="cars"] Audi
25+
26+
Get selected dropdown list label
27+
Select From List By Label id=cars Audi
28+
${Label} = Get Selected List Label xpath=//select[@id="cars"]
29+
Should Be Equal As Strings Audi ${Label}
30+
31+
Get selected dropdown list value
32+
Select From List By Label id=cars Audi
33+
${Value} = Get Selected List Value xpath=//select[@id="cars"]
34+
Should Be Equal As Strings audi ${Value}
2535

2636
*** Keywords ***
2737
Open browser to test page

Examples/form-handler/element-properties.robot

+8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ ${HOME_PAGE_URL} http://127.0.0.1:7272/basic-html-elements.html
1010

1111

1212
*** Test Cases ***
13+
Count element
14+
${No of h2} = Get Element Count css=h2
15+
Should Be Equal As Numbers 12 ${No of h2}
16+
17+
Get element attribute
18+
${type value} = Get Element Attribute id=alert_confirm type
19+
Should Be Equal As Strings button ${type value}
20+
1321
Element proprty is enable
1422
Element Should Be Enabled id:prop-enable
1523

Examples/form-handler/form-submit.robot

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Submit register form
2828
Select From List By Value id=inputState 5
2929
Input Text id=inputZip 1234
3030
Click Element css=button[type="submit"]
31+
3132

3233
*** Keywords ***
3334
Open browser to test page

Examples/input/keyboard.robot

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
*** Settings ***
2+
Library Dialogs
3+
Library PuppeteerLibrary
4+
Test Setup Open browser to test page
5+
Test Teardown Close All Browser
6+
Suite Teardown Close Puppeteer
7+
8+
*** Variables ***
9+
${DEFAULT_BROWSER} chrome
10+
${HOME_PAGE_URL} http://127.0.0.1:7272/login-form-example.html
11+
12+
13+
*** Test Cases ***
14+
Element press keys
15+
Input Text id=exampleInputEmail1 demo@qahive.com
16+
Input Text id=exampleInputPassword1 123456789
17+
Run Async Keywords
18+
... Wait For New Window Open AND
19+
... Press Keys id=exampleInputPassword1 Enter
20+
21+
*** Keywords ***
22+
Open browser to test page
23+
${BROWSER} = Get variable value ${BROWSER} ${DEFAULT_BROWSER}
24+
${HEADLESS} Get variable value ${HEADLESS} ${False}
25+
&{options} = create dictionary headless=${HEADLESS}
26+
Open browser ${HOME_PAGE_URL} browser=${BROWSER} options=${options}

Examples/utilities/screenshot.robot

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ Capture page screenshot
1515
Capture Page Screenshot test-{index}.png
1616
Capture Page Screenshot fullPage=True
1717

18+
Set page screenshot path
19+
Set Screenshot Directory ./logs
20+
Capture Page Screenshot
1821

1922
*** Keywords ***
2023
Open browser to test page

PuppeteerLibrary/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from PuppeteerLibrary.keywords.checkbox import CheckboxKeywords
12
from typing import List
23
from PuppeteerLibrary.base.ipuppeteer_library import iPuppeteerLibrary
34
import asyncio
@@ -102,6 +103,7 @@ def __init__(self):
102103
libraries = [
103104
AlertKeywords(self),
104105
BrowserManagementKeywords(self),
106+
CheckboxKeywords(self),
105107
DropdownKeywords(self),
106108
ElementKeywords(self),
107109
FormElementKeywords(self),

PuppeteerLibrary/ikeywords/ibrowsermanagement_async.py

+6
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,9 @@ async def select_frame(self, locator: str):
4242
@abstractmethod
4343
def unselect_iframe(self):
4444
pass
45+
46+
##############################
47+
# Cookies
48+
##############################
49+
async def delete_all_cookies(self):
50+
pass
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from abc import ABC, abstractmethod
2+
from PuppeteerLibrary.ikeywords.base_async_keywords import BaseAsyncKeywords
3+
4+
5+
class iCheckboxAsync(BaseAsyncKeywords, ABC):
6+
7+
@abstractmethod
8+
async def select_checkbox(self, locator):
9+
pass
10+
11+
@abstractmethod
12+
async def unselect_checkbox(self, locator):
13+
pass
14+
15+
@abstractmethod
16+
async def checkbox_should_be_selected(self, locator):
17+
pass
18+
19+
@abstractmethod
20+
async def checkbox_should_not_be_selected(self, locator):
21+
pass

PuppeteerLibrary/ikeywords/idropdown_async.py

+8
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,11 @@ async def select_from_list_by_value(self, locator, values):
1111
@abstractmethod
1212
async def select_from_list_by_label(self, locator, labels):
1313
pass
14+
15+
@abstractmethod
16+
async def get_selected_list_labels(self, locator: str) -> str:
17+
pass
18+
19+
@abstractmethod
20+
async def get_selected_list_values(self, locator: str) -> str:
21+
pass

PuppeteerLibrary/ikeywords/ielement_async.py

+26
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,32 @@
44

55
class iElementAsync(BaseAsyncKeywords, ABC):
66

7+
##############################
8+
# Query Element
9+
##############################
10+
@abstractmethod
11+
async def find_elements(self, locator: str):
12+
pass
13+
714
##############################
815
# Action
916
##############################
1017
@abstractmethod
1118
async def click_element(self, locator: str):
1219
pass
20+
21+
@abstractmethod
22+
async def click_element_at_coordinate(self, locator: str, xoffset: str, yoffset: str):
23+
pass
1324

1425
@abstractmethod
1526
async def upload_file(self, locator: str, file_path: str):
1627
pass
1728

29+
@abstractmethod
30+
async def press_keys(self, locator: str, *keys: str):
31+
pass
32+
1833
##############################
1934
# Status
2035
##############################
@@ -48,6 +63,10 @@ async def element_should_not_contain(self, locator: str, expected: str, ignore_c
4863
@abstractmethod
4964
async def get_text(self, locator: str):
5065
pass
66+
67+
@abstractmethod
68+
async def get_attribute(self, locator: str, attribute: str) -> str:
69+
pass
5170

5271
@abstractmethod
5372
async def element_text_should_be(self, locator: str, expected: str, ignore_case=False):
@@ -56,3 +75,10 @@ async def element_text_should_be(self, locator: str, expected: str, ignore_case=
5675
@abstractmethod
5776
async def element_text_should_not_be(self, locator: str, expected: str, ignore_case=False):
5877
pass
78+
79+
##############################
80+
# Scrolling
81+
##############################
82+
@abstractmethod
83+
async def scroll_element_into_view(self, locator: str):
84+
pass

PuppeteerLibrary/keywords/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from .alert import AlertKeywords
22
from .browsermanagement import BrowserManagementKeywords
3+
from .checkbox import CheckboxKeywords
34
from .dropdown import DropdownKeywords
45
from .element import ElementKeywords
56
from .formelement import FormElementKeywords

PuppeteerLibrary/keywords/browsermanagement.py

+19-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ def open_browser(self, url, browser="chrome", alias=None, options=None):
4141
self.loop.run_until_complete(library_context.create_new_page(options))
4242
self.loop.run_until_complete(self.get_async_keyword_group().go_to(url))
4343

44+
@keyword
45+
def close_window(self):
46+
""" Close current browser tab/page
47+
"""
48+
self.loop.run_until_complete(self.ctx.get_current_library_context().close_window())
49+
4450
@keyword
4551
def close_browser(self, alias=None):
4652
"""Closes the current browser
@@ -104,8 +110,7 @@ def reload_page(self):
104110
def get_window_count(self):
105111
""" Get windows count
106112
"""
107-
pass
108-
# return self.loop.run_until_complete(self.async_func.get_window_count_async())
113+
return self.loop.run_until_complete(self.get_async_keyword_group().get_window_count())
109114

110115
@keyword
111116
def wait_for_new_window_open(self, timeout=None):
@@ -152,10 +157,22 @@ def enable_emulate_mode(self, emulate_name):
152157
"""
153158
return self.loop.run_until_complete(self.get_async_keyword_group().enable_emulate_mode_async(emulate_name))
154159

160+
##############################
161+
# iFrame
162+
##############################
155163
@keyword
156164
def select_frame(self, locator):
157165
return self.loop.run_until_complete(self.get_async_keyword_group().select_frame(locator))
158166

159167
@keyword
160168
def unselect_frame(self):
161169
self.get_async_keyword_group().unselect_iframe()
170+
171+
##############################
172+
# Cookies
173+
##############################
174+
@keyword
175+
def delete_all_cookies(self):
176+
""" Deletes all cookies.
177+
"""
178+
return self.loop.run_until_complete(self.get_async_keyword_group().delete_all_cookies())

0 commit comments

Comments
 (0)