机器人框架-跨浏览器测试 [英] Robot Framework - Cross browser testing
问题描述
我是新接触自动化的人,我想在Robot框架中进行跨浏览器测试。我可以在浏览器管理文件中添加什么方法,以便我的测试用例可以在多个浏览器中运行https://github.com/MarkusBernhardt/robotframework-selenium2library-java/blob/master/src/main/java/com/github/markusbernhardt/selenium2library/keywords/BrowserManagement.java
谢谢,非常感谢您的帮助!
推荐答案
SeleniumLibrary不能在多个浏览器上运行同一命令。这个特性听起来确实很酷,但需要对其进行相当大的修改(所有修改都围绕着将相同的命令传递给所有浏览器),并处理其当前体系结构中任何不可预见的情况(如果其中一个Selenium驱动程序失去连接,但其他驱动程序工作正常,该怎么办?等)。
多浏览器测试的通常方法是针对每个浏览器逐个运行案例集合。因此,将生成完全覆盖矩阵-在一个浏览器上运行不会影响在另一个浏览器上运行。一个非常基本的示例如何做到这一点-使用内联注释编写代码:
*** Settings ***
Documentation A suite of cases.
Library SeleniumLibrary
# the browser will be opened in the start-up of the suite
Suite Setup Open Browser url=https://www.google.com browser=${browser} # which browser? the one that's the value of the variable
Suite Teardown Close Browser # and closed when the suite finishes
*** Variables ***
# the variable will hold the name of the target browser
${browser} Chrome # a default value, if not overriden
*** Test Cases ***
Test this
[Documentation] Do this then that and verify the thing.
Go To https://www.yahoo.com
My Keyword 1
My Keyword 2
Verify That
[Documentation] Another case
My Keyword Doing Thing with argument
Log log message
so-要使用的实际浏览器是${browser}
变量的值。如果它没有被覆盖,它会有一个默认值(在这种情况下是Chrome)。
现在,要使用不同的浏览器运行,只需在用于启动运行的CLI上设置其名称;示例:
robot --variable browser:Firefox suitessample.robot
参数--variable
用于设置1的值;它的格式为var_name:value
。the user guide, the Variables section中详细介绍了此btw。
因此,您可以使用Chrome启动一次运行,使用Firefox启动另一次运行,依此类推。
小提示-默认情况下,运行日志位于名为"output.xml"、"log.html"和"report.html"的文件中。如果您使用3个不同的浏览器启动3次运行,并且不费心复制这些文件,它们将被覆盖。最好为每个都定义一个自定义名称,以便于处理。这是通过以下3个参数完成的---output
、--log
和--report
;例如:
robot --variable browser:Edge --output output-edge.xml --log log-edge.html --report report-edge.html suitessample.robot
附注。我确实知道您在jython中使用RF,但我没有此环境,因此是普通的独立RF-您可以在用户指南的帮助下调整CLI示例和库导入。
这篇关于机器人框架-跨浏览器测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!