gpt4 book ai didi

javascript - 如何使用 Robot Framework 处理提示框?

转载 作者:行者123 更新时间:2023-11-29 18:15:40 31 4
gpt4 key购买 nike

我将 Robot Framework 与 Selenium2Library 一起用于网站测试自动化。在其中一种情况下,有一个提示框(类似于警报的弹出窗口,但其中有一个输入字段,请参阅 example here )要求输入一些文本。问题是 Robot Framework 只能在此类弹出窗口上单击“确定”或“取消”(确认操作并选择“下次确认关键字时取消”)。那么问题来了:如何在提示框中输入一些文字呢?可能吗?

SeleniumLibrary 中有一个 Press Key Native 关键字,它可以在不指定目标元素的情况下按键,但在 Selenium2Library 中没有。如果您知道任何替代方案 - 您的回答将不胜感激。

使用 AutoIT 不是一种选择,因为测试可以在不同的平台(不仅是 Win)上运行。

我错过了什么吗?

最佳答案

Selenium2Library 目前不支持在提示中插入文本。为此,我在问题跟踪器中打开了一个问题:

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

在它被添加之前,您可以通过子类化 Selenium2Library 创建您自己的 selenium 库,并且您可以将该函数添加到您的版本中。

例如,创建一个名为“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')

然后您可以编写一个使用该库的测试用例,如下所示:

*** 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

关于javascript - 如何使用 Robot Framework 处理提示框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23543666/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com