def find(self, imagename, interval=2, timeout=4, threshold=0.01): ''' if the expected image found on current screen return true else return false ''' expect_image_path = None current_image_path = None if os.path.isabs(imagename): expect_image_path = imagename current_image_path = join(self.report_dir_path, os.path.basenme(imagename)) else: expect_image_path = join(self.right_dir_path, imagename) current_image_path = join(self.report_dir_path, imagename) assert os.path.exists(expect_image_path), 'the local expected image %s not found!' % expect_image_path begin = time.time() isExists = False while (time.time() - begin < timeout): time.sleep(interval) self.d.screenshot(current_image_path) isExists = isMatch(expect_image_path , current_image_path , threshold) if not isExists: time.sleep(interval) continue return isExists
def find(self, imagename, interval=2, timeout=4, threshold=0.01): ''' if the expected image found on current screen return true else return false ''' expect_image_path = None current_image_path = None if os.path.isabs(imagename): expect_image_path = imagename current_image_path = join(self.report_dir_path, os.path.basename(imagename)) else: expect_image_path = join(self.right_dir_path, imagename) current_image_path = join(self.report_dir_path, imagename) assert os.path.exists( expect_image_path ), 'the local expected image %s not found!' % expect_image_path begin = time.time() isExists = False while (time.time() - begin < timeout): time.sleep(interval) self.d.screenshot(current_image_path) isExists = isMatch(expect_image_path, current_image_path, threshold) if not isExists: time.sleep(interval) continue return isExists
def expect(self, imagename, interval=2, timeout=4, threshold=0.01, msg=''): ''' if the expected image found on current screen return self else raise exception. set test to be failure. ''' expect_image_path = None current_image_path = None if os.path.isabs(imagename): expect_image_path = imagename current_image_path = join(self.report_dir_path, os.path.basename(imagename)) else: expect_image_path = join(self.right_dir_path, imagename) current_image_path = join(self.report_dir_path, imagename) assert os.path.exists( expect_image_path ), 'the local expected image %s not found!' % expect_image_path begin = time.time() while (time.time() - begin < timeout): self.d.screenshot(current_image_path) if isMatch(expect_image_path, current_image_path, threshold): return self time.sleep(interval) reason = msg if msg else 'Fail Reason: Image \'%s\' not found on screen!' % imagename raise ExpectException(expect_image_path, current_image_path, reason)
def expect(self, imagename, interval=2, timeout=4, threshold=0.01, msg=''): ''' if the expected image found on current screen return self else raise exception. set test to be failure. @type imagename: sting @param imagename: the name of picture which expected to find in current screenshot. @type interval: int @param iinterval: the value of interval time @type timeout: int @param timeout: the value of timeout @type threshold: float @param threshold: the value of threshold. 0.0~1.0 @type msg: string @param msg: the prompt message content when the expected image not found on current screenshot ''' expect_image_path = None current_image_path = None if os.path.isabs(imagename): expect_image_path = imagename current_image_path = join(self.report_dir_path, os.path.basenme(imagename)) else: expect_image_path = join(self.right_dir_path, imagename) current_image_path = join(self.report_dir_path, imagename) assert os.path.exists(expect_image_path), 'the local expected image %s not found!' % expect_image_path begin = time.time() while (time.time() - begin < timeout): self.d.screenshot(current_image_path) if isMatch(expect_image_path , current_image_path , threshold): return self time.sleep(interval) reason = msg if msg else 'Fail Reason: Image \'%s\' not found on screen!' % imagename raise ExpectException(expect_image_path, current_image_path, reason)
def expect(self, imagename, interval=2, timeout=4, threshold=0.01, msg=''): ''' if the expected image found on current screen return self else raise exception. set test to be failure. ''' expect_image_path = join(self.right_dir_path, imagename) assert os.path.exists(expect_image_path), 'the local expected image %s not found!' % imagename current_image_path = join(self.report_dir_path, imagename) begin = time.time() while (time.time() - begin < timeout): self.d.screenshot(current_image_path) if isMatch(expect_image_path , current_image_path , threshold): return self time.sleep(interval) reason = msg if msg else 'Fail Reason: Image \'%s\' not found on screen!' % imagename raise ExpectException(expect_image_path, current_image_path, reason)
def find(self, imagename, interval=2, timeout=4, threshold=0.01): ''' if the expected image found on current screen return true else return false @type imagename: sting @param imagename: the name of picture which expected to find in current screenshot. @type interval: int @param iinterval: the value of interval time @type timeout: int @param timeout: the value of timeout @type threshold: float @param threshold: the value of threshold. 0.0~1.0 @type msg: string @param msg: the prompt message content when the expected image not found on current screenshot @rtype: boolean @return: return True f the expected image found exists on current screenshot, else return false. ''' expect_image_path = None current_image_path = None if os.path.isabs(imagename): expect_image_path = imagename current_image_path = join(self.report_dir_path, os.path.basename(imagename)) else: expect_image_path = join(self.right_dir_path, imagename) current_image_path = join(self.report_dir_path, imagename) assert os.path.exists( expect_image_path ), 'the local expected image %s not found!' % expect_image_path begin = time.time() isExists = False while (time.time() - begin < timeout): #time.sleep(interval) self.d.screenshot(current_image_path) isExists = isMatch(expect_image_path, current_image_path, threshold) if not isExists: time.sleep(interval) continue break return isExists
def find(self, imagename, interval=2, timeout=4, threshold=0.01): ''' if the expected image found on current screen return true else return false @type imagename: sting @param imagename: the name of picture which expected to find in current screenshot. @type interval: int @param iinterval: the value of interval time @type timeout: int @param timeout: the value of timeout @type threshold: float @param threshold: the value of threshold. 0.0~1.0 @type msg: string @param msg: the prompt message content when the expected image not found on current screenshot @rtype: boolean @return: return True f the expected image found exists on current screenshot, else return false. ''' expect_image_path = None current_image_path = None if os.path.isabs(imagename): expect_image_path = imagename current_image_path = join(self.report_dir_path, os.path.basenme(imagename)) else: expect_image_path = join(self.right_dir_path, imagename) current_image_path = join(self.report_dir_path, imagename) assert os.path.exists(expect_image_path), 'the local expected image %s not found!' % expect_image_path begin = time.time() isExists = False while (time.time() - begin < timeout): time.sleep(interval) self.d.screenshot(current_image_path) isExists = isMatch(expect_image_path , current_image_path , threshold) if not isExists: time.sleep(interval) continue return isExists
def expect(self, imagename, interval=2, timeout=4, threshold=0.01, msg=''): ''' if the expected image found on current screen return self else raise exception. set test to be failure. @type imagename: sting @param imagename: the name of picture which expected to find in current screenshot. @type interval: int @param iinterval: the value of interval time @type timeout: int @param timeout: the value of timeout @type threshold: float @param threshold: the value of threshold. 0.0~1.0 @type msg: string @param msg: the prompt message content when the expected image not found on current screenshot ''' expect_image_path = None current_image_path = None if os.path.isabs(imagename): expect_image_path = imagename current_image_path = join(self.report_dir_path, os.path.basename(imagename)) else: expect_image_path = join(self.right_dir_path, imagename) current_image_path = join(self.report_dir_path, imagename) assert os.path.exists( expect_image_path ), 'the local expected image %s not found!' % expect_image_path begin = time.time() while (time.time() - begin < timeout): self.d.screenshot(current_image_path) if isMatch(expect_image_path, current_image_path, threshold): return self time.sleep(interval) reason = msg if msg else 'Fail Reason: Image \'%s\' not found on screen!' % imagename raise ExpectException(expect_image_path, current_image_path, reason)