def test(data): actions.navigate(data.env.url) actions.send_keys(login.username_input, 'admin') actions.send_keys(login.password_input, 'incorrect password') actions.click(login.login_button) actions.take_screenshot('Verify the correct error message is shown') actions.assert_element_text(login.error_list, 'Username and password do not match')
def test_take_screenshot_with_alert_present(data): actions.navigate(data.env.url + 'alert/') actions.click('#alert-button') assert actions.get_browser().alert_is_present() actions.take_screenshot('my_screenshot_with_alert') # screenshot step is not added when an exception is thrown taking # the screenshot golem_steps.assert_last_step_message('Click #alert-button') # screenshot file was not generated listdir = os.listdir(execution.test_reportdir) assert not any(x.endswith('.png') for x in listdir) # The exception was logged assert 'There was an error while taking screenshot' in golem_logger.get_info_log( ) assert 'selenium.common.exceptions.UnexpectedAlertPresentException' in golem_logger.get_info_log( )
def run_test(self): try: if hasattr(self.test_module, 'test'): self.test_module.test(execution.data) # take screenshot_on_end if self.settings['screenshot_on_end'] and execution.browser: actions.take_screenshot('Test end') else: error_msg = 'test {} does not have a test function'.format(self.test_name) actions._add_error(error_msg) self.result['result'] = ResultsEnum.CODE_ERROR except AssertionError as e: self._add_error(message='Failure', exception=e) self.result['result'] = ResultsEnum.FAILURE except Exception as e: if not self.result['result'] == ResultsEnum.FAILURE: self.result['result'] = ResultsEnum.CODE_ERROR self._add_error(message='Error', exception=e) self.run_teardown()
def test(data): actions.navigate(data.env.url + 'elements/') actions.take_screenshot('my_screenshot') golem_steps.assert_last_step_message('my_screenshot') listdir = os.listdir(execution.report_directory) assert any(x.endswith('.png') for x in listdir)
def run_test_function(self, test_name): result = self.test_functions[test_name] self._reset_execution_module_values_for_test_function(None, test_name) if self.global_skip or self.skip_tests: result['result'] = ResultsEnum.SKIPPED execution.logger.info(f'Test skipped: {test_name}') self._finalize_test_function(test_name) return # Create folder for the test function report test_reportdir = test_report.create_test_function_report_dir(self.reportdir, test_name) result['test_reportdir'] = test_reportdir # Run before_each hooks for before_each_hook in self.test_hooks['before_each']: # reset execution values specific to this test self._reset_execution_module_values_for_test_function(None, 'before_each') before_each_result = self.generic_run_function(before_each_hook) if before_each_result != ResultsEnum.SUCCESS: self.skip_tests = True self.generate_report_for_hook_function('before_each', before_each_result) # reset execution values specific to this test self._reset_execution_module_values_for_test_function(test_reportdir, test_name) if self.skip_tests: result['result'] = ResultsEnum.SKIPPED execution.logger.info(f'Test skipped: {test_name}') self._finalize_test_function(test_name) return execution.logger.info(f'Test started: {test_name}') result['start_time'] = time.time() try: f = getattr(self.test_module, test_name) f(execution.data) # take screenshot_on_end if self.settings['screenshot_on_end'] and execution.browser: actions.take_screenshot('Test end') except AssertionError as e: self._add_error(message='Failure', exception=e) result['result'] = ResultsEnum.FAILURE except Exception as e: result['result'] = ResultsEnum.CODE_ERROR self._add_error(message='Error', exception=e) if result['result'] not in [ResultsEnum.CODE_ERROR, ResultsEnum.FAILURE]: if execution.errors: result['result'] = ResultsEnum.ERROR if result['result'] in [None, ResultsEnum.PENDING]: result['result'] = ResultsEnum.SUCCESS result['end_time'] = time.time() result['test_elapsed_time'] = round(result['end_time'] - result['start_time'], 2) execution.logger.info(f"Test Result: {result['result'].upper()}") self._finalize_test_function(test_name) # Run after_each hooks for after_each_hook in self.test_hooks['after_each']: # reset execution values specific to this test self._reset_execution_module_values_for_test_function(None, 'after_each') after_each_result = self.generic_run_function(after_each_hook) if after_each_result != ResultsEnum.SUCCESS: self.skip_tests = True self.generate_report_for_hook_function('after_each', after_each_result)
def assert_project_exists(project_name): actions.take_screenshot('verify the project exists in the list') assert _project_exists(project_name), 'Project {} does not exists'.format( project_name)
def test_login_blank_username(data): actions.navigate(data.env.url) actions.send_keys(login.password_input, 'admin') actions.click(login.login_button) actions.take_screenshot('Verify the correct error message is shown') actions.assert_element_text(login.error_list, 'Username is required')