Example #1
0
class TestInteract(unittest.TestCase):

    def setUp(self):
        self.emu = Emulate()

    def testSleep(self):
        beforesec = int(time.time())
        self.emu.sleepseconds(1)
        aftersec = int(time.time())
        took = aftersec - beforesec
        self.assertTrue((took >= 1) and (took < 5))

    def testUsleep(self):
        beforesec = int(time.time())
        self.emu.sleep(1000)
        aftersec = int(time.time())
        took = aftersec - beforesec
        self.assertTrue((took >= 1) and (took < 5))

    def testSleepseconds(self):
        beforesec = int(time.time())
        self.emu.sleepseconds(1)
        aftersec = int(time.time())
        took = aftersec - beforesec
        self.assertTrue((took >= 1) and (took < 5))

    def testShortwait(self):
        beforetime = time.time()
        self.emu.shortwait()
        aftertime = time.time()
        took = aftertime - beforetime
        self.assertTrue((took >= 0.2) and (took < 1))

    def testLongwait(self):
        beforesec = int(time.time())
        self.emu.longwait()
        aftersec = int(time.time())
        took = aftersec - beforesec
        self.assertTrue((took >= 1) and (took < 5))
Example #2
0
class Automation:
    """An automation (Automation) consists of a way to send keypresses (Emulate) and a way to read the screen (Screen)"""

    def __init__(self, settings):
        self.emu = Emulate(settings.guidelay)
        self.screen = Screen()

    def startapp(self, command):
        """Starts an application by pressing Alt+F2, clicking in the center of the screen and typing in a command."""
        e = self.emu
        e.alt("F2")
        e.shortwait()
        e.clickat(self.screen.center)
        e.shortwait()
        e.type(command + "\n")
        e.longwait()

    def alttab(self):
        """Presses Alt+Tab"""
        e = self.emu
        e.alt("Tab")
        e.shortwait()

    def say(self, text):
        """Types in text, followed by Return"""
        self.emu.type(text + "\n")
        self.emu.shortwait()

    def close(self):
        """Stops the key/mouse emulation"""
        self.emu.close()

    def getemu(self):
        """Returns the Emulation object for sending keys and mouseclicks"""
        return self.emu

    def getscreen(self):
        """Returns the Screen object for aquiring and interpreting graphics"""
        return self.screen
Example #3
0
 def setUp(self):
     self.emu = Emulate()
Example #4
0
 def __init__(self, settings):
     self.emu = Emulate(settings.guidelay)
     self.screen = Screen()