def _start_server(interface, server_conf, robot_conf): suite = TestSuite('RFServer', rpa=True) suite.resource.imports.library('RFServer', args=[interface, server_conf]) test = suite.tests.create('RFserver Task') if version.parse(VERSION) < version.parse('4.0.0'): test.keywords.create('RFServer.Main Loop') else: test.body.create_keyword('RFServer.Main Loop') suite.run(**robot_conf)
def random_walker(file_path, coverage, walk_path=None): # 初始化robot suite test_suite_name = os.path.basename(file_path).split('.')[0] suite = TestSuite(test_suite_name) suite.resource.imports.library('ApolloLibrary') g = graphml.read_graphml(file_path) e = [e for e in g.edges_iter()] n = [n for n in g.node] edges = g.edge nodes = g.node now_coverage = 0 exec_paths = [] while now_coverage < coverage: curr_path = [] node = 'n0' while g.successors(node): if len(g.successors(node)) > 0 and node == 'n0': curr_path.append('n0') node = g.successors(node)[int(random.uniform(0, len(g.successors(node))))] curr_path.append(node) elif len(g.successors(node)) > 0 and node != 'n0': prev_node = curr_path[-2] node = g.successors(node)[int(random.uniform(0, len(g.successors(node))))] if node == prev_node: break curr_path.append(node) elif len(g.successors(node)) == 0: break exec_paths.append(curr_path) if len(exec_paths) > 1: exec_paths = sorted(exec_paths) exec_paths = [exec_paths[i] for i in range(len(exec_paths)) if i == 0 or exec_paths[i] != exec_paths[i - 1]] curr_nodes = list(set([item for sub_list in exec_paths for item in sub_list])) now_coverage = float(len(curr_nodes)) / float(len(n)) * 100 # 整合成robot suite if walk_path is None: for exec_path in exec_paths: generate_suite(suite, nodes, edges, exec_path) else: sorted_path = [] for path in walk_path: temp = path.replace('[', '').replace(']', '').replace(',', '') sorted_path.append(temp) generate_suite(suite, nodes, edges, sorted_path) # 运行suite并回收报告 suite.run(output='results/{}.xml'.format(test_suite_name)) xml_files = [join('results/', f) for f in os.listdir('results/') if isfile(join('results/', f))] ResultWriter(*xml_files) \ .write_results(log='reports/{}_log.html'.format(test_suite_name) , report='reports/{}_report.html'.format(test_suite_name) , output='reports/{}_output.xml'.format(test_suite_name))
class BaiduSearchTest(): def __init__(self, name, librarys=["SeleniumLibrary"]): # 创建测试套件 self.suite = TestSuite(name) # 导入SeleniumLibrary for lib in librarys: self.suite.resource.imports.library(lib) # 定义变量 def create_variables(self): variables = { "${baidu}": "https://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) # 测试用例:启动浏览器 def open_browsers(self): test_01 = self.suite.tests.create("Open") test_01.keywords.create("Open Browser", args=["${baidu}", "${browser}"]) test_01.keywords.create("Title Should Be", args=[u"百度一下,你就知道"]) # 测试用例:百度搜索测试 def search_word(self): test_02 = self.suite.tests.create(u"百度搜索测试") test_02.keywords.create("Input Text", args=["${search_input}", u"测试教程网"]) test_02.keywords.create("Click Button", args=["${search_btn}"]) test_02.keywords.create("Sleep", args=["5s"]) # 测试用例:断言验证搜索结果标题 def assert_title(self): test_03 = self.suite.tests.create(u"断言验证搜索结果标题") test_03.keywords.create("Title Should Be", args=[u"测试教程网_百度搜索"]) # 测试用例:关闭测试用例 def close_browsers(self): test_04 = self.suite.tests.create("Close") test_04.keywords.create("Close All Browsers") # 运行 def run(self): self.create_variables() self.open_browsers() self.search_word() self.assert_title() self.close_browsers() # 运行套件 result = self.suite.run(critical="find_baidu", output=os.getcwd() + "/tempfile/output.xml") # 生成日志、报告文件 ResultWriter(result).write_results( report=os.getcwd() + "/tempfile/report.html", log=os.getcwd() + "/tempfile/log.html")
class BaiduSerachTest: def __init__(self, name, librarys=["SeleniumLibrary"]): # 创建测试套件 self.suit = TestSuite(name) # 导入支持库 for lib in librarys: self.suit.resource.imports.library(lib) # 创建变量 def create_variables(self): variables = { "${baidu}": "http://www.baidu.com", "${browser}": "Chrome", "${searchWord}": "Python", "${search_input}": "id=kw", "${search_btn}": "id=su" } for k, v in variables.items(): self.suit.resource.variables.create(k, v) # 创建测试用例:启动浏览器 def open_browsers(self): test_01 = self.suit.tests.create("启动浏览器") test_01.keywords.create("Open Browser", args=["${baidu}", "${browser}"]) test_01.keywords.create("Title Should Be", args=["百度一下,你就知道"]) # 创建测试用例:搜索测试 def search_word(self): test_02 = self.suit.tests.create("关键字搜索测试") test_02.keywords.create("Input Text", args=["${search_input}", "${searchWord}"]) test_02.keywords.create("Click Button", args=["${search_btn}"]) test_02.keywords.create("Sleep", args=["5s"]) # 创建测试用例:断言 def assert_title(self): test_03 = self.suit.tests.create("断言验证搜索结果页标题") test_03.keywords.create("Title should be", args=["Python_百度搜索"]) # 创建测试用例:关闭 def close_browsers(self): test_04 = self.suit.tests.create("关闭浏览器") test_04.keywords.create("Close All Browsers") # 运行 def run(self): self.create_variables() self.open_browsers() self.search_word() self.assert_title() self.close_browsers() # 运行套件 result = self.suit.run(critical="百度搜索", output="output3.xml") ResultWriter(result).write_results(report="report3.html", log="log3.html")
class BaiduTest(object): def __init__(self, name, librarys=['SeleniumLibrary']): #创建测试套件 self.suite = TestSuite(name) #导入seleniumlibrary for lib in librarys: 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) #测试用例 def open_browser(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 search_words(self): test_02 = self.suite.tests.create('百度搜索测试') test_02.keywords.create("Input Text", args=["${search_input}", "测试教程网"]) test_02.keywords.create("Click Button", args=["${search_btn}"]) test_02.keywords.create("Sleep", args=['5s']) def assert_title(self): test_03 = self.suite.tests.create('断言结果') test_03.keywords.create("Title Should Be", args=["测试教程网_百度搜索"]) def close_browsers(self): test_04 = self.suite.tests.create("关闭浏览器") test_04.keywords.create("Close All Browsers") test_04.keywords.create("Sleep", args=['5s']) def run(self): self.create_variables() self.open_browser() self.search_words() self.assert_title() self.close_browsers() # 运行套件 result = self.suite.run(critical="百度搜索", output="output.xml") # 生成日志、报告文件 ResultWriter(result).write_results(report="report.html", log="log.html")
def run(self): if options.verbose: print " @@@ in SoapUIRunner (%s) @@@ " % self.file rc = 0 if not options.batch: os.putenv('DB_PROPERTIES',db_prop) rc = loader.run_makesuds(self.file) else: from robot.api import TestSuite, TestSuiteBuilder suite = TestSuite(str(self)) suite.imports.resource("common_resource.txt") suite.imports.library("generic_testloader") t = suite.tests.create(name=self.name) t.keywords.create("Set Environment Variable", args=["NO_SOAPUI_REPORT","1"]) t.keywords.create("Set Environment Variable", args=["SOAPUI_LOGSDIR",os.getenv('ROBOT_REPORTDIR')+'/'+self.name+'/'+'SOAPUI_LOGS']) t.keywords.create("Set Environment Variable", args=["DB_PROPERTIES",db_prop]) t.keywords.create("Run Makesuds", args=[self.file]) t.keywords.create("Soapui Project Passed", args=[os.getenv('ROBOT_REPORTDIR')+'/'+self.name+'/'+'SOAPUI_LOGS/soapui-errors.log']) # dirty hack since create doesn't expand vars rc = suite.run(loglevel=os.getenv('ROBOT_SYSLOG_LEVEL'), outputdir=os.path.join(os.getenv('ROBOT_REPORTDIR'),self.name)) #debugfile=os.getenv('ROBOT_DEBUGFILE') rc = rc.return_code return rc
def run(self): if options.verbose: print " @@@ in PyBotRunner (%s) @@@ " % self.file rc = 0 if not options.batch: os.putenv('DB_PROPERTIES',db_prop) try: rc = loader.run_pybot(self.file) except AssertionError: rc = 1 else: from robot.api import TestSuite, TestSuiteBuilder suite = TestSuite(str(self)) suite.imports.resource("common_resource.txt") suite.imports.library("generic_testloader") t = suite.tests.create(name=self.name) t.keywords.create("Set Environment Variable", args=["DB_PROPERTIES",db_prop]) t.keywords.create("Run Pybot", args=[self.file]) rc = suite.run(loglevel=os.getenv('ROBOT_SYSLOG_LEVEL'), outputdir=os.path.join(os.getenv('ROBOT_REPORTDIR'),self.name)) #debugfile=os.getenv('ROBOT_DEBUGFILE') rc = rc.return_code return rc
def run(self): if options.verbose: print " @@@ in ContainerRunner (%s) @@@ " % self.file rc = 0 if not options.batch: for r in self.runners: if r.run()==1: rc=1 break else: from robot.running import TestSuite, TestSuiteBuilder suite = TestSuite(str(self)) suite.imports.resource("common_resource.txt") suite.imports.library("generic_testloader") t = suite.tests.create(name=self.name) for r in self.runners: if isinstance(r,RobotRunner): t.keywords.create("Run Pybot", args=[r.file]) t.keywords.create("Set Environment Variable", args=["DB_PROPERTIES",db_prop]) elif isinstance(r,PyTestRunner): t.keywords.create("Set Environment Variable", args=["SCREENSHOT_DIR",os.getenv('ROBOT_REPORTDIR')+'/'+'SEL-SCREENSHOTS']) t.keywords.create("Set Environment Variable", args=["DB_PROPERTIES",db_prop]) t.keywords.create("Run Pytest", args=[r.file]) elif isinstance(r,SoapUIRunner): t.keywords.create("Set Environment Variable", args=["NO_SOAPUI_REPORT","1"]) t.keywords.create("Set Environment Variable", args=["SOAPUI_LOGSDIR",os.getenv('ROBOT_REPORTDIR')+'/'+r.name+'/'+'SOAPUI_LOGS']) t.keywords.create("Set Environment Variable", args=["DB_PROPERTIES",db_prop]) t.keywords.create("Run Makesuds", args=[r.file]) t.keywords.create("Soapui Project Passed", args=[os.getenv('ROBOT_REPORTDIR')+'/'+r.name+'/'+'SOAPUI_LOGS/soapui-errors.log']) # dirty hack since create doesn't expand vars rc = suite.run(loglevel=os.getenv('ROBOT_SYSLOG_LEVEL'), outputdir=os.path.join(os.getenv('ROBOT_REPORTDIR'),r.name)) #debugfile=os.getenv('ROBOT_DEBUGFILE') XXX not working ??? rc = rc.return_code return rc
from robot.api import ResultWriter from robot.reporting.resultwriter import Results suite = TestSuite('I am Test Suite') #TODO: import python module suite.imports.library('lib.py') test_case = suite.tests.create('Should Activate Skynet', tags=['smoke']) kw = test_case.keywords.create(assign=['${var}'], name='Set Variable', args=['value in variable']) kw2 = test_case.keywords.create('log', args=['this is my first robot python case']) result = suite.run(critical='smoke', dryrun = 'dryrun',output='skynet.xml') ''' <class 'robot.result.executionresult.Result'> ['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_stat_config', '_status_rc', 'configure', 'errors', 'generated_by_robot', 'handle_suite_teardown_failures', 'return_code', 'save', 'source', 'statistics', 'suite', 'visit'] ''' #result = suite.run() assert result.return_code == 0 # Report and xUnit files can be generated based on the result object. ResultWriter(result).write_results(report='report.html', log='log.html') # Generating log files requires processing the earlier generated output XML.
class CxmCaiWuTest: def __init__(self, name, librarys=["SeleniumLibrary"]): # 创建测试套件 self.suite = TestSuite(name) # 导入SeleniumLibrary for lib in librarys: self.suite.resource.imports.library(lib) # 定义变量 def create_variables(self): variables = { "${url}": "http://test.mmp-new.caixm.cn/", "${browser}": "Chrome", "${username_type}": "id=userName", "${password_type}": "id=password", "${loginBtn}": 'xpath=//*[@id="root"]/div/div[2]/div[2]/div/form/div[3]/div/div/span/button' } for k, v in variables.items(): self.suite.resource.variables.create(k, v) # 测试用例:启动浏览器 def open_browsers(self): test_01 = self.suite.tests.create("启动浏览器") test_01.keywords.create("Open Browser", args=["${url}", "${browser}"]) test_01.keywords.create("Title Should Be", args=["菜小秘"]) # 测试用例:输入账号和密码,登录财务端 def et_word(self): test_02 = self.suite.tests.create("登录财务端") test_02.keywords.create("Sleep", args=["5s"]) test_02.keywords.create("Input Text", args=["${username_type}", "15868134428"]) test_02.keywords.create("Input Text", args=["${password_type}", "232323"]) test_02.keywords.create("Click Button", args=["${loginBtn}"]) test_02.keywords.create("Sleep", args=["5s"]) # 测试用例:断言验证登录之后标题 def assert_title(self): test_03 = self.suite.tests.create("断言验证登录之后标题") test_03.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.et_word() self.assert_title() self.close_browsers() # 运行套件 result = self.suite.run(critical="菜小秘财务端", output="../reports/output.xml") # 生成日志、报告文件 ResultWriter(result).write_results(report="../reports/report.html", log="../reports/log.html")
def full_walker(file_path): # 初始化robot suite test_suite_name = os.path.basename(file_path).split('.')[0] suite = TestSuite(test_suite_name) suite.resource.imports.library('ApolloLibrary') g = graphml.read_graphml(file_path) e = [e for e in g.edges_iter()] n = [n for n in g.node] edges = g.edge nodes = g.node revers_paths = [] exec_paths = [] # 获取所有反向路径 for edge1 in e: for edge2 in e: if edge1[0] == edge2[1] and edge1[1] == edge2[0]: revers_paths.append(edge1) # 遍历反向路径 if len(revers_paths) > 0: for revers_path in revers_paths: for path in nx.all_simple_paths(g, 'n0', revers_path[0]): if path[-2] == revers_path[1]: exec_paths.append(path + [revers_path[1]]) # 搜寻所有的末端路径 for node in n: if len(g.successors(node)) == 0: for path in nx.all_simple_paths(g, 'n0', node): exec_paths.append(path) # 整合成robot suite for exec_path in exec_paths: test = suite.tests.create(str(exec_path).strip(' ')) for i in range(len(exec_path)-1): prev_node = exec_path[i] next_node = exec_path[i+1] if str(nodes[prev_node]['label']).lower() == 'start': test.keywords.create('Log', args=['测试开始'.decode('utf-8')]) e_label = edges['n0'][next_node]['label'] if len(e_label.split('/')) > 1: test.keywords.create(e_label.split('/')[0], args=[e_label.split('/')[1]]) else: test.keywords.create(edges['n0'][next_node]['label']) test.keywords.create('Log', args=['当前的节点为: {}'.format(next_node).decode('utf-8')]) n_label = nodes[next_node]['label'] if len(n_label.split('/')) > 1: test.keywords.create(n_label.split('/')[0], args=[n_label.split('/')[1]]) else: test.keywords.create(n_label) else: test.keywords.create('Log', args=['当前的向量为: {}'.format(edges[prev_node][next_node]['id']).decode('utf-8')]) e_label = edges[prev_node][next_node]['label'] if len(e_label.split('/')) > 1: test.keywords.create(e_label.split('/')[0], args=[e_label.split('/')[1]]) else: test.keywords.create(e_label) test.keywords.create('Log', args=['当前的节点为: {}'.format(next_node).decode('utf-8')]) n_label = nodes[next_node]['label'] if len(n_label.split('/')) > 1: test.keywords.create(n_label.split('/')[0], args=[n_label.split('/')[1]]) else: test.keywords.create(n_label) # 运行suite并回收报告 suite.run(output='../results/{}.xml'.format(test_suite_name)) xml_files = [join('../results/', f) for f in listdir('../results/') if isfile(join('../results/', f))] ResultWriter(*xml_files) \ .write_results(log='../reports/{}_log.html'.format(test_suite_name) , report='../reports/{}_report.html'.format(test_suite_name) , output='../reports/{}_output.xml'.format(test_suite_name))
class CRM_add_areaTest: def __init__(self, name, librarys=["SeleniumLibrary"]): # 创建测试套件 self.suite = TestSuite(name) # 导入SeleniumLibrary for lib in librarys: self.suite.resource.imports.library(lib) # 定义变量 def create_variables(self): variables = { "${CRM}": "https://crm.kemai.com.cn", "${browser}": "Chrome", "${login1_input}": "name=user_name", "${login2_input}": "name=password", "${login_btn}": "class=loginBut", "${ziliao_element}": "xpath=//*[.='资料']", "${area_element}": "xpath=//*[.='区域信息']", "${area_add_btn}": "id=area_add", "${area_name_input}": "xpath=//div[@class='form-body']/div[2]/div/input", "${area_save_btn}": "xpath=//*[.='保存']", "${area_add_result}": "class=km-modal-dialog-msg" } for k, v in variables.items(): self.suite.resource.variables.create(k, v) # 测试用例:启动浏览器 def open_browsers(self): test_01 = self.suite.tests.create("启动浏览器") test_01.keywords.create("Open Browser", args=["${CRM}", "${browser}"]) test_01.keywords.create("Title Should Be", args=["科脉慧猿CRM"]) # 测试用例:慧猿CRM登录 def login(self): test_02 = self.suite.tests.create("慧猿CRM登录测试") test_02.keywords.create("Input Text", args=["${login1_input}", "769316"]) test_02.keywords.create("Input Text", args=["${login2_input}", "crm666"]) test_02.keywords.create("Click Button", args=["${login_btn}"]) test_02.keywords.create("Sleep", args=["3s"]) # 测试用例:断言验证搜索结果标题 def assert_title(self): test_03 = self.suite.tests.create("断言验证登录结果标题") test_03.keywords.create("Title Should Be", args=["科脉慧猿CRM-首页"]) # 测试用例:新增区域 def add_area(self): test_04 = self.suite.tests.create("新增区域") test_04.keywords.create("Sleep", args=["5s"]) test_04.keywords.create("Click element", args=["${ziliao_element}"]) test_04.keywords.create("Sleep", args=["3s"]) test_04.keywords.create("Click element", args=["${area_element}"]) test_04.keywords.create("Sleep", args=["3s"]) test_04.keywords.create("Click Button", args=["${area_add_btn}"]) test_04.keywords.create("Sleep", args=["3s"]) test_04.keywords.create("Input Text", args=["${area_name_input}", "测试robot"]) test_04.keywords.create("Click Button", args=["${area_save_btn}"]) test_04.keywords.create("Sleep", args=["3s"]) # 测试用例:断言验证新增区域结果 def assert_result(self): test_05 = self.suite.tests.create("断言验证新增区域结果") test_05.keywords.create("Page Should Contain Button", args=["确定"]) # 测试用例:关闭测试用例 def close_browsers(self): test_06 = self.suite.tests.create("关闭浏览器") test_06.keywords.create("Close All Browsers") # 运行 def run(self): self.create_variables() self.open_browsers() self.login() self.assert_title() self.add_area() self.assert_result() self.close_browsers() # 运行套件 result = self.suite.run(critical="登录测试", output="output.xml") # 生成日志、报告文件 ResultWriter(result).write_results(report="report.html", log="log.html")
# 创建测试用例:启动浏览器 test_01 = suite.tests.create("启动浏览器") test_01.keywords.create("Open Browser", args=["http://www.baidu.com", "Chrome"]) test_01.keywords.create("Title Should Be", args=["百度一下,你就知道"]) # 创建测试用例:搜索测试 test_02 = suite.tests.create("关键字搜索测试") test_02.keywords.create("Input Text", args=["id=kw","Python"]) test_02.keywords.create("Click Button", args=["id=su"]) test_02.keywords.create("Sleep", args=["5s"]) # 创建测试用例:断言验证搜索结果页标题 test_03 = suite.tests.create("断言验证搜索结果页标题") test_03.keywords.create("Title should be", args=["Python_百度搜索"]) # 创建测试用例:关闭测试用例 test_04 = suite.tests.create("关闭浏览器") test_04.keywords.create("Close All Browsers") # 运行套件 result = suite.run(critical="百度搜索", output="output_py.xml") # 生成日志、报告文件 ResultWriter(result).write_results(report="report_py.html", log="log_py.html")
class LowLevelTest(TestCase): @classmethod def setUpClass(cls): cls.settings = {'log_level': logging.DEBUG} def setUp(self): self.suite = TestSuite('Test low level keywords') self.suite.resource.imports.library('VnfValidator') def tearDown(self): pass def test__set_context__pass(self): tests = [ Keyword(name=u'Set application context to node_1'), Keyword(name=u'Set network context to node_1'), Keyword(name=u'Set node context to node_1'), Keyword(name=u'Set service context to node_1'), ] with patch('DockerController.DockerController') as mock_controller: mock_controller = MagicMock(DockerController) run_keyword_tests(test_instance=self, tests=tests, expected_result=Result.PASS) def test__set_context__wrong_context_type__fail(self): test = self.suite.tests.create(name=u'Test context') test.keywords.append(Keyword(name=u'Set app context to bla')) result = self.suite.run() self.assertIn("Invalid context given", result.suite.tests[0].message) def test__port__pass(self): self.suite.keywords.append(Keyword(name='Set network context to node_1', type='setup')) tests = [ Keyword(name=u'Port 80: state is open'), Keyword(name=u'Port 80/TCP: state is open'), Keyword(name=u'Port 80/UDP: state is open'), Keyword(name=u'Port 80/UDP: state is closed'), ] run_keyword_tests(test_instance=self, tests=tests, expected_result=Result.PASS) def test__port__invalid_property__fail(self): self.suite.keywords.append(Keyword(name='Set network context to node_1', type='setup')) tests = [ Keyword(name=u'Port 80: stateful is open'), ] with patch('ValidationTargets.port.exc.SetupError.ROBOT_EXIT_ON_FAILURE', False): run_keyword_tests(test_instance=self, setup=None, tests=tests, expected_result=Result.FAIL, expected_message=u'ValidationError: Property') def test__port__invalid_port__fail(self): self.suite.keywords.append(Keyword(name='Set network context to node_1', type='setup')) tests = [ Keyword(name=u'Port abc: stateful is open'), Keyword(name=u'Port abc: stateful is open'), ] with patch('ValidationTargets.port.exc.SetupError.ROBOT_EXIT_ON_FAILURE', False): run_keyword_tests(test_instance=self, setup=None, tests=tests, expected_result=Result.FAIL, expected_message=u'ValidationError: Port') def test__port__invalid_value__fail(self): self.suite.keywords.append(Keyword(name='Set network context to node_1', type='setup')) tests = [ Keyword(name=u'Port 80: state is openedd'), ] with patch('ValidationTargets.port.exc.SetupError.ROBOT_EXIT_ON_FAILURE', False): run_keyword_tests(test_instance=self, setup=None, tests=tests, expected_result=Result.FAIL, expected_message=u'ValidationError: Value')
def build_keywords(parsed_keywords, suite): for name, settings, steps in parsed_keywords: kw = suite.keywords.create(name=name) for name, value in settings: pass for assign, name, args in steps: if assign is not None: assign = [assign] else: assign = [] kw.keywords.create(name=name, assign=assign, args=args) return suite if __name__ == '__main__': data = open(sys.argv[1]).read() sections = parse_sections(data) parsed_settings = setting_parser.parse(sections['SETTING']) parsed_variables = variable_parser.parse(sections['VARIABLE']) parsed_tests = testcase_parser.parse(sections['TESTCASE']) parsed_kws = keyword_parser.parse(sections['KEYWORD']) print(parsed_kws) suite = TestSuite('test suite name') suite = build_settings(parsed_settings, suite) suite = build_variables(parsed_variables, suite) suite = build_tests(parsed_tests, suite) suite = build_keywords(parsed_kws, suite) suite.run(outputdir=tempfile.gettempdir(), log='log.html')
create_case_step(suite, suite_steps) for case in testcases: test_case_name = case.get('name') tags = case.get('tags') steps = case.get('steps') assertions = case.get('assertions') # test = suite.tests.create(test_case_name, tags=tags) test = suite.tests.create(test_case_name, tags=tags) # test.keywords.create('test_builtin_keyword') create_case_step(test, steps) create_assertion_step(test, assertions) path = "reports" apiname = 'skynet' options = { "output": "{}-output.xml".format(apiname), "log": "{}-log.html".format(apiname), "report": "{}-reporter.html".format(apiname), "outputdir": path, # "include": ['CI'] # "exclude": ['SMOKE'] } settings = RobotSettings(options) suite.configure(**settings.suite_config) result = suite.run(settings, critical='smoke') ResultWriter(settings.output if settings.log else result).write_results( report=settings.report, log=settings.log)
from robot.api import TestSuite suite = TestSuite('Login') suite.resource.imports.library('ITASLibrary') test = suite.tests.create('LoginTest', tags=['smoke']) print type(test) test.keywords.create('SetBaseUrl', args=[ 'http://192.168.168.151:8080'], type='setup') loginResp=test.keywords.create('login', args=[ 'REGSUP201504','1234a*']) print type(loginResp) result = suite.run(critical='smoke', output='skynet.xml')