How to use __add_pytest_html_extra method in SeleniumBase

Best Python code snippet using SeleniumBase

base_case.py

Source:base_case.py Github

copy

Full Screen

...4107 data_payload.message = tb_string.split("Error: ")[-1]4108 else:4109 data_payload.message = "Unknown Error: See Stacktrace"4110 self.testcase_manager.update_testcase_data(data_payload)4111 def __add_pytest_html_extra(self):4112 if not self.__added_pytest_html_extra:4113 try:4114 if self.with_selenium:4115 if not self.__last_page_screenshot:4116 self.__set_last_page_screenshot()4117 if self.report_on:4118 extra_url = {}4119 extra_url['name'] = 'URL'4120 extra_url['format'] = 'url'4121 extra_url['content'] = self.get_current_url()4122 extra_url['mime_type'] = None4123 extra_url['extension'] = None4124 extra_image = {}4125 extra_image['name'] = 'Screenshot'4126 extra_image['format'] = 'image'4127 extra_image['content'] = self.__last_page_screenshot4128 extra_image['mime_type'] = 'image/png'4129 extra_image['extension'] = 'png'4130 self.__added_pytest_html_extra = True4131 self._html_report_extra.append(extra_url)4132 self._html_report_extra.append(extra_image)4133 except Exception:4134 pass4135 def __quit_all_drivers(self):4136 if self._reuse_session and sb_config.shared_driver:4137 if len(self._drivers_list) > 0:4138 sb_config.shared_driver = self._drivers_list[0]4139 self._default_driver = self._drivers_list[0]4140 self.switch_to_default_driver()4141 if len(self._drivers_list) > 1:4142 self._drivers_list = self._drivers_list[1:]4143 else:4144 self._drivers_list = []4145 # Close all open browser windows4146 self._drivers_list.reverse() # Last In, First Out4147 for driver in self._drivers_list:4148 try:4149 driver.quit()4150 except AttributeError:4151 pass4152 except Exception:4153 pass4154 self.driver = None4155 self._default_driver = None4156 self._drivers_list = []4157 def __has_exception(self):4158 has_exception = False4159 if sys.version_info[0] >= 3 and hasattr(self, '_outcome'):4160 if hasattr(self._outcome, 'errors') and self._outcome.errors:4161 has_exception = True4162 else:4163 has_exception = sys.exc_info()[1] is not None4164 return has_exception4165 def __get_test_id(self):4166 test_id = "%s.%s.%s" % (self.__class__.__module__,4167 self.__class__.__name__,4168 self._testMethodName)4169 return test_id4170 def __create_log_path_as_needed(self, test_logpath):4171 if not os.path.exists(test_logpath):4172 try:4173 os.makedirs(test_logpath)4174 except Exception:4175 pass # Only reachable during multi-threaded runs4176 def save_teardown_screenshot(self):4177 """ (Should ONLY be used at the start of custom tearDown() methods.)4178 This method takes a screenshot of the current web page for a4179 failing test (or when running your tests with --save-screenshot).4180 That way your tearDown() method can navigate away from the last4181 page where the test failed, and still get the correct screenshot4182 before performing tearDown() steps on other pages. If this method4183 is not included in your custom tearDown() method, a screenshot4184 will still be taken after the last step of your tearDown(), where4185 you should be calling "super(SubClassOfBaseCase, self).tearDown()"4186 """4187 if self.__has_exception() or self.save_screenshot_after_test:4188 test_id = self.__get_test_id()4189 test_logpath = self.log_path + "/" + test_id4190 self.__create_log_path_as_needed(test_logpath)4191 self.__set_last_page_screenshot()4192 if self.is_pytest:4193 self.__add_pytest_html_extra()4194 def tearDown(self):4195 """4196 Be careful if a subclass of BaseCase overrides setUp()4197 You'll need to add the following line to the subclass's tearDown():4198 super(SubClassOfBaseCase, self).tearDown()4199 """4200 self.__slow_mode_pause_if_active()4201 has_exception = self.__has_exception()4202 if self.__delayed_assert_failures:4203 print(4204 "\nWhen using self.delayed_assert_*() methods in your tests, "4205 "remember to call self.process_delayed_asserts() afterwards. "4206 "Now calling in tearDown()...\nFailures Detected:")4207 if not has_exception:4208 self.process_delayed_asserts()4209 else:4210 self.process_delayed_asserts(print_only=True)4211 if self.is_pytest:4212 # pytest-specific code4213 test_id = self.__get_test_id()4214 try:4215 with_selenium = self.with_selenium4216 except Exception:4217 sub_class_name = str(4218 self.__class__.__bases__[0]).split('.')[-1].split("'")[0]4219 sub_file_name = str(self.__class__.__bases__[0]).split('.')[-2]4220 sub_file_name = sub_file_name + ".py"4221 class_name = str(self.__class__).split('.')[-1].split("'")[0]4222 file_name = str(self.__class__).split('.')[-2] + ".py"4223 class_name_used = sub_class_name4224 file_name_used = sub_file_name4225 if sub_class_name == "BaseCase":4226 class_name_used = class_name4227 file_name_used = file_name4228 fix_setup = "super(%s, self).setUp()" % class_name_used4229 fix_teardown = "super(%s, self).tearDown()" % class_name_used4230 message = ("You're overriding SeleniumBase's BaseCase setUp() "4231 "method with your own setUp() method, which breaks "4232 "SeleniumBase. You can fix this by going to your "4233 "%s class located in your %s file and adding the "4234 "following line of code AT THE BEGINNING of your "4235 "setUp() method:\n%s\n\nAlso make sure "4236 "you have added the following line of code AT THE "4237 "END of your tearDown() method:\n%s\n"4238 % (class_name_used, file_name_used,4239 fix_setup, fix_teardown))4240 raise Exception(message)4241 if with_selenium:4242 # Save a screenshot if logging is on when an exception occurs4243 if has_exception:4244 self.__add_pytest_html_extra()4245 if self.with_testing_base and not has_exception and (4246 self.save_screenshot_after_test):4247 test_logpath = self.log_path + "/" + test_id4248 self.__create_log_path_as_needed(test_logpath)4249 if not self.__last_page_screenshot_png:4250 self.__set_last_page_screenshot()4251 log_helper.log_screenshot(4252 test_logpath,4253 self.driver,4254 self.__last_page_screenshot_png)4255 self.__add_pytest_html_extra()4256 if self.with_testing_base and has_exception:4257 test_logpath = self.log_path + "/" + test_id4258 self.__create_log_path_as_needed(test_logpath)4259 if ((not self.with_screen_shots) and (4260 not self.with_basic_test_info) and (4261 not self.with_page_source)):4262 # Log everything if nothing specified (if testing_base)4263 if not self.__last_page_screenshot_png:4264 self.__set_last_page_screenshot()4265 log_helper.log_screenshot(4266 test_logpath,4267 self.driver,4268 self.__last_page_screenshot_png)4269 log_helper.log_test_failure_data(...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run SeleniumBase automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful