Robotframework(5)-用python编写RF测试
- 说明:
- 可以使用RobotFramework中的RIDE来编写和执行测试用例
- 使用功能python直接操作RF,会让测试的更灵活,功能更强。
- 需具备的条件
- python编程得过关
- RF的API得熟悉
1.安装RF测试框架
- 参考列表
- https://blog.csdn.net/weixin_42006387/article/details/114269373
- https://blog.csdn.net/weixin_42006387/article/details/120491691
2.安装浏览器驱动器
- 参考:https://editor.csdn.net/md/?articleId=121746494
3.安装必要的库
- 参考:https://blog.csdn.net/weixin_42006387/article/details/120492263
4.编写测试用例
-
RobotFramework的API文档地址:https://robot-framework.readthedocs.io/en/stable/index.html -
代码举例 -
from robot.running.model import TestSuite
from robot.reporting.resultwriter import ResultWriter
class BaiduSearchTest:
def __init__(self, name, libraries=["SeleniumLibrary"]):
self.suite = TestSuite(name)
for lib in libraries:
self.suite.resource.imports.library(lib)
def create_variables(self):
variables = {
"${baidu}": "http://www.baidu.com",
"${browser}": "Chrome",
"${search_input}": "id=kw",
"${search_btn}": "id=su",
}
for k, v in variables.items():
self.suite.resource.variables.create(k, v)
print()
def open_browsers(self):
test_01 = self.suite.tests.create("启动浏览器")
test_01.keywords.create("Open Browser",
args=["${baidu}", "${browser}"])
test_01.keywords.create("Title Should Be",
args=["百度一下,你就知道"])
def close_browsers(self):
test_04 = self.suite.tests.create("关闭浏览器")
test_04.keywords.create("Close All Browsers")
def run(self):
self.create_variables()
self.open_browsers()
self.search_word()
self.close_browsers()
result = self.suite.run(critical="百度搜索",
output="output.xml")
ResultWriter(result).write_results(
report="report.html", log="log.html")
if __name__ == "__main__":
print("用Python写Robot Framework测试")
suite = BaiduSearchTest("百度搜索测试套件")
suite.run()
-
参考连接:点击跳转
5.调试
|