[英]How to handle prompt box with Robot Framework?
I am using Robot Framework with Selenium2Library for website tests automation. 我正在将Robot Framework与Selenium2Library一起用于网站测试自动化。 In one of the cases there is a prompt box (pop-up similar to alert, but with an input field in it, see example here ) asking for some text. 在一种情况下,会出现一个提示框(类似于警报的弹出窗口,但其中带有输入字段,请参见此处的示例 ),要求输入一些文本。 The problem is Robot Framework can only click OK or Cancel (Confirm Action and Choose Cancel On Next Confirmation keywords) on such pop-ups. 问题在于,Robot Framework只能在此类弹出窗口中单击“确定”或“取消”(“确认操作”,然后选择“在下次确认时取消”)。 So the question is: how can I input some text into the prompt box? 所以问题是:如何在提示框中输入一些文本? Is it possible? 可能吗?
In SeleniumLibrary there was a Press Key Native keyword which could press keys without specifying the target element, but it is absent in Selenium2Library. 在SeleniumLibrary中,有一个Press Key Native关键字,可以在不指定目标元素的情况下按下键,但是Selenium2Library中不存在。 If you know of any alternative - your answer will be much appreciated. 如果您知道其他选择-您的回答将不胜感激。
Using AutoIT isn't an option as the tests could be run on different platforms (not only Win). 不能选择使用AutoIT,因为测试可以在不同的平台上运行(不仅限于Win)。
Am I missing something? 我想念什么吗?
Selenium2Library doesn't currently have support for inserting text into a prompt. Selenium2Library当前不支持在提示中插入文本。 I've opened an issue in the issue tracker for this: 我已经在问题跟踪器中为此打开了一个问题:
https://github.com/rtomac/robotframework-selenium2library/issues/292 https://github.com/rtomac/robotframework-selenium2library/issues/292
Until it gets added, you can create your own selenium library by subclassing Selenium2Library, and you can add the function to your version. 在添加之前,您可以通过将Selenium2Library子类化来创建自己的Selenium库,然后可以将该函数添加到您的版本中。
For example, create a file named "CustomSeleniumLibrary.py", and make it look like this: 例如,创建一个名为“ CustomSeleniumLibrary.py”的文件,并使其如下所示:
# CustomSeleniumLibrary.py
from Selenium2Library import Selenium2Library
class CustomSeleniumLibrary(Selenium2Library):
def insert_into_prompt(self, text):
alert = None
try:
alert = self._current_browser().switch_to_alert()
alert.send_keys(text)
except WebDriverException:
raise RuntimeError('There were no alerts')
You can then write a test case which uses that library like this: 然后,您可以编写一个使用该库的测试用例,如下所示:
*** Settings ***
| Library | CustomSeleniumLibrary.py
| Suite Teardown | Close All Browsers
*** test cases ***
| Example of typing into a prompt
| | Open Browser | http://www.w3schools.com/js/tryit.asp?filename=tryjs_prompt
| | Select Frame | iframeResult
| | Click Button | Try it
| | Insert into prompt | my name is Inigo Montoya
| | Confirm action
Think it's worth pointing out that this keyword exists now (since SeleniumLibrary 3.0), so there's no longer any need to use a custom script/library. 认为值得指出的是,此关键字现已存在(自SeleniumLibrary 3.0起),因此不再需要使用自定义脚本/库。 http://robotframework.org/Selenium2Library/Selenium2Library.html#Input%20Text%20Into%20Alert http://robotframework.org/Selenium2Library/Selenium2Library.html#Input%20Text%20Into%20Alert
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.