def waitUntilComplete(self, timeout=60, resultArgs={}):
     
     self.validate()
     
     # Convert Match to Region -> workaround: https://bugs.launchpad.net/sikuli/+bug/905435
     r = Region(self.region)
     r.onChange(self.__changed)
     r.observe(FOREVER, background=True) # start observing progress bar
     
     startTime = time.time()
     self.lastChange = time.time()
     # loop while things are still changing        
     while (time.time()-self.lastChange) < timeout:
         sleep(1)
         
     r.stopObserver() # stop observing progress bar
     self.logger.trace("stopped changing after %ds" % (time.time()-startTime))
         
     # try and click the button            
     state = "complete"
     ir = self.regionFinder(self, region=self.region, state=state) # image region of the button                
     try:
         region = ir.find()                                    
     except FindExhaustedException, e:
         raise StateFailedException("incorrect state [%s]" % state)
Example #2
0
    def waitUntilComplete(self, timeout=60, resultArgs={}):

        self.validate()

        # Convert Match to Region -> workaround: https://bugs.launchpad.net/sikuli/+bug/905435
        r = Region(self.region)
        r.onChange(self.__changed)
        r.observe(FOREVER, background=True)  # start observing progress bar

        startTime = time.time()
        self.lastChange = time.time()
        # loop while things are still changing
        while (time.time() - self.lastChange) < timeout:
            sleep(1)

        r.stopObserver()  # stop observing progress bar
        self.logger.trace("stopped changing after %ds" %
                          (time.time() - startTime))

        # try and click the button
        state = "complete"
        ir = self.regionFinder(self, region=self.region,
                               state=state)  # image region of the button
        try:
            region = ir.find()
        except FindExhaustedException, e:
            raise StateFailedException("incorrect state [%s]" % state)
 def apply(self, operand, *args, **kargs):
     #print operand.getX() + self.x, operand.getY() + self.y
     #operand.click(operand.getX() + self.x, operand.getY() + self.y)
     #operand.click(500,500)
     operand.mouseMove(Location(operand.getX() + self.x, operand.getY() + self.y))
     operand.mouseDown(InputEvent.BUTTON1_MASK)
     sleep(0.5)
     operand.mouseUp(InputEvent.BUTTON1_MASK)
     
     return operand
Example #4
0
    def apply(self, operand, *args, **kargs):
        #print operand.getX() + self.x, operand.getY() + self.y
        #operand.click(operand.getX() + self.x, operand.getY() + self.y)
        #operand.click(500,500)
        operand.mouseMove(
            Location(operand.getX() + self.x,
                     operand.getY() + self.y))
        operand.mouseDown(InputEvent.BUTTON1_MASK)
        sleep(0.5)
        operand.mouseUp(InputEvent.BUTTON1_MASK)

        return operand
Example #5
0
    def click(self, entity, button=InputEvent.BUTTON1_MASK):

        
        # click
        self.screen.mouseMove(entity.getRegion().getClickLocation())
        sleep(0.5)        
        
        # Get the state of the button before we click
        state = self.screen.capture(entity.getRegion())
        #sleep(0.2)        
        
        self.screen.mouseDown(button)
        sleep(0.5)
        
        # Wait for button to change its appearnce because we're clicking on it
        if entity.getRegion().waitVanish(Pattern(state).similar(1.0), 0.7):                
            sleep(0.2)
        else:
            if self.assertStateChanged:
                raise Exception("State did not change")
            else:
                self.logger.warn("State did not change")
            
        self.screen.mouseUp(button)
        sleep(0.5)
Example #6
0
 def assertEquals(self, expectedText):
     
     # If we're on MAC, use CMD instead of CTRL
     if Env.getOS() == OS.MAC:
         keyMod = KeyModifier.CMD
     else:
         keyMod = KeyModifier.CTRL
     
     # Select 
     self.config.screen.type(None, "a", keyMod)
     sleep(0.5)
     
     self.config.screen.type(None, "c", keyMod)
     sleep(0.5)
     
     clipboardContents = Env.getClipboard()        
     if clipboardContents != expectedText:
         self.logger.error("Clipboard contents [%s] does not match expected value of [%s]" % (clipboardContents, expectedText))
         raise Exception()
     else:
         self.logger.trace("Verified clipboard contents [%s] equals [%s]" % (clipboardContents, expectedText))
