-
Notifications
You must be signed in to change notification settings - Fork 0
/
automation-practice.cy.js
415 lines (282 loc) · 11 KB
/
automation-practice.cy.js
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
/// <reference types="cypress" />
const userCredentials = require("../../fixtures/user-credentials.json")
const {
blouse,
smallBlouse,
printedDressInPinkColor,
printedSummerDressInSkyBlue
} = require("../../fixtures/products.json")
const { generateUniqueEmail } = require("../../support/utils")
describe("Automation Practice Test Cases", () => {
beforeEach(() => {
userCredentials.email = "testuser@gmail.com"
cy.visit("http://www.automationpractice.pl/")
})
it("TC.01 Register User", () => {
userCredentials.email = generateUniqueEmail(userCredentials.email)
cy.signUpUser(userCredentials)
cy.url().should("include", "controller=my-account")
cy.checkElemText(".breadcrumb", "My account")
cy.checkElemText("h1", "My account")
cy.checkElemText(".alert", "Your account has been created.")
cy.checkElemText(
".info-account",
"Welcome to your account. Here you can manage all of your personal information and orders."
)
})
it("TC.02 Login User with correct email and password", () => {
cy.loginUser(userCredentials)
cy.url().should("include", "controller=my-account")
cy.checkElemText(".breadcrumb", "My account")
cy.checkElemText("h1", "My account")
cy.checkElemText("h1", "My account")
cy.checkElemText(
".info-account",
"Welcome to your account. Here you can manage all of your personal information and orders."
)
})
it("TC.03 Login User with incorrect email and password", () => {
cy.loginUser(
{
email: "invalid99@gmail.com",
password: userCredentials.password
},
true
)
cy.checkElemText(".breadcrumb", "Authentication")
cy.checkElemText("h1", "Authentication")
cy.get("#login_form").should("be.visible")
cy.checkElemText(
"#center_column > :nth-child(2)",
"There is 1 error",
"Authentication failed."
)
})
it("TC.04 Logout User", () => {
userCredentials.email = generateUniqueEmail(userCredentials.email)
cy.signUpUser(userCredentials)
cy.checkElemText(".alert", "Your account has been created.")
cy.contains("Sign out").click()
cy.url().should("contains", "controller=authentication")
cy.checkElemText(".breadcrumb", "Authentication")
cy.checkElemText("h1", "Authentication")
cy.get("#create-account_form").should("be.visible")
cy.get("#login_form").should("be.visible")
})
it("TC.05 Register User with existing email", () => {
userCredentials.email = generateUniqueEmail(userCredentials.email)
cy.signUpUser(userCredentials)
cy.checkElemText(".alert", "Your account has been created.")
cy.contains("Sign out").click()
cy.contains("Sign in").click()
cy.fillCreateAccountEmail(userCredentials)
cy.checkElemText(
"#create_account_error",
"An account using this email address has already been registered. Please enter a valid password or request a new one."
)
})
it("TC.06 Contact Us Form", () => {
cy.contains("Contact us").click()
cy.checkElemText(".breadcrumb", "Contact")
cy.checkElemText("h1", "Customer service - Contact us")
cy.checkElemText(".contact-form-box", "send a message").within(() => {
cy.get("#id_contact").select("Customer service")
cy.get("#email").should("be.visible").type(userCredentials.email).blur()
cy.get(".form-ok #email").should("be.visible")
cy.get("#id_order").should("be.visible").type("12345")
cy.get("#message")
.should("be.visible")
.type("My order has not yet arrived!")
cy.contains("Send").should("be.visible").click()
})
cy.checkElemText(
".alert",
"Your message has been successfully sent to our team."
)
})
it("TC.07 Verify All Products and product detail page", () => {
cy.clickNavSection("women")
cy.checkElemText("h1", "Women")
cy.get(".product_list")
.should("be.visible")
.within(() => {
cy.get(".product-container").each(($el) => {
cy.get($el).within(() => {
cy.get(".product-image-container").should("be.visible")
cy.get(".product-name").should("be.visible")
cy.get(".content_price").should("be.visible")
cy.get(".button-container").should("be.visible")
})
})
})
cy.get(
".first-in-line.last-item-of-tablet-line > .product-container > .right-block > .button-container > .lnk_view > span"
).click()
cy.url().should(
"eq",
"http://www.automationpractice.pl/index.php?id_product=4&controller=product"
)
cy.checkElemText("h1", "Printed Dress")
cy.checkElemText("#product_reference", "demo_4")
cy.checkElemText("#product_condition", "New product")
cy.checkElemText(
"#short_description_content > p",
"Printed evening dress with straight sleeves with black thin waist belt and ruffled linings."
)
cy.checkElemText(".content_prices", "$51")
cy.get(".product_attributes").should("be.visible")
})
it("TC.08 Search Product", () => {
cy.searchProduct("Blouse")
cy.checkElemText("h1", "Search", "Blouse")
cy.get(".product-count").first().should("contain.text", "1 - 1 of 1 item")
cy.get(".product_list")
.should("be.visible")
.within(() => {
cy.get(".product-container").should("have.length", 1)
cy.checkElemText(".product-container", "Blouse")
})
})
it("TC.09 Verify Subscription in home page", () => {
userCredentials.email = generateUniqueEmail(userCredentials.email)
cy.get("#newsletter-input").type(userCredentials.email)
cy.get(".form-group > .btn").click()
cy.checkElemText(
".alert-success",
"Newsletter : You have successfully subscribed to this newsletter."
)
})
it("TC.10 Verify Subscription in Cart page", () => {
userCredentials.email = generateUniqueEmail(userCredentials.email)
cy.get(".shopping_cart").should("be.visible").click()
cy.get("#newsletter-input").type(userCredentials.email)
cy.get(".form-group > .btn").click()
cy.checkElemText(
".alert-success",
"Newsletter : You have successfully subscribed to this newsletter."
)
})
it("TC.11 Add Products in Cart", () => {
cy.checkElemText(".shopping_cart", "(empty)")
cy.clickNavSection("women")
cy.addProductToCart(blouse)
cy.get(".exclusive > span").click()
cy.checkElemText(
"#layer_cart > .clearfix",
"Product successfully added to your shopping cart",
"There is 1 item in your cart."
)
cy.contains("Continue shopping").should("be.visible").click()
cy.checkElemText(".shopping_cart", "1", "Product")
})
it("TC.12 Verify Product quantity in Cart", () => {
cy.checkElemText(".shopping_cart", "(empty)")
cy.clickNavSection("women")
blouse.quantity = 3
cy.addProductToCart(blouse)
cy.checkElemText(
"#layer_cart > .clearfix",
"Product successfully added to your shopping cart",
"There are 3 items in your cart."
)
cy.contains("Continue shopping").should("be.visible").click()
cy.checkElemText(".shopping_cart", "3", "Products")
cy.checkElemText(".shopping_cart", "3", "x", "Blouse")
})
it("TC.13 Place Order: Login before Checkout", () => {
cy.loginUser(userCredentials)
cy.url().should("include", "my-account")
cy.addProductToCart(printedDressInPinkColor)
cy.contains("Proceed to checkout").click()
cy.get(".step_current > span").should("contain.text", "Summary")
cy.get(".cart_navigation > .button > span").click()
cy.get(".step_current > span").should("contain.text", "Address")
cy.get(".cart_navigation > .button > span").click()
cy.get(".step_current > span").should("contain.text", "Shipping")
cy.get("#cgv").click()
cy.get(".cart_navigation > .button > span").click()
cy.get(".step_current > span").should("contain.text", "Payment")
cy.get(".bankwire").click()
cy.get("#cart_navigation > .button > span").click()
cy.checkElemText(".alert", "Your order on My Shop is complete.")
})
it("TC.14 Remove Products From Cart", () => {
cy.checkElemText(".shopping_cart", "(empty)")
cy.clickNavSection("women")
cy.addProductToCart(blouse)
cy.addProductToCart(blouse)
cy.addProductToCart(blouse)
cy.checkElemText(".shopping_cart", "3", "Products")
cy.contains("Continue shopping").click()
cy.get('[title="View my shopping cart"]').trigger("mouseover")
cy.checkElemText(".cart-info", "3", "x", "Blouse")
cy.get(".remove_link").click()
cy.checkElemText(".shopping_cart", "(empty)")
cy.get('[title="View my shopping cart"]').click()
cy.checkElemText(".alert", "Your shopping cart is empty.")
})
it("TC.15 View Category Products", () => {
cy.clickNavSection("women")
cy.checkElemText("h1", "Women")
cy.get(".product_list")
.should("be.visible")
.within(() => {
cy.get(".product-container").should("have.length", 7)
})
cy.get("#ul_layered_category_0 > :nth-child(1) > label").click()
cy.checkElemText("h1", "Women > Categories Tops")
cy.get(".product_list")
.should("be.visible")
.within(() => {
cy.get(".product-container").should("have.length", 2)
})
})
it("TC.16 View & Cart Brand Products", () => {
cy.clickNavSection("women")
cy.checkElemText("h1", "Women")
cy.get(".product_list").should("be.visible")
cy.get(".product-container").should("have.length", 7)
cy.get("#ul_layered_category_0 > :nth-child(2) > label").click()
cy.checkElemText("h1", "Women > Categories Dresses")
cy.get(".product-container").should("have.length", 5)
// Product is in the 3rd position when using 'Dresses' filter
const _printedSummerDressInSkyBlue = {
productNum: 3,
color: printedSummerDressInSkyBlue.color
}
cy.addProductToCart(_printedSummerDressInSkyBlue)
cy.checkElemText(
"#layer_cart > .clearfix",
"Product successfully added to your shopping cart",
"There is 1 item in your cart."
)
cy.get(".continue > span").click()
cy.checkElemText('[title="View my shopping cart"]', "Cart", "1", "Product")
})
it.skip("TC.17 Search Products and Verify Cart After Login", () => {
cy.loginUser(userCredentials)
cy.searchProduct("Printed Summer Dress")
cy.addProductToCart(printedSummerDressInSkyBlue)
cy.get(".button-medium > span").click()
// Find all elements whose ID starts with "#product_"
cy.get('[id^="product_"]')
.first()
.within(() => {
cy.checkElemText(
".cart_description > .product-name",
"Printed Summer Dress"
)
cy.checkElemText(".cart_ref", "SKU : demo_5")
cy.checkElemText(
".cart_description > :nth-child(3)",
"Size : S, Color : Blue"
)
cy.checkElemText(".label", "In stock")
cy.checkElemText(".price", "$29")
cy.get(".cart_quantity_input")
.should("be.visible")
.and("contain.value", "1")
cy.checkElemText(".cart_total", "$29")
})
})
})