Best Python code snippet using robotframework-pageobjects_python
test_functional.py
Source:test_functional.py
...178 self.assert_run(run, expected_returncode=0, search_output="OK")179 def test_no_selector_raises_exception(self):180 run = self.run_scenario("test_no_selector.py")181 self.assert_run(run, expected_returncode=0, search_output="OK")182 def test_selector_template(self):183 run = self.run_scenario("test_templated_selector.py")184 self.assert_run(run, expected_returncode=0, search_output="OK")185 def test_selector_self_ref(self):186 run = self.run_scenario("test_selector_self_ref.py")187 self.assert_run(run, expected_returncode=0, search_output="OK")188# def test_no_robot_action_failing_should_not_warn_about_screenshot(self):189# run = self.run_scenario("test_fail.py")190# self.assertFalse("warn" in run.output.lower(), "No warning should be issued when a method fails outside "191# "robot")192#193 def robot_importing_se2lib_after_page_object_should_work(self):194 # This run is duplicated, but it shows that SE2Lib library imported195 # with page objects works.196 run = self.run_scenario("test_template_passed.robot")...
robot_prioritizer.py
Source:robot_prioritizer.py
1import sys2import json3import argparse4from urllib.request import Request, urlopen5DESCRIPTION = """Use ChangeEngine to generate Robot Framework argument files that6 select a prioritized subset of test cases based on given changes to system7 under test."""8TEST_SELECTOR_TEMPLATE = '--test {}\n'9def get_priority_list(args, changes):10 data = {"context": "default", "changes": changes,11 "tests": {"repository": args.repository, 'subtype': 'Robot Framework'}}12 url = "{}/prioritize/".format(args.change_engine_url)13 request = Request(url)14 request.add_header('Content-Type', 'application/json;')15 body = json.dumps(data)16 response = urlopen(request, body.encode("utf-8"))17 if response.getcode() == 200:18 return json.loads(response.read())['tests']19 else:20 print("ERROR: ChangeEngine request failed. Return code: {}".format(response.getcode()))21 print(response.read())22 exit(1)23def write_argument_files(args, tests):24 prioritized = []25 while len(prioritized) < args.top and tests:26 prioritized.append(tests.pop(0))27 rest = tests28 with open(args.prioritized_file, 'w') as argument_file:29 for test in prioritized:30 argument_file.write(TEST_SELECTOR_TEMPLATE.format(test['name']))31 if args.remnant:32 with open(args.remnant_file, 'w') as argument_file:33 for test in rest:34 argument_file.write(TEST_SELECTOR_TEMPLATE.format(test['name']))35def changes_from_stdin():36 changes = []37 line = input()38 while True:39 changes.append(line)40 try:41 line = input()42 except EOFError:43 break44 return changes45def changes_from_args():46 return sys.argv[1:]47if __name__ == '__main__':48 if sys.version_info[0] < 3:49 sys.exit('Unsupported Python version (' + str(sys.version_info.major) + '). Please use version 3.')50 parser = argparse.ArgumentParser(description=DESCRIPTION)51 parser.add_argument('--change_engine_url', required=True, help='url for the change engine instance')52 parser.add_argument('--repository', default='default repo', help='repository of the tests')53 parser.add_argument('--context', default='default', help='context of the prioritization (defaul: default)')54 parser.add_argument('--prioritized_file', default='prioritized.robot', help='sets the name of the prioritized argument file (default: prioritized.robot)')55 parser.add_argument('--top', type=int, default=3, help='number of tests in the prioritized set (default: 10)')56 parser.add_argument('--remnant', action='store_true', help='generate a remnant argument file that contains the rest of the test cases')57 parser.add_argument('--remnant_file', default='remnant.robot', help='sets the name of the remnant argument file (default: remnant.robot)')58 parser.add_argument('--changes', nargs='+', help='list of changes to the system under test')59 parser.add_argument('--stdin', action='store_true', help='read changes from stdin, items separated by new lines')60 args = parser.parse_args()61 changes = changes_from_stdin() if args.stdin else args.changes62 priority_list = get_priority_list(args, changes)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!