self.logger.info("Asserting [%s]" % text) baselinePath = self.config.imageBaseline + "/assert/" + str(Env.getOS()).lower() + "/" + text + ".png" baseline = Pattern(baselinePath) # TODO: Refactor to allow for using RegionFinder class so PNG attributes can be used try: ImageLocator().locate( baselinePath ) result = self.region.find(baseline) self.logger.info('%%s matched %%s', self.logger.getFormatter()(result), self.logger.getFormatter()(baseline)) except FindFailed, e: self.logger.error('%%s does not match %%s', self.logger.getFormatter()(self.region), self.logger.getFormatter()(baseline)) raise Exception("Assertion failure") except FileNotFoundException, e: # Baseline doesn't exist, save a copy shutil.copy(capture(self.region), baselinePath) self.logger.error("Baseline not provided, please verify the baseline %s manually" % (baselinePath)) def findEntityByName(self, query): """ Search for child entity definitions matching a particular query. """ searcher = self.searcherStrategy() searcher.add(self.__class__) return self[searcher.search(query)['entity']] def waitUntilVanish(self, timeout=300, **resultArgs): """
def __str__(self): labelStr = "" if self.label: labelStr = '"%s"' % self.label elif isinstance(self.entity, Match): match = re.search(r"(?P<match>Match.*?\])", str(self.entity), re.IGNORECASE) if match: labelStr = '"%s"' % match.group("match") else: raise Exception("Unable to regex match on [%s]" % str(self.entity)) elif isinstance(self.entity, Screen): match = re.search(r"(?P<screen>Screen.*?\])", str(self.entity), re.IGNORECASE) if match: labelStr = '"%s"' % match.group("screen") else: raise Exception("Unable to regex match on Screen") elif isinstance(self.entity, Region): match = re.search(r"(?P<region>(Region).*?)@(?P<screen>Screen.*\])", str(self.entity), re.IGNORECASE) if match: labelStr = '"%s"' % match.group("region") else: raise Exception("Unable to regex match on [%s]" % str(self.entity)) elif isinstance(self.entity, Pattern): labelStr = '"%s"' % str(self.entity) else: labelStr = "%s" % str(self.entity) ## Create Suffix images = [] regionFinder = None region = None if not self.meetsLogThreshold(): pass # Don't log this image, doesn't meet logging threshold elif isinstance(self.entity, entity.Entity): # If entity has a valid regions if self.entity.region: region = self.entity.region # Get the enity names from regionFinder regionFinder = self.entity.getRegionFinder() elif isinstance(self.entity, FinderAbstract): region = self.entity.getLastRegionFound() regionFinder = self.entity elif isinstance(self.entity, Region): region = self.entity elif isinstance(self.entity, Pattern): match = re.search(r'Pattern\("(?P<path>.*?)"\)', str(self.entity), re.IGNORECASE) if match: imagePath = match.group("path") images.append(self.tool.saveAsset(imagePath)) else: raise Exception("Unaable to match path") # Capture images if self.meetsLogThreshold() and region: images.append(self.tool.saveAsset((capture(region))) + ":Actual") if self.meetsLogThreshold() and regionFinder and self.doShowBaselines: seriesRange = [] if self.series != None: seriesRange.append(self.series) elif regionFinder.getLastSeriesMatched() != None: seriesRange.append(regionFinder.getLastSeriesMatched()) elif regionFinder.getSeriesRange(): seriesRange = regionFinder.getSeriesRange() state = self.state if self.state else regionFinder.getState() for series in seriesRange: for image in regionFinder.getImageNames(series=series, state=state): # images.append(image + ':Baseline') # images.append(self.tools.saveAsset(image) + ":%s" % os.path.basename(image)) images.append(self.tool.saveAsset(image) + ":%s" % "series_" + str(series)) imageStr = ",".join(images) return "[%s](%s)" % (labelStr, imageStr)
def __str__(self): labelStr = "" if self.label: labelStr = '"%s"' % self.label elif isinstance(self.entity, Match): match = re.search(r"(?P<match>M\[.*?\])", str(self.entity), re.IGNORECASE) if match: labelStr = '"%s"' % match.group("match") else: raise Exception("Unable to regex match on [%s]" % str(self.entity)) elif isinstance(self.entity, Screen): match = re.search(r"(?P<screen>Screen.*?\])", str(self.entity), re.IGNORECASE) if match: labelStr = '"%s"' % match.group("screen") else: raise Exception("Unable to regex match on Screen") elif isinstance(self.entity, Region): match = re.search(r"(?P<region>R\[.*?)@(?P<screen>.*\])", str(self.entity), re.IGNORECASE) if match: labelStr = '"%s"' % match.group("region") else: raise Exception("Unable to regex match on [%s]" % str(self.entity)) elif isinstance(self.entity, Pattern): labelStr = '"%s"' % str(self.entity) else: labelStr = '%s' % str(self.entity) ## Create Suffix images = [] regionFinder = None region = None if not self.meetsLogThreshold(): pass # Don't log this image, doesn't meet logging threshold elif isinstance(self.entity, entity.Entity): # If entity has a valid regions if self.entity.region: region = self.entity.region # Get the enity names from regionFinder regionFinder = self.entity.getRegionFinder() elif isinstance(self.entity, FinderAbstract): region = self.entity.getLastRegionFound() regionFinder = self.entity elif isinstance(self.entity, Region): region = self.entity elif isinstance(self.entity, Pattern): match = re.search(r'P\((?P<path>.*?)\)', str(self.entity), re.IGNORECASE) if match: imagePath = match.group("path") images.append(self.tool.saveAsset(imagePath)) else: raise Exception("Unaable to match path: %s" % str(self.entity)) # Capture images if self.meetsLogThreshold() and region: images.append(self.tool.saveAsset((capture(region))) + ':Actual') if self.meetsLogThreshold() and regionFinder and self.doShowBaselines: seriesRange = [] if self.series != None: seriesRange.append(self.series) elif regionFinder.getLastSeriesMatched() != None: seriesRange.append(regionFinder.getLastSeriesMatched()) elif regionFinder.getSeriesRange(): seriesRange = regionFinder.getSeriesRange() state = self.state if self.state else regionFinder.getState() for series in seriesRange: for image in regionFinder.getImageNames(series=series, state=state): #images.append(image + ':Baseline') #images.append(self.tools.saveAsset(image) + ":%s" % os.path.basename(image)) images.append( self.tool.saveAsset(image) + ":%s" % 'series_' + str(series)) imageStr = ','.join(images) return '[%s](%s)' % (labelStr, imageStr)