Best Python code snippet using toolium_python
test_visual_test.py
Source:test_visual_test.py
...257 driver_wrapper.config.set('Driver', 'type', 'firefox')258 visual = VisualTest(driver_wrapper)259 # Check scrolls260 assert visual.get_scrolls_size() == {'x': 0, 'y': 0}261def test_remove_scrolls(driver_wrapper):262 # Create a new VisualTest instance263 visual = VisualTest(driver_wrapper)264 visual.get_scrolls_size = lambda: {'x': 0, 'y': 17}265 # Remove scroll266 img = Image.open(file_scroll)267 img = visual.remove_scrolls(img)268 # Assert output image269 assert_image(visual, img, 'report_name', 'register_chrome_scroll_removed')270def test_remove_scrolls_without_scroll(driver_wrapper):271 # Create a new VisualTest instance272 visual = VisualTest(driver_wrapper)273 visual.get_scrolls_size = lambda: {'x': 0, 'y': 0}274 # Remove scroll275 img = Image.open(file_scroll)276 img = visual.remove_scrolls(img)277 # Assert output image278 assert_image(visual, img, 'report_name', 'register_chrome_scroll')279def test_mobile_resize(driver_wrapper):280 # Update conf and create a new VisualTest instance281 driver_wrapper.config.set('Driver', 'type', 'ios')282 driver_wrapper.utils.get_window_size.return_value = {'width': 375, 'height': 667}283 visual = VisualTest(driver_wrapper)284 # Resize image285 img = Image.open(file_ios)286 img = visual.mobile_resize(img)287 # Assert output image288 assert_image(visual, img, 'report_name', 'ios_resized')289def test_mobile_no_resize(driver_wrapper):290 # Update conf and create a new VisualTest instance...
visual_test.py
Source:visual_test.py
...104 output_file = os.path.join(self.output_directory, unique_name)105 report_name = '{}<br>({})'.format(file_suffix, filename) if file_suffix else '-<br>({})'.format(filename)106 # Get screenshot and modify it107 img = Image.open(BytesIO(self.driver_wrapper.driver.get_screenshot_as_png()))108 img = self.remove_scrolls(img)109 img = self.mobile_resize(img)110 img = self.exclude_elements(img, exclude_web_elements)111 img = self.crop_element(img, web_element)112 img.save(output_file)113 DriverManager.visual_number += 1114 # Determine whether we should save the baseline image115 if self.save_baseline or not os.path.exists(baseline_file):116 # Copy screenshot to baseline117 shutil.copyfile(output_file, baseline_file)118 if self.driver_wrapper.config.getboolean_optional('VisualTests', 'complete_report'):119 self._add_result_to_report('baseline', report_name, output_file, None, 'Screenshot added to baseline')120 self.logger.debug("Visual screenshot '%s' saved in visualtests/baseline folder", filename)121 else:122 # Compare the screenshots123 self.compare_files(report_name, output_file, baseline_file, threshold)124 def get_scrolls_size(self):125 scroll_x = 0126 scroll_y = 0127 if (self.driver_wrapper.config.get('Driver', 'type').split('-')[0] in ['chrome', 'iexplore'] and128 not self.driver_wrapper.is_mobile_test()):129 scroll_height = self.driver_wrapper.driver.execute_script("return document.body.scrollHeight")130 scroll_width = self.driver_wrapper.driver.execute_script("return document.body.scrollWidth")131 window_height = self.driver_wrapper.driver.execute_script("return window.innerHeight")132 window_width = self.driver_wrapper.driver.execute_script("return window.innerWidth")133 scroll_size = 21 if self.driver_wrapper.config.get('Driver', 'type').split('-')[0] == 'iexplore' else 17134 scroll_x = scroll_size if scroll_width > window_width else 0135 scroll_y = scroll_size if scroll_height > window_height else 0136 return {'x': scroll_x, 'y': scroll_y}137 def remove_scrolls(self, img):138 scrolls_size = self.get_scrolls_size()139 if scrolls_size['x'] > 0 or scrolls_size['y'] > 0:140 new_image_width = img.size[0] - scrolls_size['y']141 new_image_height = img.size[1] - scrolls_size['x']142 img = img.crop((0, 0, new_image_width, new_image_height))143 return img144 def mobile_resize(self, img):145 if self.driver_wrapper.is_ios_test() or self.driver_wrapper.is_android_web_test():146 scale = img.size[0] / self.utils.get_window_size()['width']147 if scale != 1:148 new_image_size = (int(img.size[0] / scale), int(img.size[1] / scale))149 img = img.resize(new_image_size, Image.ANTIALIAS)150 return img151 def get_element_box(self, web_element):...
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!!