-
Notifications
You must be signed in to change notification settings - Fork 0
/
selenium_unitary_tets.py
231 lines (177 loc) · 5.91 KB
/
selenium_unitary_tets.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
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
#Luis Reyes
#Miguel Gallo
normal_user = ["email@email.com", "admin123"]
admin_user = ["admin@email.com", "admin123"]
register_data = [
["", "", "","formulario vacio"],
["", "123456", "567856","sin correo electronico"],
["correopruebagmail.com", "123456", "567856","correo sin @"],
["correoprueba@gmail", "123412", "","sin contraseña de confirmacion"],
["correoprueba@gmail", "", "123412","sin contraseña"],
["correoprueba@gmail", "123412", "123412", "registro existoso de un nuevo usuario"],
["correoprueba@gmail", "567892", "567892", "registrando usuario existente"],
]
# 'email@email.com' , password: 'admin123'
login_data = [
["", "", "formulario vacio"],
["", "123456", "correo vacio"],
["noregistradogmail.com", "123456", "correo invalido"],
["email@email.com", "123456", "contraseña incorrecta"],
["noregistrado@gmail.com", "123456", "correo no registrado"],
["email@email.com", "admin123", "inicio de sesion exitoso"],
]
driver = webdriver.Chrome('./chromedriver_linux64/chromedriver')
# driver.maximize_window()
def run_registration_test(user_email,password,password_confirmation):
global driver
driver.get('http://localhost:3000/users/sign_up')
time.sleep(5)
email_box = driver.find_element_by_id('user_email')
email_box.send_keys(str(user_email))
password_box = driver.find_element_by_id('user_password')
password_box.send_keys(str(password))
password_confirmation_box = driver.find_element_by_id(
'user_password_confirmation')
password_confirmation_box.send_keys(str(password_confirmation))
submit_button = driver.find_element_by_id('submit_registration')
submit_button.click()
time.sleep(5)
checkError("Error de formulario")
input("Prueba terminada presiones cualquier tecla para continuar")
try:
close_session()
except:
pass
def run_login_test(user_email, password):
login(user_email, password)
time.sleep(5)
checkError("Error de formulario")
input("Prueba terminada presiones cualquier tecla para continuar")
try:
close_session()
except:
pass
def close_session():
global driver
try:
close_session_button = driver.find_element_by_id('close_session_link')
close_session_button.click()
print("cerrando sesion")
time.sleep(5)
except:
pass
pass
def checkError(mensaje):
global driver
try:
if driver.find_element_by_class_name('alert') != None:
print(mensaje)
pass
except:
pass
def do_registration_tests():
global register_data
input("Presione cualquier tecla para iniciar las pruebas de registro de usuario")
for data in register_data:
print(data[3])
run_registration_test(data[0],data[1],data[2])
def do_login_tests():
global login_data
input("Presione cualquier tecla para iniciar las pruebas de inicio de sesion de usuario")
for data in login_data:
print(data[2])
run_login_test(data[0],data[1])
def login(user_email, password):
global driver
driver.get('http://localhost:3000/users/sign_in')
time.sleep(5)
email_box = driver.find_element_by_id('user_email')
email_box.send_keys(str(user_email))
password_box = driver.find_element_by_id('user_password')
password_box.send_keys(str(password))
submit_button = driver.find_element_by_id('submit_login_user')
submit_button.click()
def do_fail_app_showcase():
global driver
global normal_user
input("Presione cualquier tecla para iniciar las pruebas de recorrido fallido de la app")
driver.get('http://localhost:3000/')
time.sleep(5)
print("iniciando sesion")
login(normal_user[0], normal_user[1]) #login in
time.sleep(5)
print("añadiendo elementos al carrito")
driver.find_element_by_class_name("add_to_cart").click() #adding to cart
time.sleep(5)
#in cart view
print("vaciando carrito")
empty_cart() #empty the cart
#attempt to register
driver.find_element_by_id("register_cart_order").click()
print("Fallo en registrar orden")
close_session()
def empty_cart():
global driver
try:
driver.find_element_by_class_name("delete_cart").click()
time.sleep(5)
empty_cart()
except:
pass
def do_successful_app_showcase():
global driver
global admin_user
input("Presione cualquier tecla para iniciar las pruebas de recorrido exitoso de la app")
driver.get('http://localhost:3000/')
time.sleep(5)
print("inicio de sesion con admin")
login(admin_user[0], admin_user[1]) # login in
print("añdiendo elementos al carrito")
time.sleep(5)
driver.find_element_by_class_name("add_to_cart").click() # adding to cart
time.sleep(5)
#register to cart
print("registrando orden")
driver.find_element_by_id("register_cart_order").click()
time.sleep(5)
#go to admin section
print("entrando a la seccion de admin")
driver.find_element_by_id("admin_nav_link").click()
time.sleep(5)
#Travel in the admin sections
print("navegando en la seccion de admin")
driver.find_element_by_id("products_section").click()
print("visualiza seccion producto")
time.sleep(5)
driver.find_element_by_id("orders_section").click()
print("visualiza seccion ordenes")
time.sleep(5)
driver.find_element_by_id("users_section").click()
print("visualiza seccion usuarios")
time.sleep(5)
driver.find_element_by_id("reports_section").click()
print("visualiza seccion reportes")
time.sleep(5)
# go to procut
driver.find_element_by_id("products_section").click()
print("visualiza seccion producto")
time.sleep(5)
# go to create
driver.find_element_by_id("create_product").click()
print("visualiza seccion crear producto")
time.sleep(5)
# attemp to submit
driver.find_element_by_id("submit_button").click()
print("falla crear producto vacio")
time.sleep(5)
close_session()
def main():
do_registration_tests()
do_login_tests()
do_fail_app_showcase()
do_successful_app_showcase()
if __name__ == '__main__':
main()