Example #7
0
    def drag(self, destination):

        # Ensure valid
        self.validate()

        # Move the mouse to this entity
        self.config.screen.mouseMove(self.region)
        sleep(0.1)
        self.config.screen.mouseDown(InputEvent.BUTTON1_MASK)
        sleep(0.4)
        self.config.screen.mouseMove(destination)
        sleep(0.3)
        self.config.screen.mouseUp(InputEvent.BUTTON1_MASK)

        # This entity is no longer valid since it's been dragged
        self.invalidate()
 def drag(self, destination):
     
     # Ensure valid
     self.validate()
             
     # Move the mouse to this entity
     self.config.screen.mouseMove(self.region)        
     sleep(0.1) 
     self.config.screen.mouseDown(InputEvent.BUTTON1_MASK)
     sleep(0.4) 
     self.config.screen.mouseMove(destination)
     sleep(0.3)
     self.config.screen.mouseUp(InputEvent.BUTTON1_MASK)
     
     # This entity is no longer valid since it's been dragged
     self.invalidate()
Example #9
0
    def sleep(self, duration):
        """
        Pauses the script for N seconds
        """

        sleep(int(duration))
 def sleep(self, duration):
     """
     Pauses the script for N seconds
     """
             
     sleep(int(duration))
Example #11
0
 def click(self, entity, button=InputEvent.BUTTON1_MASK):
     self.screen.mouseMove(entity.getRegion().getClickLocation())
     sleep(0.1) 
     self.screen.mouseDown(button)               
     self.screen.mouseUp(button)
Example #12
0
    def type(self, text, callback=None, context=None, verify=True, **kargs):
        """ Select a element (eg. Button) """
         
        # Ensure valid
        self.validate()

        # Sometimes click isn't registered, implement our own version of click
        self.config.screen.mouseMove(self.region.getClickLocation())
        sleep(0.5)
        self.config.screen.mouseDown(InputEvent.BUTTON1_MASK)
        sleep(0.8)
        self.config.screen.mouseUp(InputEvent.BUTTON1_MASK)
        sleep(0.5)
        
        # If we're on OSX, use CMD instead of CTRL
        if Env.getOS() == OS.MAC:
            keyMod = KeyModifier.CMD
        else:
            keyMod = KeyModifier.CTRL        
            
        # Select 
        self.config.screen.type(None, "a", keyMod)
        sleep(0.5)
        self.config.screen.type(Key.BACKSPACE)
        sleep(0.5)
     
        """
        Note: Config.screen.type() or paste() behaves differently in Windows and Mac regarding clipboard
        
        In Mac: 
        Through testing, found that Config.screen.type(text), then copy the text somehow does not store the text in the clipboard.
        if we want to retrieve the text properly in Mac from clipboard later, then we have to use "Config.screen.paste(text).
        
        However, if we use paste() here, then Mac response "prompt adding title page" does not recognize that text has been pasted in the edit
        box and the "Add" button will not enabled. (In Mac, you need to actually type something in that edit box for the "Add" button 
        to be enabled. A bug is raised.
        
        In Windows:
        Both Config.screen.type()/Config.screen.paste() and copy the text STORE the text in the clipboard properly. And Response "prompt adding
        title page" recognize the pasted text in the edit box and the "Add" button is enabled properly
        """
        self.config.screen.paste(text) 
        sleep(1.0)
     
        if verify:
            self.config.screen.type(None, "a", keyMod)
            sleep(1.0)
            self.config.screen.type(None, "c", keyMod)
            sleep(1.0)
            clipboardContents = Env.getClipboard()
            clipboardContents = string.replace(clipboardContents,'\r','')
            clipboardContents = string.replace(clipboardContents,'\n','')
            
            if clipboardContents != text:
                self.logger.error("Clipboard contents [%s] does not match expected value of [%s]" % (clipboardContents, text))
                raise Exception()
            else:
                self.logger.trace("Verified clipboard contents [%s] equals [%s]" % (clipboardContents, text))

        
        self.logger.info('typed ["%s"], on %%s' % (text), self.logger.getFormatter()(self.parent))
        
        return self.parent