def test_changers(self): # setLocation self.assertEqual(self.r.getTopLeft(), lackey.Location(0, 0)) self.assertEqual( self.r.setLocation(lackey.Location(10, 10)).getTopLeft(), lackey.Location(10, 10)) with self.assertRaises(ValueError): self.r.setLocation(None) # setROI self.r.setROI((5, 5, 10, 10)) new_region = lackey.Screen(0) new_region.morphTo(self.r) with self.assertRaises(TypeError): new_region.morphTo("werdz") self.assertEqual(self.r.getTopLeft(), new_region.getTopLeft()) self.assertEqual(self.r.getTopRight(), new_region.getTopRight()) self.assertEqual(self.r.getBottomLeft(), new_region.getBottomLeft()) self.assertEqual(self.r.getBottomRight(), new_region.getBottomRight()) with self.assertRaises(TypeError): new_region.setROI("hammersauce") with self.assertRaises(TypeError): new_region.setROI() new_region.add(5, 5, 5, 5) self.assertEqual(new_region.getTopLeft(), lackey.Location(0, 0)) # copyTo - only guaranteed one screen, so just make sure it doesn't crash new_region.copyTo(0) new_region.copyTo(lackey.Screen(0))
def testOpenApp(self): """ This looks for the specified Notepad icon on the desktop. This test will probably fail if you don't have the same setup I do. """ def test_observer(appear_event): assert (appear_event.isAppear()) img = appear_event.getImage() region = appear_event.getRegion() region.TestFlag = True region.stopObserver() r = lackey.Screen(0) if sys.platform.startswith("win"): r.doubleClick("notepad.png") elif sys.platform == "darwin": r.doubleClick("textedit.png") r.wait("preview_open_2.png") r.type("n", lackey.KeyModifier.CMD) time.sleep(2) r.type("This is a test") if sys.platform.startswith("win"): r.onAppear( lackey.Pattern("test_text.png").similar(0.6), test_observer) elif sys.platform == "darwin": r.onAppear( lackey.Pattern("mac_test_text.png").similar(0.6), test_observer) r.observe(30) self.assertTrue(r.TestFlag) self.assertGreater(r.getTime(), 0) # OCR if sys.platform.startswith("win"): a = r.find("notepad_header.png").below(400) elif sys.platform == "darwin": a = r.find("textedit_header.png").below(400) #a.highlight() self.assertIsNotNone(a.findText("This is a test")) self.assertGreater(len([a.findAllText("This is a test")]), 0) # if sys.platform.startswith("win"): r.rightClick(r.getLastMatch()) r.click("select_all.png") r.type("c", lackey.Key.CTRL) # Copy elif sys.platform == "darwin": r.type("a", lackey.KeyModifier.CMD) r.type("c", lackey.KeyModifier.CMD) self.assertEqual(r.getClipboard(), "This is a test") r.type("{DELETE}") self.assertTrue(r.waitVanishText("This is a test")) if sys.platform.startswith("win"): r.type("{F4}", lackey.Key.ALT) elif sys.platform == "darwin": r.type("w", lackey.KeyModifier.CMD) r.wait(lackey.Pattern("textedit_save_2.png")) r.click( lackey.Pattern("textedit_save_2.png").targetOffset(-126, 20)) lackey.sleep(0.5) r.type("q", lackey.KeyModifier.CMD)
def testOpenApp(self): """ This looks for the specified Notepad icon on the desktop. This test will probably fail if you don't have the same setup I do. """ def test_observer(appear_event): assert (appear_event.isAppear()) img = appear_event.getImage() region = appear_event.getRegion() region.TestFlag = True region.stopObserver() r = lackey.Screen(0) r.doubleClick("notepad.png") time.sleep(2) r.type("This is a test") r.onAppear(lackey.Pattern("test_text.png").similar(0.6), test_observer) r.observe(30) self.assertTrue(r.TestFlag) r.rightClick(r.getLastMatch()) self.assertGreater(r.getTime(), 0) r.click("select_all.png") r.type("c", lackey.Key.CONTROL) # Copy self.assertEqual(r.getClipboard(), "This is a test") r.type("{DELETE}") r.type("{F4}", lackey.Key.ALT)
def test_automate_program(self): dados_pessoa = self.collect_data() r = lackey.Screen( 0 ) # define que a região de trabalho da biblioteca Lackey será toda a tela keyboard.send("win+r") r.wait(lackey.Pattern('janela_executar.png'), 30) # espera até 30 segundos para localizar a imagem na tela r.click(lackey.Pattern('janela_executar.png')) keyboard.send( "ctrl+a" ) # seleciona tudo o que estiver escrito na caixa de texto na janela de execução keyboard.send("del") # apaga o que foi selecionado keyboard.write("wordpad") r.click('btn_ok.png') r.wait(lackey.Pattern('wordpad.png'), 60) for chave, valor in dados_pessoa.items( ): # lê todos os elementos do dicionário que tem os dados pessoais keyboard.write(chave + ' : ' + valor) keyboard.send("enter") r.wait(lackey.Pattern('btn_gravar.png'), 30) r.click(lackey.Pattern('btn_gravar.png')) r.wait(lackey.Pattern('txt_nome_arquivo.png'), 30) data_hora_atual = datetime.now().strftime('%d-%m-%y %H-%M') keyboard.write( "Teste automação " + data_hora_atual) # o nome do arquivo terá a data e hora atual r.click('btn_salvar.png') r.wait(lackey.Pattern("opcao_arquivo.png"), 30) r.click("opcao_arquivo.png") r.wait(lackey.Pattern("opcao_sair.png"), 30) r.click("opcao_sair.png")
def testDragDrop(self): """ This relies on two specific icons on the desktop. This test will probably fail if you don't have the same setup I do. """ r = lackey.Screen(0) r.dragDrop("test_file_txt.png", "notepad.png") self.assertTrue(r.exists("test_file_text.png")) r.type("{F4}", lackey.Key.ALT)
def testFindFailed(self): """ Sets up a region (which should not have the target icon) """ r = lackey.Screen(0).get(lackey.Region.NORTH_EAST) with self.assertRaises(lackey.FindFailed) as context: r.find("notepad.png") r.setFindFailedResponse(r.SKIP) try: r.find("notepad.png") except lackey.FindFailed: self.fail( "Incorrectly threw FindFailed exception; should have skipped")
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 testOpenApp(self): """ This looks for the specified Notepad icon on the desktop. This test will probably fail if you don't have the same setup I do. """ r = lackey.Screen(0) r.doubleClick("notepad.png") time.sleep(2) r.type("This is a test") r.rightClick(lackey.Pattern("test_text.png").similar(0.6)) r.click("select_all.png") r.type("c", lackey.Key.CONTROL) # Copy self.assertEqual(r.getClipboard(), "This is a test") r.type("{DELETE}") r.type("{F4}", lackey.Key.ALT)
def testDragDrop(self): """ This relies on two specific icons on the desktop. This test will probably fail if you don't have the same setup I do. """ r = lackey.Screen(0) if sys.platform.startswith("win"): r.dragDrop("test_file_txt.png", "notepad.png") self.assertTrue(r.exists("test_file_txt.png")) r.type("{F4}", lackey.Key.ALT) elif sys.platform == "darwin": r.dragDrop("test_file_rtf.png", "textedit.png") self.assertTrue(r.exists("test_file_rtf.png")) r.type("w", lackey.KeyModifier.CMD) r.type("q", lackey.KeyModifier.CMD)
def main(): lackey.addImagePath(os.path.dirname(__file__)) r = lackey.Screen(0) r.doubleClick("notepad.png") time.sleep(2) r.type("This is a test") r.onAppear(lackey.Pattern("test_text.png").similar(0.6), test_observer) r.observeInBackground(30) time.sleep(7) r.rightClick(lackey.Pattern("test_text.png").similar(0.6)) r.click("select_all.png") r.type("c", lackey.Key.CTRL) # Copy assert r.getClipboard() == "This is a test" r.type("{DELETE}") r.type("{F4}", lackey.Key.ALT)
def setUp(self): self.r = lackey.Screen(0) self.generic_event = lackey.ObserveEvent(self.r, event_type="GENERIC") self.appear_event = lackey.ObserveEvent(self.r, event_type="APPEAR") self.vanish_event = lackey.ObserveEvent(self.r, event_type="VANISH") self.change_event = lackey.ObserveEvent(self.r, event_type="CHANGE")
def setUp(self): self.r = lackey.Screen(0)
def setUp(self): lackey.addImagePath(os.path.dirname(__file__)) lackey.Screen(0).hover() lackey.Screen(0).click()
import lackey r = lackey.Screen(1) r.highlight() print(r.text()) r.findText("IBUPROFEN SUSPENSION").highlight() print(r.existsText("CHEESE")) var = [print(m) for m in r.findAllText("IBUPROFEN")]
def setUp(self): self.primaryScreen = lackey.Screen(0)
try_again = lackey.Pattern(image_path + "\\try_again.png") cancel = lackey.Pattern(image_path + "\\cancel.png") back = lackey.Pattern(image_path + "\\back.png") stolen = lackey.Pattern(image_path + "\\stolen.png") disabled = lackey.Pattern(image_path + "\\disabled_account.PNG") billing_system = lackey.Pattern(image_path + "\\billing_system.PNG") too_many_login_attemtps = lackey.Pattern(image_path + "\\too_many_login_attempts.png") logout_button = lackey.Pattern(image_path + "\\logout_button.png") click_to_play = lackey.Pattern(image_path + "\\click_to_play.png") click_to_logout = lackey.Pattern(image_path + "\\click_here_to_logout.png") authenticated = lackey.Pattern(image_path + "\\authenticated.png") accept = lackey.Pattern(image_path + "\\accept.png") report = lackey.Pattern(image_path + "\\report.png") screen = lackey.Screen() lackey.Settings.MoveMouseDelay = 0 lackey.Settings.InfoLogs = False lackey.Settings.ActionLogs = False lackey.Settings.UserLogs = False lackey.Settings.SlowMotionDelay = 0 lackey.Settings.ObserveScanRate = 10 def alert(): speak = Dispatch("SAPI.SpVoice") speak.Speak("Alert") def clicker(image): while True:
def screen(self): self.screen = lackey.Screen()