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 test_constructor(self): cloned_pattern = lackey.Pattern(self.pattern) self.assertTrue(cloned_pattern.isValid()) pattern_from_image = lackey.Pattern(self.pattern.getImage()) self.assertTrue(pattern_from_image.isImagePattern()) with self.assertRaises(TypeError): lackey.Pattern(True) with self.assertRaises(lackey.ImageMissing): lackey.Pattern("non_existent_file.png")
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 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 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 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 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 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 find_gems(board): #board.debugPreview() gem_types = [("green_gem.png", 0.85), ("yellow_gem.png", 0.85), ("red_gem.png", 0.85), ("purple_gem.png", 0.75), ("orange_gem.png", 0.85), ("white_gem.png", 0.85), ("blue_gem.png", 0.85)] board_state = [[None for j in range(8)] for i in range(8)] cell_size = board.getW() / 8 for gem, similarity in gem_types: matches = board.findAll(lackey.Pattern(gem).similar(similarity)) offset = board.getTopLeft() for m in matches: board_x = int((m.getTarget().x - offset.x) / cell_size) board_y = int((m.getTarget().y - offset.y) / cell_size) board_state[board_y][board_x] = gem[:1] #print ("\n".join([str(m.getTarget()) for m in matches])) #break return board_state
import time import lackey import jsonlines from time import sleep from win32com.client import Dispatch from pyautogui import typewrite, hotkey image_path = r"C:\\Users\\Sylar\\pyscripts3\\freelancer\\Z9x_DB\\BulkChecker\\RS_CHECKER\\images" existing_user = lackey.Pattern(image_path + "\\existing_user.png") login_text = lackey.Pattern(image_path + "\\login_text.png") password_text = lackey.Pattern(image_path + "\\password_text.png") login = lackey.Pattern(image_path + "\\login.png") 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
def setUp(self): self.file_path = os.path.join("tests", "test_pattern.png") self.pattern = lackey.Pattern(self.file_path)
def setUp(self): self.pattern = lackey.Pattern("tests\\test_pattern.png")