def test_getters(self): if sys.platform.startswith("win"): app = lackey.App("notepad.exe tests\\test_cases.py") app2 = lackey.App("notepad.exe tests\\test_cases.py") #app.setUsing("test_cases.py") app.open() app2.open() lackey.sleep(1) app2.close() else: raise NotImplementedError("Platforms supported include: Windows") app.focus() self.assertEqual(app.getName(), "notepad.exe") self.assertTrue(app.isRunning()) self.assertEqual(app.getWindow(), "test_cases.py - Notepad") self.assertNotEqual(app.getPID(), -1) region = app.window() self.assertIsInstance(region, lackey.Region) self.assertGreater(region.getW(), 0) self.assertGreater(region.getH(), 0) if sys.platform.startswith("win"): app.close() lackey.sleep(1.0)
def test_launchers(self): if sys.platform.startswith("win"): app = lackey.App("notepad.exe") app.setUsing("tests\\test_cases.py") app.open() lackey.wait(1) self.assertEqual(app.getName(), "notepad.exe") self.assertTrue(app.isRunning()) self.assertRegex(app.getWindow(), "test_cases(.py)? - Notepad") self.assertNotEqual(app.getPID(), -1) app.close() lackey.wait(0.9) elif sys.platform.startswith("darwin"): if "TRAVIS" in os.environ: return # Skip these tests in travis build environment a = lackey.App("open") a.setUsing("-a TextEdit tests/test_cases.py") a.open() lackey.wait(1) app = lackey.App("test_cases.py") self.assertTrue(app.isRunning()) self.assertEqual(app.getName()[-len("TextEdit"):], "TextEdit") #self.assertEqual(app.getWindow(), "test_cases.py") # Doesn't work on `open`-triggered apps self.assertNotEqual(app.getPID(), -1) app.close() lackey.wait(0.9) else: raise NotImplementedError( "Platforms supported include: Windows, OS X")
def testTypeCopyPaste(self): """ Also tests the log file """ lackey.Debug.setLogFile("logfile.txt") r = lackey.Screen(0) if sys.platform.startswith("win"): app = lackey.App("notepad.exe").open() time.sleep(1) r.type("This is a Test") r.type("a", lackey.Key.CTRL) # Select all r.type("c", lackey.Key.CTRL) # Copy self.assertEqual(r.getClipboard(), "This is a Test") r.type("{DELETE}") # Clear the selected text r.paste( "This, on the other hand, is a {SHIFT}broken {SHIFT}record." ) # Paste should ignore special characters and insert the string as is r.type("a", lackey.Key.CTRL) # Select all r.type("c", lackey.Key.CTRL) # Copy self.assertEqual( r.getClipboard(), "This, on the other hand, is a {SHIFT}broken {SHIFT}record.") elif sys.platform == "darwin": app = lackey.App("+open -e") lackey.sleep(2) #r.debugPreview() r.wait(lackey.Pattern("preview_open_2.png")) r.click(lackey.Pattern("preview_open_2.png")) lackey.type("n", lackey.KeyModifier.CMD) time.sleep(1) app = lackey.App("Untitled") r.type("This is a test") r.type("a", lackey.KeyModifier.CMD) # Select all r.type("c", lackey.KeyModifier.CMD) # Copy self.assertEqual(r.getClipboard(), "This is a test") r.type("{DELETE}") # Clear the selected text r.paste( "This, on the other hand, is a {SHIFT}broken {SHIFT}record." ) # Paste should ignore special characters and insert the string as is r.type("a", lackey.KeyModifier.CMD) # Select all r.type("c", lackey.KeyModifier.CMD) # Copy self.assertEqual( r.getClipboard(), "This, on the other hand, is a {SHIFT}broken {SHIFT}record.") else: raise NotImplementedError( "Platforms supported include: Windows, OS X") app.close() lackey.Debug.setLogFile(None) self.assertTrue(os.path.exists("logfile.txt"))
def try_attach_game(): app = lackey.App("Space Is Hungry") if app.isValid(): app.focus() return app else: return None
def testTypeCopyPaste(self): if sys.platform.startswith("win"): app = lackey.App("notepad.exe").open() time.sleep(1) else: raise NotImplementedError("Platforms supported include: Windows") r = app.window() r.type( "This is a Test" ) # Type should translate "+" into shift modifier for capital first letters r.type("a", lackey.Key.CONTROL) # Select all r.type("c", lackey.Key.CONTROL) # Copy self.assertEqual(r.getClipboard(), "This is a Test") r.type("{DELETE}") # Clear the selected text r.paste( "This, on the other hand, is a {SHIFT}broken {SHIFT}record." ) # Paste should ignore special characters and insert the string as is r.type("a", lackey.Key.CONTROL) # Select all r.type("c", lackey.Key.CONTROL) # Copy self.assertEqual( r.getClipboard(), "This, on the other hand, is a {SHIFT}broken {SHIFT}record.") if sys.platform.startswith("win"): app.close()
def testTypeCopyPaste(self): """ Also tests the log file """ lackey.Debug.setLogFile("logfile.txt") if sys.platform.startswith("win"): app = lackey.App("notepad.exe").open() time.sleep(1) else: raise NotImplementedError("Platforms supported include: Windows") r = app.window() r.type("This is a Test") r.type("a", lackey.Key.CONTROL) # Select all r.type("c", lackey.Key.CONTROL) # Copy self.assertEqual(r.getClipboard(), "This is a Test") r.type("{DELETE}") # Clear the selected text r.paste( "This, on the other hand, is a {SHIFT}broken {SHIFT}record." ) # Paste should ignore special characters and insert the string as is r.type("a", lackey.Key.CONTROL) # Select all r.type("c", lackey.Key.CONTROL) # Copy self.assertEqual( r.getClipboard(), "This, on the other hand, is a {SHIFT}broken {SHIFT}record.") if sys.platform.startswith("win"): app.close() lackey.Debug.setLogFile(None) self.assertTrue(os.path.exists("logfile.txt"))
def setUp(self): if sys.platform.startswith("win"): self.app = lackey.App("notepad.exe") self.app.setUsing("test_cases.py") self.app.open() time.sleep(1) else: raise NotImplementedError("Platforms supported include: Windows") self.app.focus()
def test_launchers(self): app = lackey.App("notepad.exe") app.setUsing("tests\\test_cases.py") app.open() time.sleep(1) self.assertEqual(app.getName(), "notepad.exe") self.assertTrue(app.isRunning()) self.assertEqual(app.getWindow(), "test_cases.py - Notepad") self.assertNotEqual(app.getPID(), -1) app.close() time.sleep(1)
def start_game(): app = lackey.App("Bejeweled").focus() r = app.window() if not r.exists(lackey.Pattern("hint_button.png"), 0.5): if not r.exists(lackey.Pattern("zen_mode.png"), 0.5): r.wait(lackey.Pattern("play_button.png")) r.click() r.wait(lackey.Pattern("zen_mode.png")) r.click() r.wait(lackey.Pattern("hint_button.png")) return r
def test_app_interface(self): """ Checking App class interface methods """ ## Class methods self.assertHasMethod(lackey.App, "pause", 2) self.assertHasMethod(lackey.App, "open", 2) self.assertHasMethod(lackey.App, "focus", 2) self.assertHasMethod(lackey.App, "close", 2) self.assertHasMethod(lackey.App, "focusedWindow", 1) ## Instance methods app = lackey.App() self.assertHasMethod(app, "__init__", 2) self.assertHasMethod(app, "isRunning", 2) self.assertHasMethod(app, "hasWindow", 1) self.assertHasMethod(app, "getWindow", 1) self.assertHasMethod(app, "getPID", 1) self.assertHasMethod(app, "getName", 1) self.assertHasMethod(app, "setUsing", 2) self.assertHasMethod(app, "open", 2) self.assertHasMethod(app, "focus", 1) self.assertHasMethod(app, "close", 1) self.assertHasMethod(app, "window", 2)
def test_getters(self): if sys.platform.startswith("win"): app = lackey.App("notepad.exe tests\\test_cases.py") app2 = lackey.App("notepad.exe tests\\test_cases.py") #app.setUsing("test_cases.py") app.open() app2.open() lackey.sleep(1) app2.close() app.focus() self.assertEqual(app.getName(), "notepad.exe") self.assertTrue(app.isRunning()) self.assertRegex(app.getWindow(), "test_cases(.py)? - Notepad") self.assertNotEqual(app.getPID(), -1) region = app.window() self.assertIsInstance(region, lackey.Region) self.assertGreater(region.getW(), 0) self.assertGreater(region.getH(), 0) app.close() elif sys.platform == "darwin": if "TRAVIS" in os.environ: return # Skip these tests in travis build environment a = lackey.App("+open -a TextEdit tests/test_cases.py") a2 = lackey.App("open -a TextEdit tests/appveyor_test_cases.py") lackey.sleep(1) app = lackey.App("test_cases.py") app2 = lackey.App("appveyor_test_cases.py") #app.setUsing("test_cases.py") lackey.sleep(1) app2.close() app.focus() print(app.getPID()) self.assertTrue(app.isRunning()) self.assertEqual(app.getName()[-len("TextEdit"):], "TextEdit") #self.assertEqual(app.getWindow(), "test_cases.py") # Doesn't work on `open`-triggered apps self.assertNotEqual(app.getPID(), -1) region = app.window() self.assertIsInstance(region, lackey.Region) self.assertGreater(region.getW(), 0) self.assertGreater(region.getH(), 0) app.close() else: raise NotImplementedError( "Platforms supported include: Windows, OS X")
def setUp(self): self.kb = lackey.Keyboard() self.app = lackey.App("notepad.exe") self.app.open() time.sleep(1)