Best Python code snippet using toolium_python
test_visual_test.py
Source:test_visual_test.py
...219 img = Image.open(file_v1)220 img = visual.crop_element(img, web_element)221 # Assert output image222 assert_image(visual, img, 'report_name', 'register_cropped_element_oversize')223def test_get_scrolls_size(driver_wrapper):224 # Update conf and create a new VisualTest instance225 # Mock scrollHeight, scrollWidth, innerHeight, innerWidth226 driver_wrapper.driver.execute_script.side_effect = [600, 1200, 400, 900]227 driver_wrapper.config.set('Driver', 'type', 'chrome')228 visual = VisualTest(driver_wrapper)229 # Check scrolls230 assert visual.get_scrolls_size() == {'x': 17, 'y': 17}231def test_get_scrolls_size_y(driver_wrapper):232 # Update conf and create a new VisualTest instance233 # Mock scrollHeight, scrollWidth, innerHeight, innerWidth234 driver_wrapper.driver.execute_script.side_effect = [600, 1200, 400, 1200]235 driver_wrapper.config.set('Driver', 'type', 'chrome')236 visual = VisualTest(driver_wrapper)237 # Check scrolls238 assert visual.get_scrolls_size() == {'x': 0, 'y': 17}239def test_get_scrolls_size_without_scrolls(driver_wrapper):240 # Update conf and create a new VisualTest instance241 # Mock scrollHeight, scrollWidth, innerHeight, innerWidth242 driver_wrapper.driver.execute_script.side_effect = [600, 1200, 600, 1200]243 driver_wrapper.config.set('Driver', 'type', 'chrome')244 visual = VisualTest(driver_wrapper)245 # Check scrolls246 assert visual.get_scrolls_size() == {'x': 0, 'y': 0}247def test_get_scrolls_size_iexplore(driver_wrapper):248 # Update conf and create a new VisualTest instance249 # Mock scrollHeight, scrollWidth, innerHeight, innerWidth250 driver_wrapper.driver.execute_script.side_effect = [600, 1200, 400, 900]251 driver_wrapper.config.set('Driver', 'type', 'iexplore')252 visual = VisualTest(driver_wrapper)253 # Check scrolls254 assert visual.get_scrolls_size() == {'x': 21, 'y': 21}255def test_get_scrolls_size_firefox(driver_wrapper):256 # Update conf and create a new VisualTest instance257 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 scroll...
visual_test.py
Source:visual_test.py
...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():...
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!!