RobotFramework自动化框架,基础教程整理。
robotframework本身可以用ride编辑写用例,但那交互真是太别扭了。 我宁愿手撸脚本。这里我是用pycharm 写的,配置好后,写了个最基础的Web自动化脚本。
1 2 3 4 5 6 7 8 *** Test Cases *** test01 [Documentation] 基础用例:打开网站,点击元素 Open Browser https://www.made-in -china.com/ firefox Input Text name=word led Click Element xpath = //button[@class ='m-search-btn' ] sleep 5 Close browser
其实robotframework还可以通过robot api来些python脚本。 同样的Web自动化脚本,还可以这样写。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 from robot.api import TestSuite,ResultWriterclass WebTest : def __init__ (self, name, librarys=["SeleniumLibrary" ] ): self.suite = TestSuite(name) for lib in librarys: self.suite.resource.imports.library(lib) def search_word (self ): test_01 = self.suite.tests.create(u"基础用例:打开网站,点击元素" ) test_01.keywords.create("Open Browser" , args=["https://www.made-in-china.com/" , "firefox" ]) test_01.keywords.create("Input Text" , args=["name=word" ,"led" ]) test_01.keywords.create("Click Element" , args=["xpath = //button[@class='m-search-btn']" ]) test_01.keywords.create("sleep" , args=["5" ]) test_01.keywords.create("Close browser" ) def run (self ): self.search_word() result = self.suite.run(critical=u"搜索测试" , output="./results/output.xml" ) ResultWriter(result).write_results( report="./results/report.html" , log="./results/log.html" ) if __name__ == "__main__" : print ("用Python写Robot Framework测试" ) suite = WebTest(u"搜索测试套件" ) suite.run()