[英]Robot Framework, integrating custom keywords with Selenium2Library
I am facing issues with adding custom keywords with robot selenium library. 我在使用机器人selenium库添加自定义关键字时遇到了问题。 I have seen some solutions for adding custom keywords but this approach does not seem to be working for me. 我已经看到了一些添加自定义关键字的解决方案,但这种方法对我来说似乎并不适用。 The custom keyword implemented in the test case is specified by CustomSeleniumLibrary.Get Ok Button.I have posted the code I have used below and my test case: Custom Keyword implementing Selenium2Library: 在测试用例中实现的自定义关键字由CustomSeleniumLibrary.Get Ok Button指定。我已经发布了我在下面使用的代码和我的测试用例:实现Selenium2Library的自定义关键字:
from Selenium2Library import Selenium2Library
# create new class that inherits from Selenium2Library
class CustomSeleniumLibrary(Selenium2Library):
# create a new keyword called "get webdriver instance"
def get_ok_button(self, locator):
element = self._get_checkbox(locator)
element.click()
Test that calls custom keyword: 测试调用自定义关键字:
*** Settings ***
Documentation A test suite containing tests related to invalid login. These
... tests are data-driven by they nature. They use a single
... keyword, specified with Test Template setting, that is called
... with different arguments to cover different scenarios.
Resource resource_one.txt
Library CustomSeleniumLibrary.py
*** Variables ***
${button_xpath} //button[@type='button']/span[text()=""'"Ok"'""]"))
${message} Please select one or more entries to unlock!
${table_TO} //table[@id='userdetailTable']/tbody/tr/td
${unlock_checkbox} //*[@id='userdetailTable']/tbody/tr/td[6]/input
*** Test Cases ***
Happy_Path_Unlock
Given a Intellix user is on the login page
When they enter their credentials
Attempt to Unlock an Valid TO User Id
Then they will see the TO User Id in the results list
*** Keywords ***
a Intellix user is on the login page
Selenium2Library.Open Browser ${url} ${BROWSER_CHROME}
they enter their credentials
Selenium2Library.Input Text ${username_xpath} ${username_txt}
Selenium2Library.Input Password ${password_xpath} ${password_txt}
Selenium2Library.Click Button ${btn_submit}
Attempt to Unlock an Valid TO User Id
Selenium2Library.Page Should Contain Link ${view_tab} ${view_tab_text}
Selenium2Library.Page Should Contain Link ${admin_tab} ${admin_tab_text}
Selenium2Library.Page Should Contain Link ${unlock_tab} ${unlock_tab_text}
Selenium2Library.Click Link ${unlock_tab}
Selenium2Library.Wait Until Element Is Visible ${TO_User_Id}
Selenium2Library.Click Element ${TO_User_Id}
Selenium2Library.Input Text ${TO_User_Id} teksmith
Selenium2Library.Click Button ${go_btn}
they will see the TO User Id in the results list
Selenium2Library.Wait Until Page Contains Element ${unlock_checkbox}
CustomSeleniumLibrary.Get Ok Button ${unlock_checkbox}
Selenium2Library.Close Window
After running files, I am getting the following error: CaptureScreenshot failed. 运行文件后,我收到以下错误:CaptureScreenshot失败。 It does not give me a specific run error for the python custom keyword implemented. 它没有给我实现的python custom关键字的特定运行错误。 Feedback on if my implementation would be much appreciated! 关于我的实施是否会受到高度赞赏的反馈!
Your code sample does not have line that imports Selenium2Library but you are constantly calling keywords from there. 您的代码示例没有导入Selenium2Library的行,但您不断地从那里调用关键字。 Maybe you forgot to include it in your sample. 也许你忘了把它包含在样品中。
Because CustomSeleniumLibrary inherits from Selenium2Library, you do not need to specify Selenium2Library. 由于CustomSeleniumLibrary继承自Selenium2Library,因此您无需指定Selenium2Library。 Try removing Selenium2Library import and all Selenium2Library and CustomSeleniumLibrary prefixes. 尝试删除Selenium2Library导入以及所有Selenium2Library和CustomSeleniumLibrary前缀。 I think they reference different browser instances. 我认为他们引用不同的浏览器实例。
I tested your custom keyword and it works fine: it fails where it should and makes a nice screenshot. 我测试了你的自定义关键字,它工作正常:它失败了应该的地方,并制作了一个很好的截图。
*** Settings ***
Library CustomSeleniumLibrary.py
Suite Teardown Close All Browsers
*** Test Cases ***
Stackoverflow
Open Browser http://www.google.com/ Chrome
Page Should Contain Element btnK
Get Ok Button foo
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.