Skip to content

Commit 74ae2fb

Browse files
authored
Web element property validation (#20)
* Add keyword Element is disable * Add element is enabled keyword * Add keyword check visibility * Fix timeount to 0.1 seconds * Add keyword element should contain text * Add element text should be and should not be keywords * Update doc and version
1 parent 4d31343 commit 74ae2fb

File tree

6 files changed

+155
-2
lines changed

6 files changed

+155
-2
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
*** Settings ***
2+
Library PuppeteerLibrary
3+
Test Setup Open browser to test page
4+
Test Teardown Close Browser
5+
6+
7+
*** Variables ***
8+
${HOME_PAGE_URL} http://127.0.0.1:7272
9+
10+
11+
*** Test Cases ***
12+
Element property is disable
13+
Element Should Be Disabled id:disabled-button
14+
Run Keyword And Expect Error REGEXP:Element 'id:username_field' is enabled Element Should Be Disabled id:username_field
15+
16+
Element proprty is enable
17+
Element Should Be Enabled id:username_field
18+
19+
Element is visible and not visible
20+
Element Should Be Visible id:username_field
21+
Element Should Not Be Visible id:not-visible-button
22+
Run Keyword And Expect Error REGEXP:Element 'id:not-visible-button' is not be visible Element Should Be Visible id:not-visible-button
23+
24+
Element should containt text
25+
Element Should Contain id=container please input ${True}
26+
27+
Element should not contain text
28+
Element Should Not Contain id=container please input2 ${True}
29+
30+
Element text should be
31+
Element Text Should Be id=get_ajax Change Content ${True}
32+
33+
Element test should not be
34+
Element Text Should Not Be id=get_ajax Change ${True}
35+
36+
*** Keywords ***
37+
Open browser to test page
38+
${HEADLESS} Get variable value ${HEADLESS} ${False}
39+
&{options} = create dictionary headless=${HEADLESS}
40+
Open browser ${HOME_PAGE_URL} options=${options}

PuppeteerLibrary/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
WaitingKeywords,
2222
WaitingKeywordsAsync)
2323

24-
__version__ = '0.4.1'
24+
__version__ = '0.4.2'
2525

2626

2727
class PuppeteerLibrary(DynamicCore):

