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

WIP - Adding Playwright Tests #8805

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
32e5198
adding todo
stevector Dec 18, 2023
4afb15f
playwright stuff
stevector Dec 18, 2023
c93467e
github actions tweaks
stevector Dec 18, 2023
25e2dc4
more echos
stevector Dec 18, 2023
4d657f1
trying another way of getting the sha
stevector Dec 18, 2023
38f83cc
githead.txt
stevector Dec 18, 2023
c3f1797
check githead
stevector Dec 18, 2023
666eb81
trying to unbreak test
stevector Dec 18, 2023
3db6fda
curl githead
stevector Dec 18, 2023
3a59239
adding video recording
stevector Dec 18, 2023
a3bd466
removing commented out stuff
stevector Dec 19, 2023
e5ee858
moving test location
stevector Dec 19, 2023
778fe47
set tests directory default again
stevector Dec 19, 2023
08168fe
updating comments
stevector Dec 19, 2023
0b9e112
adding polling
stevector Dec 19, 2023
3c24fc5
debug polling
stevector Dec 19, 2023
f582b34
checking body
stevector Dec 19, 2023
8374bc2
wait 10 minutes
stevector Dec 19, 2023
36eb6d1
plain sha
stevector Dec 19, 2023
7977119
checking pr
stevector Dec 19, 2023
ec6b051
trying again with polling
stevector Dec 19, 2023
0c3a12b
checking sha again
stevector Dec 19, 2023
128514f
put hash in file name
stevector Dec 19, 2023
38c248a
check whole body, not regex
stevector Dec 19, 2023
9731b28
retrigger
stevector Dec 19, 2023
6185d66
check the plain file
stevector Dec 19, 2023
d79dac5
trigger again
stevector Dec 19, 2023
ddf9a37
trying another combo
stevector Dec 19, 2023
46e85ea
trigger CI
stevector Dec 19, 2023
40d37d1
trigger CI
stevector Dec 19, 2023
8adfbd3
checking search results
stevector Dec 20, 2023
4080cd2
comment out polling
stevector Dec 20, 2023
c477bb3
more generic check
stevector Dec 20, 2023
4f82807
Update gatsby-node.js
stevector Apr 1, 2024
054149b
Merge remote-tracking branch 'origin/main' into playwright-tests
stevector May 13, 2024
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
57 changes: 57 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Playwright Tests
# todo, this GitHub Action should either be Triggered by Pantheon's build process
# phoning back to GitHub Actions after the deployment completes
# Or the GitHub Action will need to poll somehow that the deployment has completed.
# The Gatsby Build Process could place a file that reports that Git Hash that it was
# built from. Check that via polling.
# consider this for polling. https://github.com/artiz/poll-endpoint
# https://github.com/marketplace/actions/poll-endpoint
on:
pull_request:
branches: [ main, master ]
env:
GITHUB_PR_NUMBER: ${{ github.event.number }}
# @todo figure out how to make this work on main.
GIT_SHA: ${{ github.event.pull_request.head.sha }}

jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./tests
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- name: Print Commit SHA
run: echo $GIT_SHA
- name: Check githead
run: curl https://pr-${GITHUB_PR_NUMBER}-documentation.appa.pantheon.site/githead.txt

# @todo, this is a hack to get the githead from the build process.
# - uses: artiz/[email protected]
# with:
# url: https://pr-${{ github.event.number }}-documentation.appa.pantheon.site/githead-${{ github.event.pull_request.head.sha }}.txt
# method: GET
# expectStatus: 200
# expectBody: ${{ github.event.pull_request.head.sha }}
# #expectBodyRegex: "git commit"
# timeout: 600000
# interval: 5000

- name: Install dependencies
run: npm ci
- name: Install Playwright Browsers
run: npx playwright install --with-deps

- name: Run Playwright tests
run: npx playwright test
- uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: tests/playwright-report/
retention-days: 30
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ typings/
.cache/
public

# This file is made during the build process. It is used to determine the current git commit hash.
static/githead.txt

# Mac files
.DS_Store

Expand Down
4 changes: 4 additions & 0 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,10 @@ exports.onCreateNode = ({ node, getNode, actions }) => {
}
}

/**
* Todo, create a page for the git hash.
*/

// Releases and Changelog Content
var nodeString = node.internal.type.toString()
var isReleaseJson = nodeString.includes("ReleasesJson")
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@
"node": ">=18.0.0 <20.0.0"
},
"scripts": {
"build": "gatsby build --prefix-paths --log-pages",

"build": "echo $(git rev-parse HEAD) > static/githead-$(git rev-parse HEAD).txt && gatsby build --prefix-paths --log-pages",
"develop": "gatsby develop",
"format": "prettier --write src/**/*.{js,jsx}",
"start": "npm run develop",
Expand Down
5 changes: 5 additions & 0 deletions tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
91 changes: 91 additions & 0 deletions tests/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions tests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "tests",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@playwright/test": "^1.40.1",
"@types/node": "^20.10.5"
}
}
38 changes: 38 additions & 0 deletions tests/playwright-tests/example.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { test, expect } from '@playwright/test';

test('has title', async ({ page }) => {
await page.goto('/certification');
// Expect a title "to contain" a substring.
await expect(page).toHaveTitle(/Certification Program/);

/* @todo, add a test of Searching */
});

test('Use Search Form', async ({ page }) => {
await page.goto('/');
// Enter the word "Terminus" into the search box.
await page.fill('#searchform input', 'Terminus');
// Submit the form
await page.press('#searchform input', 'Enter');
// Check that the page contains "Introduction | Terminus Guide | Pantheon Docs"
//
//const searchResults = page.getByTestId('h3 a').nth(0);

// const searchResults = page.getByClassName('search-results').nth(0);
// await expect(searchResults).toHaveText('Terminus Platform Support');

const firstResult = await page.locator('h3 a')
.filter({ hasText: "Terminus Platform Support" }) //orderID in variable
//.getByRole('span', { hasText: 'Queued' })


await firstResult.click();

// check that the current path is guides/platform-considerations/terminus-platform
// ignore the base URL.
// await expect(page).toHaveURL('https://docs.pantheon.io/guides/platform-considerations/terminus-platform');
// check that the current path contains guides/platform-considerations/terminus-platform
await expect(page).toHaveURL(/guides\/platform-considerations\/terminus-platform/);


});
53 changes: 53 additions & 0 deletions tests/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { defineConfig, devices } from '@playwright/test';

/* todo, decide whether or not to use dotenv */
/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './playwright-tests',
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
video: 'on',
/* Base URL to use in actions like `await page.goto('/')`. */
// TODO, update this url to handle building on the main branch.
baseURL: process.env.GITHUB_PR_NUMBER ? 'https://pr-' + process.env.GITHUB_PR_NUMBER + '-documentation.appa.pantheon.site' : 'http://localhost:8000',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},

/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},

{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
},

{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
},
],
});
Loading
Loading