如何使用Robot Framework处理提示框? [英] How to handle prompt box with Robot Framework?

查看:730
本文介绍了如何使用Robot Framework处理提示框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Robot Framework与Selenium2Library一起用于网站测试自动化.在一种情况下,会出现一个提示框(类似于警报的弹出窗口,但其中带有输入字段,请参见

I am using Robot Framework with Selenium2Library for website tests automation. 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. So the question is: how can I input some text into the prompt box? Is it possible?

在SeleniumLibrary中有一个Press Key Native关键字,可以在不指定目标元素的情况下按下键,但Selenium2Library中不存在.如果您知道其他选择,将非常感谢您的回答.

In SeleniumLibrary there was a Press Key Native keyword which could press keys without specifying the target element, but it is absent in Selenium2Library. If you know of any alternative - your answer will be much appreciated.

不能选择使用AutoIT,因为测试可以在不同的平台上运行(不仅限于Win).

Using AutoIT isn't an option as the tests could be run on different platforms (not only Win).

我错过了什么吗?

推荐答案

Selenium2Library当前不支持在提示中插入文本.我已经在问题跟踪器中为此打开了一个问题:

Selenium2Library doesn't currently have support for inserting text into a prompt. I've opened an issue in the issue tracker for this:

https://github.com/rtomac/robotframework-selenium2library/issues/292

在添加之前,您可以通过将Selenium2Library子类化来创建自己的Selenium库,然后可以将该函数添加到您的版本中.

Until it gets added, you can create your own selenium library by subclassing Selenium2Library, and you can add the function to your version.

例如,创建一个名为"CustomSeleniumLibrary.py"的文件,并使它看起来像这样:

For example, create a file named "CustomSeleniumLibrary.py", and make it look like this:

# 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

这篇关于如何使用Robot Framework处理提示框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