Skip to content

Commit 21cfda3

Browse files
authoredFeb 23, 2023
test(cypress): fix tests flakiness by stubbing httpbin.org requests (#8410)
Closes #8409
1 parent 6164292 commit 21cfda3

File tree

3 files changed

+129
-52
lines changed

3 files changed

+129
-52
lines changed
 

‎test/e2e-cypress/tests/bugs/6183.js

+24
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
11
describe("When trying it out", () => {
22
it("should render the response headers as comma separated lists", () => {
3+
cy.intercept(
4+
{
5+
method: "GET",
6+
url: /^\/response-headers/,
7+
hostname: "httpbin.org",
8+
},
9+
{
10+
body: {
11+
"Access-Control-Expose-Headers": "X-Header1, X-Header2, X-Header3, Access-Control-Expose-Headers",
12+
"Content-Length": "289",
13+
"Content-Type": "application/json",
14+
"X-Header1": "value1,value2",
15+
"X-Header2": "value3,value4",
16+
"X-Header3": ["value5", "value6"]
17+
},
18+
headers: {
19+
"access-control-expose-headers": "X-Header1,X-Header2,X-Header3,Access-Control-Expose-Headers",
20+
"content-type": "application/json",
21+
"x-header1": "value1,value2",
22+
"x-header2": "value3,value4",
23+
"x-header3": "value5,value6",
24+
}
25+
})
26+
327
cy.visit("/?url=/documents/bugs/6183.yaml")
428
.get("#operations-default-get_response_headers")
529
.click()

‎test/e2e-cypress/tests/features/oas3-multiple-media-type.js

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ describe("OpenAPI 3.0 Multiple Media Types with different schemas", () => {
88
const mediaTypeJson = "application/json"
99

1010
beforeEach(() => {
11+
cy.intercept({
12+
method: "POST",
13+
url: "/post",
14+
hostname: "httpbin.org",
15+
}, {})
16+
1117
cy.visit(
1218
"/?url=/documents/features/oas3-multiple-media-type.yaml"
1319
)

‎test/e2e-cypress/tests/features/oas3-request-body-required.js

+99-52
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,59 @@
44

55
describe("OpenAPI 3.0 Validation for Required Request Body and Request Body Fields", () => {
66
describe("Request Body required bug/5181", () => {
7-
it("on execute, if empty value, SHOULD render class 'invalid' and should NOT render cURL component", () => {
8-
cy.visit(
9-
"/?url=/documents/bugs/5181.yaml"
7+
beforeEach(() => {
8+
cy.intercept(
9+
{
10+
method: "POST",
11+
url: "/anything/foos",
12+
hostname: "httpbin.org",
13+
},
14+
{}
1015
)
16+
})
17+
18+
it("on execute, if empty value, SHOULD render class 'invalid' and should NOT render cURL component", () => {
19+
cy.visit("/?url=/documents/bugs/5181.yaml")
1120
.get("#operations-default-post_foos")
1221
.click()
1322
// Expand Try It Out
1423
.get(".try-out__btn")
1524
.click()
1625
// get input
17-
.get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(1) > .parameters-col_description input")
26+
.get(
27+
".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(1) > .parameters-col_description input"
28+
)
1829
.should("not.have.class", "invalid")
1930
// Execute
2031
.get(".execute.opblock-control__btn")
2132
.click()
2233
// class "invalid" should now exist (and render red, which we won't check)
23-
.get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(1) > .parameters-col_description input")
34+
.get(
35+
".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(1) > .parameters-col_description input"
36+
)
2437
.should("have.class", "invalid")
2538
// cURL component should not exist
2639
.get(".responses-wrapper .curl-command")
2740
.should("not.exist")
2841
})
2942
it("on execute, if value exists, should NOT render class 'invalid' and SHOULD render cURL component", () => {
30-
cy.visit(
31-
"/?url=/documents/bugs/5181.yaml"
32-
)
43+
cy.visit("/?url=/documents/bugs/5181.yaml")
3344
.get("#operations-default-post_foos")
3445
.click()
3546
// Expand Try It Out
3647
.get(".try-out__btn")
3748
.click()
3849
// get input
39-
.get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(1) > .parameters-col_description input")
50+
.get(
51+
".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(1) > .parameters-col_description input"
52+
)
4053
.type("abc")
4154
// Execute
4255
.get(".execute.opblock-control__btn")
4356
.click()
44-
.get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(1) > .parameters-col_description input")
57+
.get(
58+
".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(1) > .parameters-col_description input"
59+
)
4560
.should("not.have.class", "invalid")
4661
// cURL component should exist
4762
.get(".responses-wrapper .curl-command")
@@ -51,45 +66,49 @@ describe("OpenAPI 3.0 Validation for Required Request Body and Request Body Fiel
5166

5267
describe("Request Body required fields - application/json", () => {
5368
it("on execute, if empty value, SHOULD render class 'invalid' and should NOT render cURL component", () => {
54-
cy.visit(
55-
"/?url=/documents/features/petstore-only-pet.openapi.yaml"
56-
)
69+
cy.visit("/?url=/documents/features/petstore-only-pet.openapi.yaml")
5770
.get("#operations-pet-addPet")
5871
.click()
5972
// Expand Try It Out
6073
.get(".try-out__btn")
6174
.click()
6275
// get and clear textarea
63-
.get(".opblock-body .opblock-section .opblock-section-request-body .body-param textarea")
76+
.get(
77+
".opblock-body .opblock-section .opblock-section-request-body .body-param textarea"
78+
)
6479
.should("not.have.class", "invalid")
6580
.clear()
6681
// Execute
6782
.get(".execute.opblock-control__btn")
6883
.click()
6984
// class "invalid" should now exist (and render red, which we won't check)
70-
.get(".opblock-body .opblock-section .opblock-section-request-body .body-param textarea")
85+
.get(
86+
".opblock-body .opblock-section .opblock-section-request-body .body-param textarea"
87+
)
7188
.should("have.class", "invalid")
7289
// cURL component should not exist
7390
.get(".responses-wrapper .curl-command")
7491
.should("not.exist")
7592
})
7693
it("on execute, if value exists, even if just single space, should NOT render class 'invalid' and SHOULD render cURL component that contains the single space", () => {
77-
cy.visit(
78-
"/?url=/documents/features/petstore-only-pet.openapi.yaml"
79-
)
94+
cy.visit("/?url=/documents/features/petstore-only-pet.openapi.yaml")
8095
.get("#operations-pet-addPet")
8196
.click()
8297
// Expand Try It Out
8398
.get(".try-out__btn")
8499
.click()
85100
// get, clear, then modify textarea
86-
.get(".opblock-body .opblock-section .opblock-section-request-body .body-param textarea")
101+
.get(
102+
".opblock-body .opblock-section .opblock-section-request-body .body-param textarea"
103+
)
87104
.clear()
88105
.type(" ")
89106
// Execute
90107
.get(".execute.opblock-control__btn")
91108
.click()
92-
.get(".opblock-body .opblock-section .opblock-section-request-body .body-param textarea")
109+
.get(
110+
".opblock-body .opblock-section .opblock-section-request-body .body-param textarea"
111+
)
93112
.should("not.have.class", "invalid")
94113
// cURL component should exist
95114
.get(".responses-wrapper .curl-command")
@@ -99,57 +118,67 @@ describe("OpenAPI 3.0 Validation for Required Request Body and Request Body Fiel
99118
})
100119
})
101120

102-
/*
103-
petstore ux notes:
121+
/*
122+
petstore ux notes:
104123
- required field, but if example value exists, will populate the field. So this test will clear the example value.
105124
- "add item" will insert an empty array, and display an input text box. This establishes a value for the field.
106125
*/
107126
describe("Request Body required fields - application/x-www-form-urlencoded", () => {
108127
it("on execute, if empty value, SHOULD render class 'invalid' and should NOT render cURL component", () => {
109-
cy.visit(
110-
"/?url=/documents/features/petstore-only-pet.openapi.yaml"
111-
)
128+
cy.visit("/?url=/documents/features/petstore-only-pet.openapi.yaml")
112129
.get("#operations-pet-addPet")
113130
.click()
114-
.get(".opblock-section .opblock-section-request-body .body-param-content-type > select")
131+
.get(
132+
".opblock-section .opblock-section-request-body .body-param-content-type > select"
133+
)
115134
.select("application/x-www-form-urlencoded")
116135
// Expand Try It Out
117136
.get(".try-out__btn")
118137
.click()
119138
// get and clear input populated from example value
120-
.get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(2) > .parameters-col_description input")
139+
.get(
140+
".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(2) > .parameters-col_description input"
141+
)
121142
.clear()
122143
// Execute
123144
.get(".execute.opblock-control__btn")
124145
.click()
125146
// class "invalid" should now exist (and render red, which we won't check)
126-
.get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(2) > .parameters-col_description input")
147+
.get(
148+
".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(2) > .parameters-col_description input"
149+
)
127150
.should("have.class", "invalid")
128151
// cURL component should not exist
129152
.get(".responses-wrapper .curl-command")
130153
.should("not.exist")
131154
})
132155
it("on execute, if all values exist, even if array exists but is empty, should NOT render class 'invalid' and SHOULD render cURL component", () => {
133-
cy.visit(
134-
"/?url=/documents/features/petstore-only-pet.openapi.yaml"
135-
)
156+
cy.visit("/?url=/documents/features/petstore-only-pet.openapi.yaml")
136157
.get("#operations-pet-addPet")
137158
.click()
138-
.get(".opblock-section .opblock-section-request-body .body-param-content-type > select")
159+
.get(
160+
".opblock-section .opblock-section-request-body .body-param-content-type > select"
161+
)
139162
.select("application/x-www-form-urlencoded")
140163
// Expand Try It Out
141164
.get(".try-out__btn")
142165
.click()
143166
// add item to get input
144-
.get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(4) > .parameters-col_description button")
167+
.get(
168+
".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(4) > .parameters-col_description button"
169+
)
145170
.click()
146171
// Execute
147172
.get(".execute.opblock-control__btn")
148173
.click()
149-
.get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(2) > .parameters-col_description input")
174+
.get(
175+
".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(2) > .parameters-col_description input"
176+
)
150177
.should("have.value", "doggie")
151178
.should("not.have.class", "invalid")
152-
.get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(4) > .parameters-col_description input")
179+
.get(
180+
".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(4) > .parameters-col_description input"
181+
)
153182
.should("have.value", "string")
154183
.should("not.have.class", "invalid")
155184
// cURL component should exist
@@ -160,58 +189,76 @@ describe("OpenAPI 3.0 Validation for Required Request Body and Request Body Fiel
160189

161190
describe("Request Body: switching between Content Types", () => {
162191
it("after application/json 'invalid' error, on switch content type to application/x-www-form-urlencoded, SHOULD be free of errors", () => {
163-
cy.visit(
164-
"/?url=/documents/features/petstore-only-pet.openapi.yaml"
165-
)
192+
cy.visit("/?url=/documents/features/petstore-only-pet.openapi.yaml")
166193
.get("#operations-pet-addPet")
167194
.click()
168195
// Expand Try It Out
169196
.get(".try-out__btn")
170197
.click()
171198
// get and clear textarea
172-
.get(".opblock-body .opblock-section .opblock-section-request-body .body-param textarea")
199+
.get(
200+
".opblock-body .opblock-section .opblock-section-request-body .body-param textarea"
201+
)
173202
.should("not.have.class", "invalid")
174203
.clear()
175204
// Execute
176205
.get(".execute.opblock-control__btn")
177206
.click()
178-
.get(".opblock-body .opblock-section .opblock-section-request-body .body-param textarea")
207+
.get(
208+
".opblock-body .opblock-section .opblock-section-request-body .body-param textarea"
209+
)
179210
.should("have.class", "invalid")
180211
// switch content type
181-
.get(".opblock-section .opblock-section-request-body .body-param-content-type > select")
212+
.get(
213+
".opblock-section .opblock-section-request-body .body-param-content-type > select"
214+
)
182215
.select("application/x-www-form-urlencoded")
183-
.get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(2) > .parameters-col_description input")
216+
.get(
217+
".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(2) > .parameters-col_description input"
218+
)
184219
.should("not.have.class", "invalid")
185220
// add item to get input, just an extra confirmation of non-invalid class
186-
.get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(4) > .parameters-col_description button")
221+
.get(
222+
".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(4) > .parameters-col_description button"
223+
)
187224
.click()
188-
.get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(4) > .parameters-col_description input")
225+
.get(
226+
".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(4) > .parameters-col_description input"
227+
)
189228
.should("not.have.class", "invalid")
190229
})
191230
it("after application/x-www-form-urlencoded 'invalid' error, on switch content type to application/json, SHOULD be free of errors", () => {
192-
cy.visit(
193-
"/?url=/documents/features/petstore-only-pet.openapi.yaml"
194-
)
231+
cy.visit("/?url=/documents/features/petstore-only-pet.openapi.yaml")
195232
.get("#operations-pet-addPet")
196233
.click()
197-
.get(".opblock-section .opblock-section-request-body .body-param-content-type > select")
234+
.get(
235+
".opblock-section .opblock-section-request-body .body-param-content-type > select"
236+
)
198237
.select("application/x-www-form-urlencoded")
199238
// Expand Try It Out
200239
.get(".try-out__btn")
201240
.click()
202241
// get and clear input
203-
.get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(2) > .parameters-col_description input")
242+
.get(
243+
".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(2) > .parameters-col_description input"
244+
)
204245
.clear()
205246
// Execute
206247
.get(".execute.opblock-control__btn")
207248
.click()
208249
// class "invalid" should now exist (and render red, which we won't check)
209-
.get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(2) > .parameters-col_description input")
250+
.get(
251+
".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(2) > .parameters-col_description input"
252+
)
210253
.should("have.class", "invalid")
211254
// switch content type
212-
.get(".opblock-section .opblock-section-request-body .body-param-content-type > select")
255+
.get(
256+
".opblock-section .opblock-section-request-body .body-param-content-type > select"
257+
)
213258
.select("application/json")
214-
.get(".opblock-body .opblock-section .opblock-section-request-body .body-param textarea")
259+
.get(
260+
".opblock-body .opblock-section .opblock-section-request-body .body-param textarea"
261+
)
215262
.should("not.have.class", "invalid")
216263
})
217264
})

0 commit comments

Comments
 (0)
Please sign in to comment.