-
-
Notifications
You must be signed in to change notification settings - Fork 632
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(counters_stable): add playwright tests (#1235)
- Loading branch information
Showing
21 changed files
with
537 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
extend = [{ path = "../cargo-make/playwright.toml" }] | ||
|
||
[tasks.test-e2e] | ||
dependencies = ["setup-node", "test-playwright-autostart"] | ||
|
||
[tasks.clean-all] | ||
dependencies = ["clean-cargo", "clean-node_modules", "clean-playwright"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
[tasks.clean-playwright] | ||
description = "Delete playwright directories" | ||
category = "Cleanup" | ||
script = ''' | ||
for pw_dir in $(find . -name playwright.config.ts | xargs dirname) | ||
do | ||
rm -rf $pw_dir/playwright-report pw_dir/playwright pw_dir/test-results | ||
done | ||
''' | ||
|
||
[tasks.test-playwright-autostart] | ||
description = "Run playwright test with server autostart" | ||
category = "Test" | ||
command = "npm" | ||
args = ["run", "e2e:auto-start"] | ||
|
||
[tasks.test-playwright] | ||
description = "Run playwright test" | ||
category = "Test" | ||
script = ''' | ||
BOLD="\e[1m" | ||
GREEN="\e[0;32m" | ||
RED="\e[0;31m" | ||
RESET="\e[0m" | ||
project_dir=$CARGO_MAKE_WORKING_DIRECTORY | ||
# Discover commands | ||
if command -v pnpm; then | ||
PLAYWRIGHT_CMD=pnpm | ||
elif command -v npm; then | ||
PLAYWRIGHT_CMD=npx | ||
else | ||
echo "${RED}${BOLD}ERROR${RESET} - pnpm or npm is required by this task" | ||
exit 1 | ||
fi | ||
# Run playwright command | ||
for pw_path in $(find . -name playwright.config.ts) | ||
do | ||
pw_dir=$(dirname $pw_path) | ||
cd $pw_dir | ||
${PLAYWRIGHT_CMD} playwright test | ||
cd $project_dir | ||
done | ||
''' | ||
|
||
[tasks.test-playwright-ui] | ||
description = "Run playwright test --ui" | ||
category = "Test" | ||
script = ''' | ||
BOLD="\e[1m" | ||
GREEN="\e[0;32m" | ||
RED="\e[0;31m" | ||
RESET="\e[0m" | ||
project_dir=$CARGO_MAKE_WORKING_DIRECTORY | ||
# Discover commands | ||
if command -v pnpm; then | ||
PLAYWRIGHT_CMD=pnpm | ||
elif command -v npm; then | ||
PLAYWRIGHT_CMD=npx | ||
else | ||
echo "${RED}${BOLD}ERROR${RESET} - pnpm or npm is required by this task" | ||
exit 1 | ||
fi | ||
# Run playwright command | ||
for pw_path in $(find . -name playwright.config.ts) | ||
do | ||
pw_dir=$(dirname $pw_path) | ||
cd $pw_dir | ||
${PLAYWRIGHT_CMD} playwright test --ui | ||
cd $project_dir | ||
done | ||
''' | ||
|
||
[tasks.test-playwright-report] | ||
description = "Run playwright show-report" | ||
category = "Test" | ||
script = ''' | ||
BOLD="\e[1m" | ||
GREEN="\e[0;32m" | ||
RED="\e[0;31m" | ||
RESET="\e[0m" | ||
project_dir=$CARGO_MAKE_WORKING_DIRECTORY | ||
# Discover commands | ||
if command -v pnpm; then | ||
PLAYWRIGHT_CMD=pnpm | ||
elif command -v npm; then | ||
PLAYWRIGHT_CMD=npx | ||
else | ||
echo "${RED}${BOLD}ERROR${RESET} - pnpm or npm is required by this task" | ||
exit 1 | ||
fi | ||
# Run playwright command | ||
for pw_path in $(find . -name playwright.config.ts) | ||
do | ||
pw_dir=$(dirname $pw_path) | ||
cd $pw_dir | ||
${PLAYWRIGHT_CMD} playwright show-report | ||
cd $project_dir | ||
done | ||
''' | ||
|
||
# ALIASES | ||
|
||
[tasks.pw] | ||
dependencies = ["test-playwright"] | ||
|
||
[tasks.pw-ui] | ||
dependencies = ["test-playwright-ui"] | ||
|
||
[tasks.pw-report] | ||
dependencies = ["test-playwright-report"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[tasks.build] | ||
command = "trunk" | ||
args = ["build"] | ||
|
||
[tasks.clean-trunk] | ||
command = "trunk" | ||
args = ["clean"] | ||
|
||
[tasks.start-trunk] | ||
command = "trunk" | ||
args = ["serve", "--open"] | ||
|
||
[tasks.stop-trunk] | ||
script = ''' | ||
pkill -f "cargo-make" | ||
pkill -f "trunk" | ||
''' | ||
|
||
# ALIASES | ||
|
||
[tasks.dev] | ||
dependencies = ["start-trunk"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Generated by Cargo | ||
# will have compiled files and executables | ||
/target/ | ||
|
||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries | ||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html | ||
Cargo.lock | ||
|
||
# These are backup files generated by rustfmt | ||
**/*.rs.bk | ||
|
||
# Support playwright testing | ||
node_modules/ | ||
test-results/ | ||
end2end/playwright-report/ | ||
playwright/.cache/ | ||
pnpm-lock.yaml | ||
|
||
# Support trunk | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules/ | ||
/test-results/ | ||
/playwright-report/ | ||
/playwright/.cache/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"private": "true", | ||
"scripts": {}, | ||
"devDependencies": { | ||
"@playwright/test": "^1.35.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { defineConfig, devices } from "@playwright/test"; | ||
|
||
/** | ||
* Read environment variables from file. | ||
* https://github.com/motdotla/dotenv | ||
*/ | ||
// require('dotenv').config(); | ||
|
||
/** | ||
* See https://playwright.dev/docs/test-configuration. | ||
*/ | ||
export default defineConfig({ | ||
testDir: "./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 ? 10 : 10, | ||
/* Opt out of parallel tests on CI. */ | ||
workers: process.env.CI ? 1 : 1, | ||
/* Reporter to use. See https://playwright.dev/docs/test-reporters */ | ||
reporter: "list", | ||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ | ||
use: { | ||
/* Base URL to use in actions like `await page.goto('/')`. */ | ||
baseURL: "http://127.0.0.1:8080", | ||
|
||
/* 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"] }, | ||
// }, | ||
|
||
/* Test against mobile viewports. */ | ||
// { | ||
// name: 'Mobile Chrome', | ||
// use: { ...devices['Pixel 5'] }, | ||
// }, | ||
// { | ||
// name: 'Mobile Safari', | ||
// use: { ...devices['iPhone 12'] }, | ||
// }, | ||
|
||
/* Test against branded browsers. */ | ||
// { | ||
// name: 'Microsoft Edge', | ||
// use: { ...devices['Desktop Edge'], channel: 'msedge' }, | ||
// }, | ||
// { | ||
// name: 'Google Chrome', | ||
// use: { ..devices['Desktop Chrome'], channel: 'chrome' }, | ||
// }, | ||
], | ||
|
||
/* Run your local dev server before starting the tests */ | ||
// webServer: { | ||
// command: "cd ../ && trunk serve", | ||
// url: "http://127.0.0.1:8080", | ||
// reuseExistingServer: false, //!process.env.CI, | ||
// }, | ||
}); |
23 changes: 23 additions & 0 deletions
23
examples/counters_stable/e2e/tests/add_1k_counters.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { test, expect } from "@playwright/test"; | ||
import { CountersPage } from "./counters_page"; | ||
|
||
test.describe("Add 1000 Counters", () => { | ||
test("should increment the total count by 1K", async ({ page }) => { | ||
const ui = new CountersPage(page); | ||
await ui.goto(); | ||
|
||
// FIXME: Uncomment to make the test fail consistently | ||
|
||
await ui.addOneThousandCounters(); | ||
// await expect(ui.total).toHaveText("0"); | ||
// await expect(ui.counters).toHaveText("1000"); | ||
|
||
await ui.addOneThousandCounters(); | ||
// await expect(ui.total).toHaveText("0"); | ||
// await expect(ui.counters).toHaveText("2000"); | ||
|
||
await ui.addOneThousandCounters(); | ||
await expect(ui.total).toHaveText("0"); | ||
await expect(ui.counters).toHaveText("3000"); | ||
}); | ||
}); |
Oops, something went wrong.