Ejemplo n.º 1
0
    def _adb_minicap(self, scale=1.0):
        """
        capture screen with minicap

        https://github.com/openstf/minicap
        """
        remote_file = tempfile.mktemp(dir='/data/local/tmp/',
                                      prefix='minicap-',
                                      suffix='.jpg')
        local_file = tempfile.mktemp(prefix='atx-minicap-', suffix='.jpg')
        (w, h, r) = self.display
        params = '{x}x{y}@{rx}x{ry}/{r}'.format(x=w,
                                                y=h,
                                                rx=int(w * scale),
                                                ry=int(h * scale),
                                                r=r * 90)
        try:
            self.shell('LD_LIBRARY_PATH=/data/local/tmp', self.__minicap, '-s',
                       '-P', params, '>', remote_file)
            self.pull(remote_file, local_file)
            image = imutils.open_as_pillow(local_file)
            return image
        finally:
            self.remove(remote_file)
            os.unlink(local_file)
Ejemplo n.º 2
0
 def _screenshot_uiauto(self):
     tmp_file = tempfile.mktemp(prefix='atx-tmp-', suffix='.jpg')
     self._uiauto.screenshot(tmp_file)
     try:
         return imutils.open_as_pillow(tmp_file)
     except IOError:
         raise IOError("Screenshot use uiautomator failed.")
     finally:
         base.remove_force(tmp_file)
Ejemplo n.º 3
0
 def _screenshot_uiauto(self):
     tmp_file = self._mktemp()
     self._uiauto.screenshot(tmp_file)
     try:
         return imutils.open_as_pillow(tmp_file)
     except IOError:
         raise IOError("Screenshot use uiautomator failed.")
     finally:
         base.remove_force(tmp_file)
Ejemplo n.º 4
0
 def _screenshot_uiauto(self):
     tmp_file = tempfile.mktemp(prefix='atx-tmp-', suffix='.jpg')
     self._uiauto.screenshot(tmp_file)
     try:
         return imutils.open_as_pillow(tmp_file)
     except IOError:
         raise IOError("Screenshot use uiautomator failed.")
     finally:
         base.remove_force(tmp_file)
Ejemplo n.º 5
0
 def _screenshot_uiauto(self):
     tmp_file = self._mktemp()
     UiaDevice.screenshot(self, tmp_file)
     # self._uiauto.screenshot(tmp_file) # this will call Mixin.screenshot first, which may get too many loop
     try:
         return imutils.open_as_pillow(tmp_file)
     except IOError:
         raise IOError("Screenshot use uiautomator failed.")
     finally:
         base.remove_force(tmp_file)
Ejemplo n.º 6
0
    def _adb_minicap(self, scale=1.0):
        """
        capture screen with minicap

        https://github.com/openstf/minicap
        """
        remote_file = tempfile.mktemp(dir='/data/local/tmp/', prefix='minicap-', suffix='.jpg')
        local_file = tempfile.mktemp(prefix='atx-minicap-', suffix='.jpg')
        (w, h, r) = self.display
        params = '{x}x{y}@{rx}x{ry}/{r}'.format(x=w, y=h, rx=int(w*scale), ry=int(h*scale), r=r*90)
        try:
            self.shell('LD_LIBRARY_PATH=/data/local/tmp', self.__minicap, '-s', '-P', params, '>', remote_file)
            self.pull(remote_file, local_file)
            image = imutils.open_as_pillow(local_file)
            return image
        finally:
            self.remove(remote_file)
            os.unlink(local_file)
Ejemplo n.º 7
0
 def _screenshot_minicap(self):
     phone_tmp_file = '/data/local/tmp/_atx_screen-{}.jpg'.format(self._randid)
     local_tmp_file = self._mktemp()
     command = 'LD_LIBRARY_PATH=/data/local/tmp /data/local/tmp/minicap -P {} -s > {}'.format(
         self._minicap_params(), phone_tmp_file)
     try:
         self.adb_shell(command)
         self.adb_cmd(['pull', phone_tmp_file, local_tmp_file])
         image = imutils.open_as_pillow(local_tmp_file)
         # Fix rotation not rotate right.
         (width, height) = image.size
         if self.screen_rotation in [1, 3] and width < height:
             image = image.rotate(90, Image.BILINEAR, expand=True)
         return image
     except IOError:
         raise IOError("Screenshot use minicap failed.")
     finally:
         self.adb_shell(['rm', phone_tmp_file])
         base.remove_force(local_tmp_file)
Ejemplo n.º 8
0
 def _adb_screencap(self, scale=1.0):
     """
     capture screen with adb shell screencap
     """
     remote_file = tempfile.mktemp(dir='/data/local/tmp/', prefix='screencap-', suffix='.png')
     local_file = tempfile.mktemp(prefix='atx-screencap-', suffix='.png')
     self.shell('screencap', '-p', remote_file)
     try:
         self.pull(remote_file, local_file)
         image = imutils.open_as_pillow(local_file)
         if scale is not None and scale != 1.0:
             image = image.resize([int(scale * s) for s in image.size], Image.BICUBIC)
         rotation = self.rotation()
         if rotation:
             method = getattr(Image, 'ROTATE_{}'.format(rotation*90))
             image = image.transpose(method)
         return image
     finally:
         self.remove(remote_file)
         os.unlink(local_file)
Ejemplo n.º 9
0
    def _screenshot_minicap(self):
        phone_tmp_file = '/data/local/tmp/_atx_screen-{}.jpg'.format(self._randid)
        local_tmp_file = tempfile.mktemp(prefix='atx-tmp-', suffix='.jpg')
        command = 'LD_LIBRARY_PATH=/data/local/tmp /data/local/tmp/minicap -P {} -s > {}'.format(
            self._minicap_params(), phone_tmp_file)
        try:
            self.adb_shell(command)
            self.adb_cmd(['pull', phone_tmp_file, local_tmp_file])
            image = imutils.open_as_pillow(local_tmp_file)

            # Fix rotation not rotate right.
            (width, height) = image.size
            if self.screen_rotation in [1, 3] and width < height:
                image = image.rotate(90, Image.BILINEAR, expand=True)
            return image
        except IOError:
            raise IOError("Screenshot use minicap failed.")
        finally:
            # remove_force(local_tmp_file)
            self.adb_shell(['rm', phone_tmp_file])
Ejemplo n.º 10
0
 def _adb_screencap(self, scale=1.0):
     """
     capture screen with adb shell screencap
     """
     remote_file = tempfile.mktemp(dir='/data/local/tmp/',
                                   prefix='screencap-',
                                   suffix='.png')
     local_file = tempfile.mktemp(prefix='atx-screencap-', suffix='.png')
     self.shell('screencap', '-p', remote_file)
     try:
         self.pull(remote_file, local_file)
         image = imutils.open_as_pillow(local_file)
         if scale is not None and scale != 1.0:
             image = image.resize([int(scale * s) for s in image.size],
                                  Image.BICUBIC)
         rotation = self.rotation()
         if rotation:
             method = getattr(Image, 'ROTATE_{}'.format(rotation * 90))
             image = image.transpose(method)
         return image
     finally:
         self.remove(remote_file)
         os.unlink(local_file)