-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.cy.js
161 lines (121 loc) · 5.16 KB
/
search.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
describe("Search", () => {
beforeEach(() => {
cy.visit("http://www.automationpractice.pl/")
})
it("should display all the necessary elements", () => {
cy.get("#searchbox")
.should("be.visible")
.within(() => {
cy.get("#search_query_top").should("be.visible")
cy.get(".button-search").should("be.visible")
})
})
context(
"As a customer, I want to be able to search for the products by name, so that I can find them more easily:",
() => {
beforeEach(() => {
cy.visit("http://www.automationpractice.pl/")
})
it("should display search bar on every page of the shop", () => {
cy.get("#search_query_top").should("be.visible").should("be.visible")
cy.get("#block_top_menu").contains("Women").click()
cy.get("#search_query_top").should("be.visible").should("be.visible")
cy.get(".sf-menu > :nth-child(2) > .sf-with-ul").click()
cy.get("#search_query_top").should("be.visible").should("be.visible")
cy.get(".sf-menu > :nth-child(3) > a").click()
cy.get("#search_query_top").should("be.visible").should("be.visible")
cy.get(".nav").contains("Contact us").click()
cy.get("#search_query_top").should("be.visible").should("be.visible")
cy.get(".nav").contains("Sign in").click()
cy.get("#search_query_top").should("be.visible").should("be.visible")
cy.get('[title="View my shopping cart"]').click({ force: true })
cy.get("#search_query_top").should("be.visible").should("be.visible")
})
it("should display placeholder text on search bar", () => {
cy.get("#search_query_top")
.should("be.visible")
.should("have.attr", "placeholder", "Search")
})
it("should display search suggestions and autocomplete text as user types the search", () => {
cy.get("#search_query_top").type("Summ")
cy.get(".ac_results")
.should("be.visible")
.and("contain.text", "Summer Dresses")
cy.get("#search_query_top").clear().type("Dress")
cy.get(".ac_results")
.should("be.visible")
.and("contain.text", "Dresses")
cy.get("#search_query_top").clear().type("Blo")
cy.get(".ac_results").should("be.visible").and("contain.text", "Blouse")
cy.get("#search_query_top").clear().type("T-shi")
cy.get(".ac_results")
.should("be.visible")
.and("contain.text", "T-shirt")
})
it("should return results for completed and partial word matches", () => {
cy.get("#search_query_top").type("Summer Dresses")
cy.get(".ac_results")
.should("be.visible")
.and("contain.text", "Summer Dresses")
cy.get("#search_query_top").clear().type("Dresses")
cy.get(".ac_results")
.should("be.visible")
.and("contain.text", "Dresses")
cy.get("#search_query_top").clear().type("Blouse")
cy.get(".ac_results").should("be.visible").and("contain.text", "Blouse")
cy.get("#search_query_top").clear().type("T-shirt")
cy.get(".ac_results")
.should("be.visible")
.and("contain.text", "T-shirt")
})
}
)
context(
"As a customer, I want detailed error messages if no results for my search were found, so that I search for something else:",
() => {
beforeEach(() => {
cy.visit("http://www.automationpractice.pl/")
})
it("should display error message 'No results were found for your search [searchQuery]' if no results are found", () => {
cy.get("#search_query_top").type("Blue Jeans")
cy.get("#searchbox > .btn").click()
cy.get(".heading-counter")
.should("be.visible")
.and("contain.text", "0 results have been found.")
cy.get(".alert")
.should("be.visible")
.and("include.text", "No results were found for your search")
.and("include.text", "Blue Jeans")
cy.get("#search_query_top").clear().type("Shorts")
cy.get("#searchbox > .btn").click()
cy.get(".alert")
.should("be.visible")
.and("include.text", "No results were found for your search")
.and("include.text", "Shorts")
cy.get("#search_query_top").clear().type("Socks")
cy.get("#searchbox > .btn").click()
cy.get(".alert")
.should("be.visible")
.and("include.text", "No results were found for your search")
.and("include.text", "Socks")
})
}
)
context(
"As a customer, I want detailed error messages if I didn't input any text on search field, so that I can search for something else:",
() => {
beforeEach(() => {
cy.visit("http://www.automationpractice.pl/")
})
it("should display error message 'Please enter a search keyword' if search query was empty", () => {
cy.get("#searchbox > .btn").click()
cy.get(".heading-counter")
.should("be.visible")
.and("include.text", "0 results have been found.")
cy.get(".alert")
.should("be.visible")
.and("include.text", "Please enter a search keyword")
})
}
)
})