Skip to content

Commit 68387ae

Browse files
author
Cleverson Sampaio
committed
feat(elementinteraction): added element interaction class
added element interaction class with clickElement, clickButton, clickLink, clickImage, sendKeys and submitForm methods
1 parent 192c941 commit 68387ae

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Copyright (c) 2022 Cléverson Sampaio <cleverson@sampaio.dev.br>
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Copyright (c) 2022 Cléverson Sampaio <cleverson@sampaio.dev.br>
5+
6+
from robot.libraries.BuiltIn import BuiltIn
7+
from robot.api.deco import keyword
8+
from SeleniumLibraryExtends.FindElements.findElements import FindElements
9+
from SeleniumLibraryExtends.report import Report
10+
11+
class ElementInteraction:
12+
def __init__(self):
13+
pass
14+
15+
@keyword("I press the element ${locator}")
16+
def clickElement(self, locator: str):
17+
self.driver = BuiltIn().get_library_instance("SeleniumLibrary")
18+
try:
19+
FindElements().waitForElementVisible(locator)
20+
REPEAT = "12x"
21+
REPEAT_INTERVAL = "5 sec"
22+
BuiltIn().wait_until_keyword_succeeds(REPEAT, REPEAT_INTERVAL, "Click Element", locator)
23+
except Exception as e:
24+
Report().fail(e)
25+
26+
@keyword("I press the button ${locator}")
27+
def clickButton(self, locator: str):
28+
self.driver = BuiltIn().get_library_instance("SeleniumLibrary")
29+
try:
30+
FindElements().waitForElementVisible(locator)
31+
REPEAT = "12x"
32+
REPEAT_INTERVAL = "5 sec"
33+
BuiltIn().wait_until_keyword_succeeds(REPEAT, REPEAT_INTERVAL, "Click Button", locator)
34+
except Exception as e:
35+
Report().fail(e)
36+
37+
@keyword("I press the link ${locator}")
38+
def clickLink(self, locator: str):
39+
self.driver = BuiltIn().get_library_instance("SeleniumLibrary")
40+
try:
41+
FindElements().waitForElementVisible(locator)
42+
REPEAT = "12x"
43+
REPEAT_INTERVAL = "5 sec"
44+
BuiltIn().wait_until_keyword_succeeds(REPEAT, REPEAT_INTERVAL, "Click Link", locator)
45+
except Exception as e:
46+
Report().fail(e)
47+
48+
@keyword("I press the image ${locator}")
49+
def clickImage(self, locator: str):
50+
self.driver = BuiltIn().get_library_instance("SeleniumLibrary")
51+
try:
52+
FindElements().waitForElementVisible(locator)
53+
REPEAT = "12x"
54+
REPEAT_INTERVAL = "5 sec"
55+
BuiltIn().wait_until_keyword_succeeds(REPEAT, REPEAT_INTERVAL, "Click Image", locator)
56+
except Exception as e:
57+
Report().fail(e)
58+
59+
@keyword("I fill in the ${locator} field with ${text}")
60+
def sendKeys(self, locator: str, text: str):
61+
self.driver = BuiltIn().get_library_instance("SeleniumLibrary")
62+
try:
63+
FindElements().waitForElementVisible(locator)
64+
REPEAT = "12x"
65+
REPEAT_INTERVAL = "5 sec"
66+
BuiltIn().wait_until_keyword_succeeds(REPEAT, REPEAT_INTERVAL, "Input Text", locator, text)
67+
except Exception as e:
68+
Report().fail(e)
69+
70+
@keyword("I submit the form")
71+
def submitForm(self):
72+
self.driver = BuiltIn().get_library_instance("SeleniumLibrary")
73+
try:
74+
self.driver.submit_form()
75+
except Exception as e:
76+
Report().fail(e)

0 commit comments

Comments
 (0)