-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(create-echoed): create templates for Playwright's YAML
- Loading branch information
Showing
24 changed files
with
518 additions
and
141 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
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,14 @@ | ||
# What is this directory? | ||
|
||
This `example` directory serves as a reference implementation for running Echoed's tests. | ||
For instance, `test/manual.test.ts` makes a request to http://localhost:8080/api/cart, and it asserts that the response returns with a status code of 200. | ||
|
||
Feel free to remove this `example` directory once you are ready to create your own tests. | ||
|
||
## Usage | ||
|
||
1. Start server: Move to `example` directory and start DockerCompose by `make start`. | ||
2. Run tests: Move to parent directory and execute `npm run compile` to create tests from YAMLs and `npm run test` to run Jest. | ||
3. Stop server: Move to `example` directory and stop DockerCompose by `make stop`. | ||
|
||
Note: The server utilizes a modified version of the code from [opentelemetry-demo](https://github.com/open-telemetry/opentelemetry-demo) which sends OpenTelemetry's data to `host.docker.internal:3000`, and it can be launched from DockerCompose. |
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
3 changes: 3 additions & 0 deletions
3
create-echoed/template/playwright-no-otel/.instruction/copy.json
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,3 @@ | ||
{ | ||
"from": "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,33 @@ | ||
# Echoed with Playwright | ||
|
||
This template provides a minimal setup to run Playwright after compiling YAML to Playwright tests by Echoed. | ||
The example demonstrates tests written in YAML and TypeScript. | ||
|
||
Feel free to remove the `example` directory once you've familiarized yourself and start crafting your own tests. | ||
|
||
# How to Run Example Tests | ||
|
||
Follow these steps to run the example tests in action: | ||
|
||
1. **Setup:** Set up the necessary dependencies. | ||
```sh | ||
npm install | ||
npx playwright install | ||
sudo npx playwright install-deps | ||
``` | ||
2. **Start Server:** Navigate to the `example` directory and start the Dockerized server. | ||
```sh | ||
cd example | ||
make start | ||
``` | ||
3. **Open Website**: Check the server is running by opening http://localhost:8080 in your browser. | ||
4. **Run Test:** In project's root directory, Run the tests after compiling YAML to Playwright tests. | ||
```sh | ||
cd ../ | ||
npm run compile && npm run test | ||
``` | ||
5. **Stop Server:** After testing, stop the server in the `example` directory. | ||
```sh | ||
cd example | ||
make stop | ||
``` |
15 changes: 15 additions & 0 deletions
15
create-echoed/template/playwright-no-otel/example/.echoed.yml
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,15 @@ | ||
scenario: | ||
compile: | ||
targets: | ||
- yamlDir: example/test/scenario | ||
outDir: example/test/scenario_gen | ||
type: playwright | ||
useEchoedFeatures: false | ||
cleanOutDir: true | ||
env: | ||
BASE_ENDPOINT: http://localhost:8080 | ||
plugin: | ||
commons: | ||
- names: | ||
- getSession | ||
module: "@/example/util/session" |
14 changes: 14 additions & 0 deletions
14
create-echoed/template/playwright-no-otel/example/README.md
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,14 @@ | ||
# What is this directory? | ||
|
||
This `example` directory serves as a reference implementation for running Echoed's tests. | ||
For instance, `test/scenario/home.yaml` visits http://localhost:8080, and it asserts that the page contains expected DOM elements. | ||
|
||
Feel free to remove this `example` directory once you are ready to create your own tests. | ||
|
||
## Usage | ||
|
||
1. Start server: Move to `example` directory and start DockerCompose by `make start`. | ||
2. Run tests: Move to parent directory and execute `npm run compile` to create tests from YAMLs and `npm run test` to run Playwright. | ||
3. Stop server: Move to `example` directory and stop DockerCompose by `make stop`. | ||
|
||
Note: The server utilizes a modified version of the code from [opentelemetry-demo](https://github.com/open-telemetry/opentelemetry-demo) which sends OpenTelemetry's data to `host.docker.internal:3000`, and it can be launched from DockerCompose. |
41 changes: 41 additions & 0 deletions
41
create-echoed/template/playwright-no-otel/example/test/advanced.test.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,41 @@ | ||
import { expect, test } from "@playwright/test"; | ||
|
||
test("should Open page", async ({ page }) => { | ||
await page.goto("http://localhost:8080/"); | ||
await expect(page).toHaveTitle("OTel demo"); | ||
|
||
const productList = page.locator("[data-cy=product-card]"); | ||
await expect(productList).toHaveCount(10); | ||
}); | ||
|
||
test("shoud create request with context.request", async ({ context }) => { | ||
const response = await context.request.get( | ||
`http://localhost:8080/api/products`, | ||
); | ||
expect(response.status()).toBe(200); | ||
expect((await response.json()).length).toEqual(10); | ||
}); | ||
|
||
test("shoud create request with request.get", async ({ request }) => { | ||
const response = await request.get(`http://localhost:8080/api/products`); | ||
expect(response.status()).toBe(200); | ||
expect((await response.json()).length).toEqual(10); | ||
}); | ||
|
||
test("shoud create request with playwright.request.newContext", async ({ | ||
playwright, | ||
}) => { | ||
const apiContext = await playwright.request.newContext({ | ||
baseURL: "http://localhost:8080", | ||
}); | ||
|
||
const response = await apiContext.get(`/api/products`); | ||
expect(response.status()).toBe(200); | ||
expect((await response.json()).length).toEqual(10); | ||
}); | ||
|
||
test("shoud create request with fetch", async () => { | ||
const response = await fetch(`http://localhost:8080/api/products`); | ||
expect(response.status).toBe(200); | ||
expect((await response.json()).length).toEqual(10); | ||
}); |
48 changes: 48 additions & 0 deletions
48
create-echoed/template/playwright-no-otel/example/test/scenario/checkout.yml
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,48 @@ | ||
use: | ||
baseURL: ${_env.BASE_ENDPOINT} | ||
hook: | ||
beforeEach: | ||
- fixtures: | ||
- page | ||
raw: await page.goto("/") | ||
scenarios: | ||
- name: Checkout Flow | ||
fixtures: | ||
- page | ||
steps: | ||
- description: Add product to cart | ||
arrange: | ||
- await page.locator("[data-cy=product-card]").first().click() | ||
act: | ||
raw: await page.locator("[data-cy=product-add-to-cart]").first().click() | ||
assert: | ||
- expectPageToHaveURL: ${/\/cart$/} | ||
- expectToContainText: | ||
selector: "[data-cy=cart-item-count]" | ||
expected: "1" | ||
- description: Add another product to cart | ||
arrange: | ||
- await page.goto("/") | ||
- await page.locator("[data-cy=product-card]").last().click() | ||
act: | ||
raw: await page.locator("[data-cy=product-add-to-cart]").click() | ||
assert: | ||
- expectPageToHaveURL: ${/\/cart$/} | ||
- expectToContainText: | ||
selector: "[data-cy=cart-item-count]" | ||
expected: "2" | ||
- description: Go to cart page | ||
arrange: | ||
- await page.locator("[data-cy=cart-icon]").click() | ||
act: | ||
raw: await page.locator("[data-cy=cart-go-to-shopping]").click() | ||
assert: | ||
- expectPageToHaveURL: ${/\/cart$/} | ||
- description: Checkout | ||
act: | ||
raw: await page.locator("[data-cy=checkout-place-order]").click() | ||
assert: | ||
- expectPageToHaveURL: ${/\/checkout/} | ||
- expectToHaveCount: | ||
selector: "[data-cy=checkout-item]" | ||
count: 2 |
39 changes: 39 additions & 0 deletions
39
create-echoed/template/playwright-no-otel/example/test/scenario/home.yml
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,39 @@ | ||
use: | ||
baseURL: ${_env.BASE_ENDPOINT} | ||
hook: | ||
beforeEach: | ||
- fixtures: | ||
- page | ||
raw: await page.goto("/") | ||
scenarios: | ||
- name: Validate Homepage | ||
fixtures: | ||
- page | ||
steps: | ||
- description: Check product list is shown | ||
arrange: | ||
- expectToBeVisible: "[data-cy=home-page]" | ||
assert: | ||
- expectToHaveCount: | ||
selector: "[data-cy=product-list] [data-cy=product-card]" | ||
count: 10 | ||
- description: Check session is set | ||
variable: | ||
session: ${await getSession(page)} | ||
assert: | ||
- expectToContainText: | ||
selector: "[data-cy=session-id]" | ||
expected: ${session.userId} | ||
- name: Homepage can change currency | ||
fixtures: | ||
- page | ||
steps: | ||
- description: Change currency to EUR | ||
arrange: | ||
- expectToBeVisible: "[data-cy=home-page]" | ||
act: | ||
raw: await page.locator("[data-cy=currency-switcher]").selectOption("EUR"); | ||
assert: | ||
- expectToContainText: | ||
selector: "[data-cy=product-card]:first-child" | ||
expected: "€" |
49 changes: 49 additions & 0 deletions
49
create-echoed/template/playwright-no-otel/example/test/scenario/productDetail.yml
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,49 @@ | ||
use: | ||
baseURL: ${_env.BASE_ENDPOINT} | ||
hook: | ||
beforeEach: | ||
- fixtures: | ||
- page | ||
raw: await page.goto("/") | ||
scenarios: | ||
- name: Product Detail Page is valid | ||
fixtures: | ||
- page | ||
steps: | ||
- description: Product Detail Page is shown | ||
act: | ||
raw: await page.locator("[data-cy=product-card]").first().click() | ||
assert: | ||
- expectToBeVisible: "[data-cy=product-detail]" | ||
- expectToBeVisible: "[data-cy=product-picture]" | ||
- expectToBeVisible: "[data-cy=product-name]" | ||
- expectToBeVisible: "[data-cy=product-description]" | ||
- expectToBeVisible: "[data-cy=product-add-to-cart]" | ||
- expectToHaveCount: | ||
selector: "[data-cy=recommendation-list] [data-cy=product-card]" | ||
count: 4 | ||
- expectToBeVisible: "[data-cy=ad]" | ||
- name: Product Detail Page is working | ||
fixtures: | ||
- page | ||
steps: | ||
- description: Product Detail Page is shown | ||
act: | ||
raw: await page.locator("[data-cy=product-card]").first().click() | ||
assert: | ||
- await expect(page).toHaveURL(/\/product\//); | ||
- description: Add product to cart | ||
act: | ||
raw: await page.locator("[data-cy=product-add-to-cart]").click() | ||
assert: | ||
- await expect(page).toHaveURL(/\/cart$/); | ||
- expectToHaveCount: | ||
selector: "[data-cy=cart-item-count]" | ||
count: 1 | ||
- description: Cart dropdown shows the item too | ||
act: | ||
raw: await page.locator("[data-cy=cart-icon]").click() | ||
assert: | ||
- expectToHaveCount: | ||
selector: "[data-cy=cart-dropdown-item]" | ||
count: 1 |
Oops, something went wrong.