How to use _take_screenshot method in ATX

Best Python code snippet using ATX

platform_TabletMode.py

Source:platform_TabletMode.py Github

copy

Full Screen

...56 utils.system(self.SPOOF_CMD + self.PORTRAIT_SENSOR_0)57 time.sleep(self._SHORT_WAIT)58 utils.system(self.SPOOF_CMD + self.PORTRAIT_SENSOR_1)59 time.sleep(self._WAIT)60 def _take_screenshot(self, suffix):61 """62 Captures a screenshot of the current VT screen in BMP format.63 @param suffixcurrent_vt: desired vt for screenshot.64 @returns the path of the screenshot file.65 """66 extension = 'bmp'67 return graphics_utils.take_screenshot(self.resultsdir,68 suffix + '_tablet_mode',69 extension)70 def _verify_difference(self, screenshot1, screenshot2,71 difference_percent_threshold=5):72 """73 Make sure screenshots are sufficiently different.74 @param screenshot1: path to screenshot.75 @param screenshot2: path to screenshot.76 @param difference_percent_threshold: threshold for difference.77 @returns number of errors found (0 or 1).78 """79 filename1 = screenshot1.split('/')[-1]80 filename2 = screenshot2.split('/')[-1]81 diff = get_percent_difference(screenshot1, screenshot2)82 logging.info("Screenshot 1 and 2 diff: %s" % diff)83 if not diff >= difference_percent_threshold:84 error = ('Screenshots differ by %d %%: %s vs %s'85 % (diff, filename1, filename2))86 self.ERRORS.append(error)87 def _verify_similarity(self, screenshot1, screenshot2,88 similarity_percent_threshold=5):89 """90 Make sure screenshots are the same or similar.91 @param screenshot1: path to screenshot.92 @param screenshot2: path to screenshot.93 @param difference_percent_threshold: threshold for similarity.94 @returns number of errors found (0 or 1).95 """96 filename1 = screenshot1.split('/')[-1]97 filename2 = screenshot2.split('/')[-1]98 diff = get_percent_difference(screenshot1, screenshot2)99 logging.info("Screenshot 1 and 2 similarity diff: %s" % diff)100 if not diff <= similarity_percent_threshold:101 error = ('Screenshots differ by %d %%: %s vs %s'102 % (diff, filename1, filename2))103 self.ERRORS.append(error)104 def run_once(self):105 """106 Run tablet mode test to spoof various tablet modes and ensure107 device changes accordingly.108 """109 # Ensure we start in laptop mode.110 self._revert_laptop()111 logging.info("Take screenshot for initial laptop mode.")112 laptop_start = self._take_screenshot('laptop_start')113 logging.info("Entering landscape mode.")114 self._spoof_tablet_landscape()115 landscape = self._take_screenshot('landscape')116 self._revert_laptop()117 logging.info("Entering portrait mode.")118 self._spoof_tablet_portrait()119 portrait = self._take_screenshot('portrait')120 self._revert_laptop()121 laptop_end = self._take_screenshot('laptop_end')122 # Compare screenshots and determine the number of errors.123 self._verify_similarity(laptop_start, laptop_end)124 self._verify_difference(laptop_start, landscape)125 self._verify_difference(landscape, portrait)126 self._verify_difference(portrait, laptop_end)127 if self.ERRORS:128 raise error.TestFail('; '.join(set(self.ERRORS)))129 def cleanup(self):...

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