def get_screen(self, path, log_level=logging.INFO): """ Save screen of mobile device. :param path: Path to image that will be saved. :param log_level: Log level. """ # Ensure folder to save the screen exists File.delete(path) Folder.create(folder=os.path.dirname(path)) if self.type is DeviceType.EMU or self.type is DeviceType.ANDROID: Adb.get_screen(device_id=self.id, file_path=path) if self.type is DeviceType.SIM: Simctl.get_screen(sim_id=self.id, file_path=path) if self.type is DeviceType.IOS: IDevice.get_screen(device_id=self.id, file_path=path) image_saved = False if File.exists(path): size = os.path.getsize(path) if size > 10: image_saved = True if image_saved: message = "Image of {0} saved at {1}".format(self.id, path) Log.log(level=log_level, msg=message) else: message = "Failed to save image of {0} saved at {1}".format( self.id, path) Log.error(message) raise Exception(message)
def test_02_adb_get_screen(self): path = os.path.join(Settings.TEST_OUT_TEMP, 'temp.png') File.delete(path) Adb.get_screen(device_id=self.emu.id, file_path=path)