PuppeteerLibrary/keywords/element.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,59 @@ def get_value(self, locator):
6868
| ${value} | `Get Value` | id:comment |
6969
"""
7070
return self.loop.run_until_complete(self.async_func.get_text_async(locator))
71+
72+
@keyword
73+
def element_should_be_disabled(self, locator):
74+
""" Verifies that element identified by locator is disabled.
75+
76+
"""
77+
return self.loop.run_until_complete(self.async_func.element_should_be_disabled_async(locator))
78+
79+
@keyword
80+
def element_should_be_enabled(self, locator):
81+
""" Verifies that element identified by locator is enabled.
82+
83+
"""
84+
return self.loop.run_until_complete(self.async_func.element_should_be_enabled_async(locator))
85+
86+
@keyword
87+
def element_should_be_visible(self, locator):
88+
""" Verifies that element identified by locator is visible.
89+
90+
"""
91+
return self.loop.run_until_complete(self.async_func.element_should_be_visible_async(locator))
92+
93+
@keyword
94+
def element_should_not_be_visible(self, locator):
95+
""" Verifies that element identified by locator is not be visible.
96+
97+
"""
98+
return self.loop.run_until_complete(self.async_func.element_should_not_be_visible_async(locator))
99+
100+
@keyword
101+
def element_should_contain(self, locator, expected, ignore_case=False):
102+
""" Verifies that element locator contains text `expected`.
103+
104+
"""
105+
return self.loop.run_until_complete(self.async_func.element_should_contain_async(locator, expected, ignore_case))
106+
107+
@keyword
108+
def element_should_not_contain(self, locator, expected, ignore_case=False):
109+
""" Verifies that element locator should not contains text `expected`.
110+
111+
"""
112+
return self.loop.run_until_complete(self.async_func.element_should_not_contain_async(locator, expected, ignore_case))
113+
114+
@keyword
115+
def element_text_should_be(self, locator, expected, ignore_case=False):
116+
""" Verifies that element locator contains exact the text `expected`.
117+
118+
"""
119+
return self.loop.run_until_complete(self.async_func.element_text_should_be_async(locator, expected, ignore_case))
120+
121+
@keyword
122+
def element_text_should_not_be(self, locator, expected, ignore_case=False):
123+
""" Verifies that element locator not contains exact the text `expected`.
124+
125+
"""
126+
return self.loop.run_until_complete(self.async_func.element_text_should_not_be_async(locator, expected, ignore_case))

PuppeteerLibrary/keywords/element_async.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from robot.libraries.BuiltIn import BuiltIn
2+
13
from PuppeteerLibrary.base.robotlibcore import keyword
24
from PuppeteerLibrary.base.librarycomponent import LibraryComponent
35

@@ -44,3 +46,53 @@ async def get_text_async(self, selenium_locator):
4446
async def get_value_async(self, selenium_locator):
4547
element = await self.ctx.get_current_page().querySelector_with_selenium_locator(selenium_locator)
4648
return (await (await element.getProperty('value')).jsonValue())
49+
50+
@keyword
51+
async def element_should_be_disabled_async(self, selenium_locator):
52+
element = await self.ctx.get_current_page().querySelector_with_selenium_locator(selenium_locator)
53+
is_disabled = await (await element.getProperty('disabled')).jsonValue()
54+
if not is_disabled:
55+
raise AssertionError("Element '%s' is enabled. " % selenium_locator)
56+
return element
57+
58+
@keyword
59+
async def element_should_be_enabled_async(self, selenium_locator):
60+
element = await self.ctx.get_current_page().querySelector_with_selenium_locator(selenium_locator)
61+
is_disabled = await (await element.getProperty('disabled')).jsonValue()
62+
if is_disabled:
63+
raise AssertionError("Element '%s' is disabled. " % selenium_locator)
64+
return element
65+
66+
@keyword
67+
async def element_should_be_visible_async(self, selenium_locator):
68+
try:
69+
return await self.ctx.get_current_page().waitForSelector_with_selenium_locator(selenium_locator, 0.1, visible=True, hidden=False)
70+
except:
71+
raise AssertionError("Element '%s' is not be visible. " % selenium_locator)
72+
73+
@keyword
74+
async def element_should_not_be_visible_async(self, selenium_locator):
75+
try:
76+
return await self.ctx.get_current_page().waitForSelector_with_selenium_locator(selenium_locator, 0.1, visible=False, hidden=True)
77+
except:
78+
raise AssertionError("Element '%s' is visible. " % selenium_locator)
79+
80+
@keyword
81+
async def element_should_contain_async(self, selenium_locator, expected, ignore_case=False):
82+
text = await self.get_text_async(selenium_locator)
83+
return BuiltIn().should_contain(text, expected, ignore_case=ignore_case)
84+
85+
@keyword
86+
async def element_should_not_contain_async(self, selenium_locator, expected, ignore_case=False):
87+
text = await self.get_text_async(selenium_locator)
88+
return BuiltIn().should_not_contain(text, expected, ignore_case=ignore_case)
89+
90+
@keyword
91+
async def element_text_should_be_async(self, selenium_locator, expected, ignore_case=False):
92+
text = await self.get_text_async(selenium_locator)
93+
return BuiltIn().should_be_equal_as_strings(text, expected, ignore_case=ignore_case)
94+
95+
@keyword
96+
async def element_text_should_not_be_async(self, selenium_locator, expected, ignore_case=False):
97+
text = await self.get_text_async(selenium_locator)
98+
return BuiltIn().should_not_be_equal_as_strings(text, expected, ignore_case=ignore_case)

demoapp/html/index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ <h2>The XMLHttpRequest Object</h2>
5757
<div style="margin-top: 30px;">
5858
<button type="button" onclick="alertConfirm()" id="alert_confirm">Alert confirm</button>
5959
</div>
60+
<div style="margin-top: 30px;">
61+
<h3>Element property</h3>
62+
<button id="disabled-button" disabled>disable button</button>
63+
<button id="not-visible-button" style="display:None;">in visible button</button>
64+
</div>
6065
</div>
6166
</body>
6267
</html>

docs/PuppeteerLibrary.html

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

0 commit comments

Comments
 (0)