-
Notifications
You must be signed in to change notification settings - Fork 2
/
ilovemepaws
executable file
·74 lines (58 loc) · 1.73 KB
/
ilovemepaws
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python3
import os
import time
import datetime
import Xlib.display
import pyautogui
from pyvirtualdisplay.smartdisplay import SmartDisplay
from selenium import webdriver
def move_to(x, y):
return pyautogui.moveTo(x + xdiff, y + ydiff)
def click(x, y):
return pyautogui.click(x + xdiff, y + ydiff)
def screenshot():
driver.save_screenshot("{}/Screenshot from {}.png".format(artifacts_dir, datetime.datetime.now()))
window_width = 1200
window_height = 800
artifacts_dir = os.getenv('SELENIUM_ARTIFACTS_DIR').strip()
# PyVirtualDisplay
display = SmartDisplay(visible=1, size=(window_width, window_height))
display.start()
# PyAutoGUI
pyautogui._pyautogui_x11._display = Xlib.display.Display(os.environ['DISPLAY'])
# Selenium
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
driver = webdriver.Chrome(chrome_options=options)
# When testing a website that's in a Docker container,
# use the guest port (inside the Docker network), not
# the port exposed on your host machine
driver.get('http://i-love-me-paws:8000/')
driver.maximize_window()
# You'll probably have to tweak these values according to
# your window size of choice
xdiff = 0
ydiff = 116
# Do your thing
pyautogui_window_width, pyautogui_window_height = pyautogui.size()
print("Screen size: {}x{}".format(pyautogui_window_width, pyautogui_window_height))
move_to(300, 300)
# time.sleep(1)
screenshot()
move_to(1100, 20)
# time.sleep(1)
screenshot()
# Change paws
click(1100, 20)
# time.sleep(1)
screenshot()
# Leave a nice note
move_to(300, 300)
textarea = driver.find_element_by_id("textarea")
textarea.clear()
textarea.send_keys("I S2 your paws too!")
screenshot()
# Finish
driver.quit()
display.stop()
print('>>> All done.')