Skip to content

Commit ec4d4c7

Browse files
gilzowchadwcarlson
andauthored
Adds e2e testing (#4085)
* adds cypress and initial config files * updates config files and test file, adds github actions file * adds cypress example files to ignore * updated env var name in config, aliases find of h2 since the test was losing it? * adds a check for missing object properties and if missing, attempts to repopulate them * blocks analytics scripts from loading during tests * cleans up our spec file * trying to debug why we are still failing tests * add a wait to see if that gets us over the hump * adding a full second pause since the runner seems to be slow * adds config files for adding cypress e2e testing adds workflow for triggering cypress e2e testing * removes .wait() and replaces with a .clear() on the input element * third test is still flaky w/o the .wait(). readding * Apply suggestions from code review --------- Co-authored-by: Chad Carlson <[email protected]>
1 parent b1c11f2 commit ec4d4c7

File tree

13 files changed

+5607
-274
lines changed

13 files changed

+5607
-274
lines changed

.github/workflows/e2e.yaml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: runs E2E tests
2+
on:
3+
workflow_run:
4+
workflows: [Get info on PR]
5+
types:
6+
- completed
7+
8+
jobs:
9+
setup_matrix:
10+
runs-on: ubuntu-latest
11+
outputs:
12+
psh_url: ${{ steps.retrieve-url.outputs.psh_url }}
13+
up_url: ${{ steps.retrieve-url.outputs.up_url }}
14+
steps:
15+
- name: Download info on PR
16+
uses: dawidd6/action-download-artifact@v2
17+
with:
18+
workflow: get-urls.yaml
19+
workflow_conclusion: completed
20+
name: pr-info
21+
- name: retrieve url
22+
id: retrieve-url
23+
run: |
24+
PSH_URL=$(cat environment_url.txt)
25+
echo "PSH URL is $PSH_URL"
26+
UP_URL="https://docs.upsun.com.${PSH_URL:8}"
27+
echo "UP URL is ${UP_URL}"
28+
echo "psh_url=$PSH_URL" >> $GITHUB_OUTPUT
29+
echo "up_url=$UP_URL" >> $GITHUB_OUTPUT
30+
31+
run_test:
32+
runs-on: ubuntu-latest
33+
needs: setup_matrix
34+
strategy:
35+
matrix:
36+
include:
37+
- site: platformsh
38+
url: ${{ needs.setup_matrix.outputs.psh_url }}
39+
- site: upsun
40+
url: ${{ needs.setup_matrix.outputs.up_url }}
41+
steps:
42+
- uses: actions/checkout@v4
43+
- uses: cypress-io/github-action@v6
44+
with:
45+
wait-on: ${{ matrix.url }}
46+
record: true
47+
env:
48+
CYPRESS_baseUrl: ${{ matrix.url }}
49+
CYPRESS_environment: github
50+
CYPRESS_site: ${{ matrix.site }}
51+
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
52+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ vendorize
88
vale
99
vrt-docs-migration
1010
sites/bin
11-
bin
11+
bin
12+
cypress/e2e/1-getting-started
13+
cypress/e2e/2-advanced-examples

cypress.config.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const { defineConfig } = require("cypress");
2+
3+
module.exports = defineConfig({
4+
projectId: 'k7k61v',
5+
e2e: {
6+
baseUrl: 'http://localhost:1313/',
7+
env: {
8+
site: 'not set',
9+
environment: "local",
10+
},
11+
setupNodeEvents(on, config) {
12+
// implement node event listeners here
13+
},
14+
blockHosts: [
15+
'www.googletagmanager.com',
16+
'cdn.cookielaw.org',
17+
'cdn.heapanalytics.com',
18+
'heapanalytics.com',
19+
'cdn.matomo.cloud',
20+
],
21+
},
22+
});

cypress/e2e/search.cy.js

+142
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
//Both should return results for "opensearch"
2+
//Only Upsun should return a match for "vertical scaling"
3+
//Only platform should return a match for "24.55 gb"
4+
describe("Searches",()=>{
5+
beforeEach(()=>{
6+
if('local' == Cypress.env('environment')) {
7+
cy.intercept("/indexes/*_docs/search*", { "hits":[] })
8+
}
9+
10+
//cy.visit("/")
11+
})
12+
13+
context("Search tests",()=>{
14+
it("Searches for something that should match in both", () => {
15+
cy.visit("/")
16+
if('local' == Cypress.env('environment')) {
17+
cy.intercept({
18+
pathname: '/indexes/*_docs/search',
19+
query: {
20+
q: 'opensearch'
21+
}
22+
},{ fixture: "opensearchresults" }).as("searchresultsopensearch")
23+
}
24+
25+
cy.get("#searchwicon-header").type("opensearch")
26+
27+
if ('local' == Cypress.env('environment')) {
28+
cy.wait('@searchresultsopensearch')
29+
}
30+
31+
cy.get("#xssroot").find("h2").as("searchresultsheader")
32+
cy.get("@searchresultsheader").should("exist")
33+
cy.get("@searchresultsheader").contains("Documentation")
34+
cy.get("#xssroot").find("li").contains("OpenSearch").should("exist")
35+
36+
cy.get("#searchwicon-header").type("{enter}")
37+
cy.location("pathname").should(
38+
"eq",
39+
"/search.html"
40+
)
41+
42+
cy.get("#xssSearchPage").find("h2").as("searchpageresults")
43+
cy.get("@searchpageresults").should("exist")
44+
cy.get("@searchpageresults").contains("Documentation")
45+
46+
cy.get("#xssSearchPage").find("li").contains("OpenSearch").should("exist")
47+
48+
})
49+
50+
it("Searches for something that should not match on Platformsh, but should on Upsun", ()=>{
51+
const searchDetails = {
52+
search: 'vertical scaling',
53+
header: 'No results',
54+
body: 'No documentation matched'
55+
}
56+
57+
if ('upsun' == Cypress.env('site')) {
58+
searchDetails.header = 'Documentation'
59+
searchDetails.body = searchDetails.search
60+
}
61+
62+
cy.visit("/")
63+
cy.get("#searchwicon-header").type(searchDetails.search)
64+
cy.get("#xssroot").find("h2").as("searchresultsheader")
65+
cy.get("@searchresultsheader").should("exist")
66+
cy.get("@searchresultsheader").contains(searchDetails.header)
67+
cy.get("#xssroot").find("p").contains(searchDetails.body)
68+
69+
cy.get("#searchwicon-header").type("{enter}")
70+
cy.location("pathname").should(
71+
"eq",
72+
"/search.html"
73+
)
74+
75+
cy.get("#xssSearchPage").find("h2").as("searchpageresults")
76+
cy.get("@searchpageresults").should("exist")
77+
if ('upsun' == Cypress.env('site')) {
78+
cy.get("#xssSearchPage").find("li").contains(searchDetails.body).should("exist")
79+
} else {
80+
cy.get("#xssSearchPage").contains(searchDetails.header)
81+
}
82+
83+
})
84+
85+
it("Searches for something that should ONLY match on platformsh, but not on Upsun", () => {
86+
const searchDetails = {
87+
search: '24.55',
88+
header: 'No results',
89+
body: 'No documentation matched'
90+
}
91+
92+
console.log('Current site is ' + Cypress.env('site'))
93+
94+
if ('platformsh' == Cypress.env('site')) {
95+
searchDetails.header = 'Documentation'
96+
searchDetails.body = searchDetails.search
97+
}
98+
99+
cy.visit("/")
100+
if('local' == Cypress.env('environment')) {
101+
cy.intercept({
102+
pathname: '/indexes/*_docs/search',
103+
query: {
104+
q: 'opensearch'
105+
}
106+
},{ fixture: "searchosresults" }).as("searchresultsopensearch")
107+
}
108+
109+
console.log('Pausing before starting')
110+
cy.wait(1000)
111+
console.log('finished pausing')
112+
113+
cy.get("#searchwicon-header").clear().type(searchDetails.search)
114+
115+
if ('local' == Cypress.env('environment')) {
116+
cy.wait('@searchresultsopensearch')
117+
}
118+
119+
cy.get("#xssroot").find("h2").as("searchresultsheader")
120+
cy.get("@searchresultsheader").should("exist")
121+
cy.get("@searchresultsheader").contains(searchDetails.header)
122+
cy.get('#xssroot').find('p').contains(searchDetails.body)
123+
124+
cy.get("#searchwicon-header").type("{enter}")
125+
cy.location("pathname").should(
126+
"eq",
127+
"/search.html"
128+
)
129+
130+
cy.get("#xssSearchPage").find("h2").as("searchpageresults")
131+
cy.get("@searchpageresults").should("exist")
132+
cy.get("@searchpageresults").contains(searchDetails.header)
133+
134+
if ('platformsh' == Cypress.env('site')) {
135+
cy.get("#xssSearchPage").find("li").contains(searchDetails.body).should("exist")
136+
} else {
137+
cy.get("#xssSearchPage").contains(searchDetails.body)
138+
}
139+
140+
})
141+
})
142+
})

cypress/fixtures/example.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "Using fixtures to represent data",
3+
"email": "[email protected]",
4+
"body": "Fixtures are a great way to mock data for responses to routes"
5+
}

0 commit comments

Comments
 (0)