Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds e2e testing #4085

Merged
merged 19 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: runs E2E tests
on:
workflow_run:
workflows: [Get info on PR]
types:
- completed

jobs:
setup_matrix:
runs-on: ubuntu-latest
outputs:
psh_url: ${{ steps.retrieve-url.outputs.psh_url }}
up_url: ${{ steps.retrieve-url.outputs.up_url }}
steps:
- name: Download info on PR
uses: dawidd6/action-download-artifact@v2
with:
workflow: get-urls.yaml
workflow_conclusion: completed
name: pr-info
- name: retrieve url
id: retrieve-url
run: |
PSH_URL=$(cat environment_url.txt)
echo "PSH URL is $PSH_URL"
UP_URL="https://docs.upsun.com.${PSH_URL:8}"
echo "UP URL is ${UP_URL}"
echo "psh_url=$PSH_URL" >> $GITHUB_OUTPUT
echo "up_url=$UP_URL" >> $GITHUB_OUTPUT

run_test:
runs-on: ubuntu-latest
needs: setup_matrix
strategy:
matrix:
include:
- site: platformsh
url: ${{ needs.setup_matrix.outputs.psh_url }}
- site: upsun
url: ${{ needs.setup_matrix.outputs.up_url }}
steps:
- uses: actions/checkout@v4
- uses: cypress-io/github-action@v6
with:
wait-on: ${{ matrix.url }}
record: true
env:
CYPRESS_baseUrl: ${{ matrix.url }}
CYPRESS_environment: github
CYPRESS_site: ${{ matrix.site }}
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ vendorize
vale
vrt-docs-migration
sites/bin
bin
bin
cypress/e2e/1-getting-started
cypress/e2e/2-advanced-examples
22 changes: 22 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const { defineConfig } = require("cypress");

module.exports = defineConfig({
projectId: 'k7k61v',
e2e: {
baseUrl: 'http://localhost:1313/',
env: {
site: 'not set',
environment: "local",
},
setupNodeEvents(on, config) {
// implement node event listeners here
},
blockHosts: [
'www.googletagmanager.com',
'cdn.cookielaw.org',
'cdn.heapanalytics.com',
'heapanalytics.com',
'cdn.matomo.cloud',
],
},
});
142 changes: 142 additions & 0 deletions cypress/e2e/search.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
//Both should return results for "opensearch"
//Only Upsun should return a match for "vertical scaling"
//Only platform should return a match for "24.55 gb"
describe("Searches",()=>{
beforeEach(()=>{
if('local' == Cypress.env('environment')) {
cy.intercept("/indexes/*_docs/search*", { "hits":[] })
}

//cy.visit("/")
})

context("Search tests",()=>{
it("Searches for something that should match in both", () => {
cy.visit("/")
if('local' == Cypress.env('environment')) {
cy.intercept({
pathname: '/indexes/*_docs/search',
query: {
q: 'opensearch'
}
},{ fixture: "opensearchresults" }).as("searchresultsopensearch")
}

cy.get("#searchwicon-header").type("opensearch")

if ('local' == Cypress.env('environment')) {
cy.wait('@searchresultsopensearch')
}

cy.get("#xssroot").find("h2").as("searchresultsheader")
cy.get("@searchresultsheader").should("exist")
cy.get("@searchresultsheader").contains("Documentation")
cy.get("#xssroot").find("li").contains("OpenSearch").should("exist")

cy.get("#searchwicon-header").type("{enter}")
cy.location("pathname").should(
"eq",
"/search.html"
)

cy.get("#xssSearchPage").find("h2").as("searchpageresults")
cy.get("@searchpageresults").should("exist")
cy.get("@searchpageresults").contains("Documentation")

cy.get("#xssSearchPage").find("li").contains("OpenSearch").should("exist")

})

it("Searches for something that should not match on Platformsh, but should on Upsun", ()=>{
const searchDetails = {
search: 'vertical scaling',
header: 'No results',
body: 'No documentation matched'
}

if ('upsun' == Cypress.env('site')) {
searchDetails.header = 'Documentation'
searchDetails.body = searchDetails.search
}

cy.visit("/")
cy.get("#searchwicon-header").type(searchDetails.search)
cy.get("#xssroot").find("h2").as("searchresultsheader")
cy.get("@searchresultsheader").should("exist")
cy.get("@searchresultsheader").contains(searchDetails.header)
cy.get("#xssroot").find("p").contains(searchDetails.body)

cy.get("#searchwicon-header").type("{enter}")
cy.location("pathname").should(
"eq",
"/search.html"
)

cy.get("#xssSearchPage").find("h2").as("searchpageresults")
cy.get("@searchpageresults").should("exist")
if ('upsun' == Cypress.env('site')) {
cy.get("#xssSearchPage").find("li").contains(searchDetails.body).should("exist")
} else {
cy.get("#xssSearchPage").contains(searchDetails.header)
}

})

it("Searches for something that should ONLY match on platformsh, but not on Upsun", () => {
const searchDetails = {
search: '24.55',
header: 'No results',
body: 'No documentation matched'
}

console.log('Current site is ' + Cypress.env('site'))

if ('platformsh' == Cypress.env('site')) {
searchDetails.header = 'Documentation'
searchDetails.body = searchDetails.search
}

cy.visit("/")
if('local' == Cypress.env('environment')) {
cy.intercept({
pathname: '/indexes/*_docs/search',
query: {
q: 'opensearch'
}
},{ fixture: "searchosresults" }).as("searchresultsopensearch")
}

console.log('Pausing before starting')
cy.wait(1000)
console.log('finished pausing')

cy.get("#searchwicon-header").clear().type(searchDetails.search)

if ('local' == Cypress.env('environment')) {
cy.wait('@searchresultsopensearch')
}

cy.get("#xssroot").find("h2").as("searchresultsheader")
cy.get("@searchresultsheader").should("exist")
cy.get("@searchresultsheader").contains(searchDetails.header)
cy.get('#xssroot').find('p').contains(searchDetails.body)

cy.get("#searchwicon-header").type("{enter}")
cy.location("pathname").should(
"eq",
"/search.html"
)

cy.get("#xssSearchPage").find("h2").as("searchpageresults")
cy.get("@searchpageresults").should("exist")
cy.get("@searchpageresults").contains(searchDetails.header)

if ('platformsh' == Cypress.env('site')) {
cy.get("#xssSearchPage").find("li").contains(searchDetails.body).should("exist")
} else {
cy.get("#xssSearchPage").contains(searchDetails.body)
}

})
})
})
5 changes: 5 additions & 0 deletions cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}
Loading
Loading