How to use mobile_resize method in toolium

Best Python code snippet using toolium_python

test_visual_test.py

Source:test_visual_test.py Github

copy

Full Screen

...275 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 instance291 driver_wrapper.config.set('Driver', 'type', 'ios')292 driver_wrapper.utils.get_window_size.return_value = {'width': 750, 'height': 1334}293 visual = VisualTest(driver_wrapper)294 # Resize image295 orig_img = Image.open(file_ios)296 img = visual.mobile_resize(orig_img)297 # Assert that image object has not been modified298 assert orig_img == img299def test_desktop_resize(driver_wrapper):300 # Update conf and create a new VisualTest instance301 driver_wrapper.is_mac_test = mock.MagicMock(return_value=True)302 driver_wrapper.utils.get_window_size.return_value = {'width': 1280, 'height': 1024}303 visual = VisualTest(driver_wrapper)304 # Resize image305 img = Image.open(file_mac)306 img = visual.desktop_resize(img)307 # Assert output image308 assert_image(visual, img, 'report_name', 'mac_os_retina_resized')309def test_desktop_no_resize(driver_wrapper):310 # Update conf and create a new VisualTest instance311 driver_wrapper.is_mac_test = mock.MagicMock(return_value=True)312 driver_wrapper.utils.get_window_size.return_value = {'width': 3840, 'height': 2102}313 visual = VisualTest(driver_wrapper)314 # Resize image315 orig_img = Image.open(file_ios)316 img = visual.mobile_resize(orig_img)317 # Assert that image object has not been modified318 assert orig_img == img319def test_exclude_elements(driver_wrapper):320 # Create elements mock321 driver_wrapper.driver.execute_script.return_value = 0 # scrollX=0 and scrollY=0322 visual = VisualTest(driver_wrapper)323 web_elements = [get_mock_element(x=250, y=40, height=40, width=300),324 get_mock_element(x=250, y=90, height=20, width=100)]325 img = Image.open(file_v1) # Exclude elements326 img = visual.exclude_elements(img, web_elements)327 # Assert output image328 assert_image(visual, img, 'report_name', 'register_exclude')329def test_exclude_element_outofimage(driver_wrapper):330 # Create elements mock...

Full Screen

Full Screen

visual_test.py

Source:visual_test.py Github

copy

Full Screen

...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):152 if not self.driver_wrapper.is_mobile_test():153 scroll_x = self.driver_wrapper.driver.execute_script("return window.pageXOffset")154 scroll_x = scroll_x if scroll_x else 0155 scroll_y = self.driver_wrapper.driver.execute_script("return window.pageYOffset")156 scroll_y = scroll_y if scroll_y else 0157 offset_x = -scroll_x158 offset_y = -scroll_y...

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 toolium 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