예제 #1
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))
예제 #2
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