-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintegrated-test.py
163 lines (107 loc) · 3.62 KB
/
integrated-test.py
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
from datetime import datetime
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
# to get console.log
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.chrome.service import Service
def is_error(entry):
return entry['level'] in ['ERROR'] # or add higher level
def show_log(entries):
errors = list(filter(is_error, entries))
if not errors:
return
print("log:")
for e in errors:
print(f"ERROR: {e['message']}")
raise Exception(str(errors))
# You may know your chromedriver's path using `chromedriver-path` command
chromedriver_path = "/opt/homebrew/lib/python3.9/site-packages/chromedriver_binary/chromedriver"
options = webdriver.ChromeOptions()
options.add_argument('--headless')
desired_capabilities = DesiredCapabilities.CHROME
desired_capabilities['logginPrefs'] = {'browser': 'ALL'}
chrome_service = Service(executable_path=chromedriver_path)
driver = webdriver.Chrome(service=chrome_service,
options=options, desired_capabilities=desired_capabilities)
print("start /register")
# access /register
# click #register-start
driver.get('http://localhost/register')
email_input = driver.find_element(By.ID, 'email_input')
email_input.send_keys('[email protected]')
register_start = driver.find_element(By.ID, 'register_email')
register_start.click()
show_log(driver.get_log('browser'))
# receive /registerd
print("end /register")
###
print()
print("start /confirm")
# receive email
# open the link within it (/confirm)
confirm_url = input('URL to confirm: ')
if 'https' in confirm_url:
confirm_url = confirm_url.replace('https', 'http')
driver.get(confirm_url)
show_log(driver.get_log('browser'))
print("end /confirm")
###
print()
print("start /vote")
# start vote at /incubator by hand
print("please send email at: http://localhost/incubator")
# receive email
# open the link within it (/vote)
vote_url = input('URL to vote: ')
if 'https' in vote_url:
vote_url = vote_url.replace('https', 'http')
driver.get(vote_url)
# click #start_vote
start_vote = driver.find_element(By.ID, 'start_vote')
start_vote.click()
time.sleep(0.3)
print("end /vote")
show_log(driver.get_log('browser'))
print()
print("start /choose")
# moved to /choose
# for bool-vote in .boolvote
# click .voteButton[0 or 1]
bool_votes = driver.find_elements(By.CLASS_NAME, 'boolvote')
for v in bool_votes:
yes_button = v.find_element(By.CLASS_NAME, 'voteButton')
yes_button.click()
# fill in the .freevote .textArea with some text
freevote = driver.find_element(By.CLASS_NAME, 'freevote')
textarea = freevote.find_element(By.CLASS_NAME, 'textArea')
textarea.send_keys(str(datetime.now()))
print('free-vote: %s' % textarea.get_attribute('value'))
# press #donext button,
next_button = driver.find_element(By.ID, 'donext')
# parent element of the button actually handles click event
# parent = next_button.find_element_by_xpath('..')
# parent.click()
next_button.click()
time.sleep(0.5)
# moved to /choose step 2
# click #donext again (confirm)
next_button = driver.find_element(By.ID, 'donext')
# parent element of the button actually handles click event
# parent = next_button.find_element_by_xpath('..')
# parent.click()
next_button.click()
time.sleep(0.5)
show_log(driver.get_log('browser'))
print("end /choose")
###
print()
print("start /done")
# moved to done
content = driver.find_element(By.CLASS_NAME, 'content').text
if not '投票を完了しました。' in content:
raise Exception(f'failed to finish vote: {content}')
print("end /done")
print()
print("test has successfully ended")
driver.quit()