class TestScreen(TestCase): def setUp(self): """ Record all open windows :return: """ self.ahk = AHK() self.before_windows = self.ahk.windows() im = Image.new('RGB', (20, 20)) for coord in product(range(20), range(20)): im.putpixel(coord, (255, 0, 0)) self.im = im im.show() time.sleep(2) def tearDown(self): for win in self.ahk.windows(): if win not in self.before_windows: win.close() break def test_pixel_search(self): result = self.ahk.pixel_search(0xFF0000) self.assertIsNotNone(result) def test_image_search(self): self.im.save('testimage.png') position = self.ahk.image_search('testimage.png') self.assertIsNotNone(position) def test_pixel_get_color(self): x, y = self.ahk.pixel_search(0xFF0000) result = self.ahk.pixel_get_color(x, y) self.assertIsNotNone(result) self.assertEqual(int(result, 16), 0xFF0000)
timePassed += tic - toc win.activate() winLoc = win.rect winX = winLoc[0] winY = winLoc[1] winX2 = winX + (winLoc[2] // 2) winY2 = winY + winLoc[3] resetClickLoc = () while True: resetClickLoc = ahk.image_search( image_path='ReferenceImages\\reference.png', color_variation=70, upper_bound=[winX, winY], lower_bound=[winX2, winY2]) if resetClickLoc is not None: break resetClickLoc = ahk.image_search(image_path='ReferenceImages\\reference.png', color_variation=70, upper_bound=[winX, winY], lower_bound=[winX2, winY2]) ahk.click(resetClickLoc[0], resetClickLoc[1]) # Pause to make sure the computer has time to rescan the login screen after mouse is moved off the username button time.sleep(0.1) userLoc = ahk.image_search(image_path='ReferenceImages\\usernameBox.jpg',