def screenshot(self, screenshot_location=""): '''take a screen shot for this element ''' if not os.path.isdir(screenshot_location): screenshot_location = self.screenshot_location self.start() filename = self.name + "_" + str(time.time()) + ".bmp" absfile = os.path.join(screenshot_location, filename) if os.path.isfile(absfile): os.remove(absfile) self.UIElement.screenshot(absfile) LOGGER.info("Screenshot taken: %s", absfile) return absfile
def _wait_stop(self): '''wait until UIElement is not valid or timeout ''' LOGGER.info("Waiting Element to stop, timeout %s" % self.timeout) if not self.identifier is None: #keep verify the element, until not found or timeout start_time = time.time() while True: self.UIElement = self.verify() if self.UIElement is None: return time.sleep(0.1) current_time = time.time() if current_time - start_time > self.timeout: raise TimeOutError( "time out encounter, during stop element:%s" % self.name)
def _wait_start(self): '''wait until UIElement is valid or timeout ''' #keep finding the element by identifier, until found or timeout LOGGER.info("Waiting Element show up, timeout %s", self.timeout) start_time = time.time() while True: current_time = time.time() self.UIElement = self.verify() if not self.UIElement is None: LOGGER.info("Find element: %s after waiting %ss, continue", self.name, current_time - start_time) #do a desktop screenshot here as required if self.screenshot_on: #get root element = self parent = element.parent while not parent is None: element = parent parent = element.parent #screenshot element.screenshot() return time.sleep(0.1) if current_time - start_time > self.timeout: #do a desktop screenshot here as required if not self.screenshot_off: #get root element = self parent = element.parent while not parent is None: element = parent parent = element.parent #screenshot element.screenshot() raise TimeOutError( "time out encounter, during start element:%s" % self.name)
def start(self): '''start and find this UIElement ''' #need to start parent element first self.parent.start() if self.verify() is None: LOGGER.info( "Start function triggered, due to cannot find element: %s", self.name) #run start func if self.start_func: self.start_func.run() else: LOGGER.info("Element doesn't have start function") self._wait_start() else: LOGGER.info("Find element: %s, continue", self.name)
def stop(self): '''stop and verify this UIElement Need to stop all children first ''' if not self.verify() is None: #stop all children for name in self.children: self.children[name].stop() #stop self #only stop and check element which has stop_func attribute LOGGER.info("Find element %s, trigger stop function", self.name) if self.stop_func: self.stop_func.run() else: LOGGER.info("Element doesn't have stop function") self._wait_stop() else: LOGGER.info("Not find element %s, continue", self.name)