-
Notifications
You must be signed in to change notification settings - Fork 0
/
note_edit.py
259 lines (226 loc) · 12.7 KB
/
note_edit.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
import unittest, time
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.keys import Keys
from faker import Faker
f = Faker()
class create_note(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.driver = webdriver.Chrome()
cls.driver.maximize_window()
cls.driver.implicitly_wait(10)
cls.driver.get("http://www.sandbox.opendrive.com/login") #Open page and wait
cls.driver.title
global wait
wait = WebDriverWait(cls.driver, 15)
def test_1_login(self):
self.assertIn("MyDrive - Login", self.driver.title) # check page title in HTML
username = self.driver.find_element_by_id("login_username")
username.click()
username.send_keys("qa.ivanpleten@gmail.com")
password = self.driver.find_element_by_id("login_password")
password.click()
password.send_keys("rootpass")
password.submit()
self.assertIn("MyDrive", self.driver.title) # check page title in HTML
def test_2_create_notepad(self):
# go to Notes page
self.driver.find_element_by_xpath(".//*[@id='container']/div[11]/div[1]/div/a[2]").click()
self.assertIn("https://sandbox.opendrive.com/notes", self.driver.current_url)
# create Notepad
self.driver.find_element_by_id("new-notpad-btn").click()
notepad_name_input = self.driver.find_element_by_xpath("//ul[@class='root-menu js-root-menu']/li/ul/li[last()]/input")
global notepad_name
notepad_name = f.company()
notepad_name_input.send_keys(notepad_name)
notepad_name_input.send_keys(Keys.RETURN)
self.driver.refresh()
time.sleep(3)
notepad = wait.until(EC.element_to_be_clickable((By.XPATH, ".//ul[@class='root-menu js-root-menu']/li[2]/ul/li/a")))
self.assertEqual(notepad_name, notepad.get_attribute("title"))
global notepad_id
notepad_id = self.driver.find_element_by_xpath(".//ul[@class='root-menu js-root-menu']/li[2]/ul/li").get_attribute("id")
def test_3_edit_note_color(self):
# open notepad
self.driver.find_element_by_id(notepad_id).click()
self.assertEquals(notepad_name, self.driver.find_element_by_xpath(".//*[@id='container']/div/div[3]/h2/a").get_attribute("text"))
#create first notation
note_clear = self.driver.find_element_by_xpath(".//*[@id='ghost-notelist']/div/div/div/div[2]/div/div/div")
note_clear.click()
note_clear.send_keys(f.text())
self.driver.find_element_by_xpath("//*[@id='container']/div/div[4]/div").click()
time.sleep(3)
#rename note
self.driver.find_element_by_xpath(".//*[@id='container']/div/div[4]/div/div[2]/div/div/div/div[1]/div[2]/span").click()
note_title = self.driver.find_element_by_xpath(".//*[@id='ghost-notelist']/div/div/div/div[1]/div[2]/input")
note_title.click()
global note_name
note_name = f.company()
note_title.clear()
note_title.send_keys(note_name)
note_title.send_keys(Keys.RETURN)
time.sleep(3)
self.driver.refresh()
#check_color
self.assertEqual("background-color: rgb(242, 242, 242);", self.driver.find_element_by_xpath(".//*[@id='container']/div/div[4]/div/div[2]/div/div/div").get_attribute("style"))
#create second notation
i = 0
while i < 2:
note = wait.until(EC.element_to_be_clickable((By.XPATH, ".//*[@id='container']/div/div[4]/div/div[2]/div/div/div/div[1]")))
add_notation_button = self.driver.find_element_by_xpath(".//*[@id='container']/div/div[4]/div/div[2]/div/div/div/div[1]/div[2]/a[2]")
ActionChains(self.driver).move_to_element(note).move_to_element(add_notation_button).click().perform()
text_area = self.driver.find_element_by_xpath(".//*[@id='container']/div/div[4]/div/div[2]/div/div/div/div[1]/div[2]/div[2]/textarea")
text_area.send_keys(f.text())
text_area.send_keys(Keys.RETURN)
time.sleep(3)
i += 1
# change color of notelist and check
a = 0
while a < 5:
# open menu
self.driver.refresh()
time.sleep(2)
note = wait.until(
EC.element_to_be_clickable((By.XPATH, ".//*[@id='container']/div/div[4]/div/div[2]/div/div/div/div[1]")))
menu_button = self.driver.find_element_by_xpath(
".//*[@id='container']/div/div[4]/div/div[2]/div/div/div/div[1]/div[2]/a[1]")
ActionChains(self.driver).move_to_element(note).move_to_element(menu_button).click().perform()
# change color
self.driver.find_element_by_xpath(".//*[@id='container']/div/div[4]/div/div[2]/div/div/div/div[1]/div[2]/div[1]/a[5]").click()
a += 1
time.sleep(2)
# check
if a == 1:
# yellow
self.assertEqual("background-color: rgb(250, 242, 147);", self.driver.find_element_by_xpath(
".//*[@id='container']/div/div[4]/div/div[2]/div/div/div").get_attribute("style"))
elif a == 2:
# red
self.assertEqual("background-color: rgb(250, 141, 131);", self.driver.find_element_by_xpath(
".//*[@id='container']/div/div[4]/div/div[2]/div/div/div").get_attribute("style"))
elif a == 3:
# green
self.assertEqual("background-color: rgb(202, 253, 143);", self.driver.find_element_by_xpath(
".//*[@id='container']/div/div[4]/div/div[2]/div/div/div").get_attribute("style"))
elif a == 4:
# blue
self.assertEqual("background-color: rgb(137, 207, 237);", self.driver.find_element_by_xpath(
".//*[@id='container']/div/div[4]/div/div[2]/div/div/div").get_attribute("style"))
elif a == 5:
# gray
self.assertEqual("background-color: rgb(242, 242, 242);", self.driver.find_element_by_xpath(
".//*[@id='container']/div/div[4]/div/div[2]/div/div/div").get_attribute("style"))
def test_4_change_size_of_note(self):
a = 0
while a < 3:
# open menu
self.driver.refresh()
time.sleep(4)
note = wait.until(
EC.element_to_be_clickable((By.XPATH, ".//*[@id='container']/div/div[4]/div/div[2]/div/div/div/div[1]")))
menu_button = self.driver.find_element_by_xpath(
".//*[@id='container']/div/div[4]/div/div[2]/div/div/div/div[1]/div[2]/a[1]")
ActionChains(self.driver).move_to_element(note).move_to_element(menu_button).click().perform()
time.sleep(1)
# change size
self.driver.find_element_by_xpath(".//*[@id='container']/div/div[4]/div/div[2]/div/div/div/div[1]/div[2]/div[1]/a[1]").click()
a += 1
time.sleep(3)
#check
#middle
if a == 1:
self.assertEqual("notelist-container col-md-6 col-sm-12", self.driver.find_element_by_xpath(".//*[@id='container']/div/div[4]/div/div[2]").get_attribute("class"))
self.assertEqual("notelist-rect-h", self.driver.find_element_by_xpath(".//*[@id='container']/div/div[4]/div/div[2]/div ").get_attribute("class"))
#big
elif a == 2:
self.assertEqual("notelist-container col-md-6 col-sm-12", self.driver.find_element_by_xpath(".//*[@id='container']/div/div[4]/div/div[2]").get_attribute("class"))
self.assertEqual("notelist-square", self.driver.find_element_by_xpath(".//*[@id='container']/div/div[4]/div/div[2]/div ").get_attribute("class"))
#little
elif a == 3:
self.assertEqual("notelist-container col-md-3 col-sm-6", self.driver.find_element_by_xpath(".//*[@id='container']/div/div[4]/div/div[2]").get_attribute("class"))
self.assertEqual("notelist-square", self.driver.find_element_by_xpath(".//*[@id='container']/div/div[4]/div/div[2]/div ").get_attribute("class"))
def test_5_check_in_notation(self):
# check
self.assertEqual("one-note drop-file ",
self.driver.find_element_by_xpath(".//*[@id='container']/div/div[4]/div/div[2]/div/div/div/div[2]/div/div[2]").get_attribute("class"))
# click check_box
self.driver.find_element_by_xpath(".//*[@id='container']/div/div[4]/div/div[2]/div/div/div/div[2]/div/div[2]/i[1]").click()
time.sleep(2)
# check
self.assertEqual("one-note drop-file checked",
self.driver.find_element_by_xpath(".//*[@id='container']/div/div[4]/div/div[2]/div/div/div/div[2]/div/div[2]").get_attribute("class"))
def test_6_delete_notation(self):
container = wait.until(EC.element_to_be_clickable((By.XPATH, ".//*[@id='container']/div/div[4]/div/div[2]/div/div/div/div[2]/div/div[2]")))
delete_button = self.driver.find_element_by_xpath(".//*[@id='container']/div/div[4]/div/div[2]/div/div/div/div[2]/div/div[2]/div[1]/div/a")
ActionChains(self.driver).move_to_element(container).move_to_element(delete_button).click().perform()
# accept delete
WebDriverWait(self.driver, 3).until(EC.alert_is_present(), "Do you really want to perform this action?")
alert = self.driver.switch_to_alert()
alert.accept()
time.sleep(5)
def test_7_delete_note(self):
self.driver.refresh()
time.sleep(4)
note = wait.until(
EC.element_to_be_clickable((By.XPATH, ".//*[@id='container']/div/div[4]/div/div[2]/div/div/div/div[1]")))
menu_button = self.driver.find_element_by_xpath(
".//*[@id='container']/div/div[4]/div/div[2]/div/div/div/div[1]/div[2]/a[1]")
ActionChains(self.driver).move_to_element(note).move_to_element(menu_button).click().perform()
# delete note
self.driver.find_element_by_xpath(
".//*[@id='container']/div/div[4]/div/div[2]/div/div/div/div[1]/div[2]/div[1]/a[2]").click()
time.sleep(1)
# accept delete
WebDriverWait(self.driver, 3).until(EC.alert_is_present(), "Do you really want to perform this action?")
alert = self.driver.switch_to_alert()
alert.accept()
time.sleep(5)
"""def test_8_drag_and_drop(self):
self.driver.refresh()
time.sleep(4)
# open notepad
self.driver.find_element_by_id(notepad_id).click()
self.assertEquals(notepad_name, self.driver.find_element_by_xpath(".//*[@id='container']/div/div[3]/h2/a").get_attribute("text"))
#create first notation
note_clear = self.driver.find_element_by_xpath(".//*[@id='ghost-notelist']/div/div/div/div[2]/div/div/div")
note_clear.click()
note_clear.send_keys(f.text())
self.driver.find_element_by_xpath("//*[@id='container']/div/div[4]/div").click()
time.sleep(3)
#create note
i = 0
while i < 8:
new_note_button = self.driver.find_element_by_id("new-notelist-btn").click()
time.sleep(3)
note = wait.until(EC.element_to_be_clickable((By.XPATH,
".//*[@id='container']/div/div[4]/div/div[1]/div/div/div/div[2]/div/div[1]/div")))
note.click()
note.send_keys(f.text())
self.driver.find_element_by_xpath(".//*[@id='container']/div/div[4]").click()
time.sleep(3)
i += 1"""
def test_9_delete_notepad(self):
# delete Notepad
find_notepad = wait.until(EC.element_to_be_clickable((By.XPATH, ".//*[@id='" + notepad_id + "']")))
menu = self.driver.find_element_by_xpath("//div[@class='dirs js-left-sidebar notepads']/ul/li/ul/li[1]/i[1]")
trash = self.driver.find_element_by_xpath(
"//div[@class='dirs js-left-sidebar notepads']/ul/li/ul/li[1]/ul/li[3]")
ActionChains(self.driver).move_to_element(find_notepad).move_to_element(menu).click().perform()
trash.click()
time.sleep(2)
# accept delete
WebDriverWait(self.driver, 3).until(EC.alert_is_present(), "Do you really want to perform this action?")
alert = self.driver.switch_to_alert()
alert.accept()
self.driver.delete_all_cookies()
time.sleep(5)
@classmethod
def tearDownClass(cls):
cls.driver.close()
if __name__ == '__main__':
unittest.main(verbosity=2)