How to use _adb_screencap method in ATX

Best Python code snippet using ATX

device.py

Source:device.py Github

copy

Full Screen

...132 continue133 path, name = m.group(1), m.group(2)134 packages.append(self.Package(name, path))135 return packages136 def _adb_screencap(self, scale=1.0):137 """138 capture screen with adb shell screencap139 """140 remote_file = tempfile.mktemp(dir='/data/local/tmp/', prefix='screencap-', suffix='.png')141 local_file = tempfile.mktemp(prefix='atx-screencap-', suffix='.png')142 self.shell('screencap', '-p', remote_file)143 try:144 self.pull(remote_file, local_file)145 image = imutils.open_as_pillow(local_file)146 if scale is not None and scale != 1.0:147 image = image.resize([int(scale * s) for s in image.size], Image.BICUBIC)148 rotation = self.rotation()149 if rotation:150 method = getattr(Image, 'ROTATE_{}'.format(rotation*90))151 image = image.transpose(method)152 return image153 finally:154 self.remove(remote_file)155 os.unlink(local_file)156 def _adb_minicap(self, scale=1.0):157 """158 capture screen with minicap159 https://github.com/openstf/minicap160 """161 remote_file = tempfile.mktemp(dir='/data/local/tmp/', prefix='minicap-', suffix='.jpg')162 local_file = tempfile.mktemp(prefix='atx-minicap-', suffix='.jpg')163 (w, h, r) = self.display164 params = '{x}x{y}@{rx}x{ry}/{r}'.format(x=w, y=h, rx=int(w*scale), ry=int(h*scale), r=r*90)165 try:166 self.shell('LD_LIBRARY_PATH=/data/local/tmp', self.__minicap, '-s', '-P', params, '>', remote_file)167 self.pull(remote_file, local_file)168 image = imutils.open_as_pillow(local_file)169 return image170 finally:171 self.remove(remote_file)172 os.unlink(local_file)173 def screenshot(self, filename=None, scale=1.0, method=None):174 """175 Take device screenshot176 Args:177 - filename(string): optional, save int filename178 - scale(float): scale size179 - method(string): one of minicap,screencap180 Return:181 PIL.Image182 """183 image = None184 method = method or self._screenshot_method185 if method == 'minicap':186 try:187 image = self._adb_minicap(scale)188 except Exception as e:189 logger.warn("use minicap failed, fallback to screencap. error detail: %s", e)190 self._screenshot_method = 'screencap'191 return self.screenshot(filename=filename, scale=scale)192 elif method == 'screencap':193 image = self._adb_screencap(scale)194 else:195 raise RuntimeError("No such method(%s)" % method)196 if filename:197 image.save(filename)198 return image199 def click(self, x, y):200 '''201 same as adb -s ${SERIALNO} shell input tap x y202 FIXME(ssx): not tested on horizontal screen203 '''204 self.shell('input', 'tap', str(x), str(y))205 def forward(self, local_port, remote_port):206 '''207 adb port forward. return local_port...

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