Skip to content

aktualizace změn #9

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .env.testing
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
BASE_URL=https://team8-2022brno.herokuapp.com
[email protected]
ADMIN_PASSWORD=${ADMIN_PASSWORD}
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Ignore artifacts:
build
coverage
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,55 @@
# Test Automation with Playwright/JavaScript

## Initial setup
First make user you have Node.js 20.8 installed.

First make user you have Node.js 20.8 installed.

If you sue NVM (recommended), tun the following command to set correct version of Node.js:

```
nvm use
```

Then install the dependencies:

```
npm install
```

## Setup environment variables

Create a `.env` file in the root of the project and add the following variables:

```
BASE_URL=https://example.com
ADMIN_USERNAME=admin
ADMIN_PASSWORD=password
```

Change the values to match your environment.

## Running tests

**Run tests in interactive mode (recommended):**

```
npx playwright test --ui
```

**Run tests in headless mode:**

```
npx playwright test
```

**Generate a report:**

```
npx playwright show-report
```

**Update playwright:**

```
npx playwright install
npx playwright install
```
19 changes: 18 additions & 1 deletion package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"@playwright/test": "^1.47.2",
"@types/node": "^20.14.11",
"dotenv": "^16.4.5",
"eslint": "^9.9.1"
"eslint": "^9.9.1",
"prettier": "3.3.3"
},
"scripts": {}
}
23 changes: 11 additions & 12 deletions playwright.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// @ts-check
require('dotenv').config();
require("dotenv").config();

const { defineConfig, devices } = require('@playwright/test');
const { defineConfig, devices } = require("@playwright/test");
const { BASE_URL } = process.env;

/**
* @see https://playwright.dev/docs/test-configuration
*/
module.exports = defineConfig({
testDir: './src/tests',
testDir: "./src/tests",
// testDir: './src/examples',
/* Run tests in files in parallel */
fullyParallel: false,
Expand All @@ -19,27 +19,27 @@ module.exports = defineConfig({
/* 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',
reporter: "html",
/* 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: BASE_URL,

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

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

// {
// name: 'firefox',
// use: { ...devices['Desktop Firefox'] },
// },
{
name: "firefox",
use: { ...devices["Desktop Firefox"] },
},
//
// {
// name: 'webkit',
Expand Down Expand Up @@ -74,4 +74,3 @@ module.exports = defineConfig({
// reuseExistingServer: !process.env.CI,
// },
});

78 changes: 78 additions & 0 deletions src/ZZZ_cviceni/6applications.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { test, expect } from "@playwright/test";
import {
username,
password,
userFullName,
applicationsPageSize,
applicationsSearchText,
} from "../fixtures/fixtures.js";
import { RegExp } from "../fixtures/regular-expressions.js";

test("should login", async ({ page }) => {
await page.goto("/prihlaseni");

// Finding email field, checking if it is enabled and visible
const emailField = page.getByLabel("Email");
console.log("Email field is visible" + (await emailField.isVisible()));
console.log("Email field is enabled" + (await emailField.isEnabled()));

// Finding password field, checking if it is enabled and visible
const passwordField = page.getByLabel("Heslo");
console.log("Password field is visible" + (await passwordField.isVisible()));
console.log("Password field is enabled" + (await passwordField.isEnabled()));

// Finding login button, checking text content
const loginButton = page.getByRole("button", { name: "Přihlásit" });
console.log("Login button text: " + (await loginButton.textContent()));

// Login
await emailField.fill(username);
await passwordField.fill(password);
await loginButton.click();

const currentUser = page.locator(".navbar-right").locator("strong");
await expect(currentUser, "current user should be displayed").toHaveText(
userFullName,
);

await page.goto("/admin/prihlasky");
// Got to applications page
const prihlaskyLink = page.getByRole("link", { name: "Přihlášky" });
console.log("Prihlasky link text: " + (await prihlaskyLink.textContent()));

// Check page title
console.log(
"Přihlášky " +
(await page.getByRole("heading", { level: 1 }).textContent()),
);

// Print all applications
const rows = await page
.locator(".dataTable")
.locator("tbody")
.locator("tr")
.all();
console.log("There are " + rows.length + " rows in the table");
for (const row of rows) {
//console.log(await row.textContent());
const cells = row.locator("td");
console.log(await cells.nth(0).textContent());
}

// Optional: filter the applications table
await page.locator("input[type='search']").fill("mar");
await page.waitForLoadState();

const filteredRows = await page
.locator(".dataTable")
.locator("tbody")
.locator("tr")
.all();

console.log(
"There are " + filteredRows.lenght + " filtered rows in the table",
);
for (const row of filteredRows) {
console.log(await row.textContent("mar"));
}
});
76 changes: 76 additions & 0 deletions src/ZZZ_cviceni/6applicationsUprava.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { expect, test } from "@playwright/test";
import { password, userFullName, username } from "../fixtures/fixtures.js";

async function openLoginPage(page) {
await page.goto("/prihlaseni");
}

async function login(page, username, password) {
const emailField = page.getByLabel("Email");
const passwordField = page.getByLabel("Heslo");
const loginButton = page.getByRole("button", { name: "Přihlásit" });

await emailField.fill(username);
await passwordField.fill(password);
await loginButton.click();
}

async function goToApplications(page) {
await page.goto("/admin/prihlasky");
}

async function getTableRows(page) {
return await page.locator(".dataTable").locator("tbody").locator("tr").all();
}

async function searchInTable(page, searchText) {
const searchInput = page.locator("input[type='search']");
await searchInput.fill(searchText);
}

async function waitForTableToLoad(page) {
await page.waitForLoadState();
}

test("should login and interact with applications", async ({ page }) => {
await openLoginPage(page);
await login(page, username, password);

const currentUser = page.locator(".navbar-right").locator("strong");
await expect(currentUser, "current user should be displayed").toHaveText(
userFullName,
);
await goToApplications(page);

const prihlaskyLink = page.getByRole("link", { name: "Přihlášky" });
console.log("Prihlasky link text: " + (await prihlaskyLink.textContent()));
console.log(
"Přihlášky " +
(await page.getByRole("heading", { level: 1 }).textContent()),
);

const prihlaskyLinkCount = await page
.getByRole("link", { name: "Přihlášky" })
.count();
console.log("Počet odkazů 'Přihlášky': " + prihlaskyLinkCount);

const rows = await getTableRows(page);
console.log("There are " + rows.length + " rows in the table");
for (const row of rows) {
const cells = row.locator("td");
console.log(await cells.nth(0).textContent());
}

await searchInTable(page, "mar");

await waitForTableToLoad(page);

const filteredRows = await getTableRows(page);
console.log(
"There are " + filteredRows.length + " filtered rows in the table",
);
for (const row of filteredRows) {
console.log(await row.textContent());
}
await waitForTableToLoad(page);
});
36 changes: 36 additions & 0 deletions src/ZZZ_cviceni/6login.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { test, expect } from "@playwright/test";
import {
username,
password,
userFullName,
applicationsPageSize,
applicationsSearchText,
} from "../fixtures/fixtures.js";

test("should login", async ({ page }) => {
await page.goto("/prihlaseni");

// Finding email field, checking if it is enabled and visible
const emailField = page.getByLabel("Email");
console.log("Email field is visible" + (await emailField.isVisible()));
console.log("Email field is enabled" + (await emailField.isEnabled()));

// Finding password field, checking if it is enabled and visible
const passwordField = page.getByLabel("Heslo");
console.log("Password field is visible" + (await passwordField.isVisible()));
console.log("Password field is enabled" + (await passwordField.isEnabled()));

// Finding login button, checking text content
const loginButton = page.getByRole("button", { name: "Přihlásit" });
console.log("Login button text: " + (await loginButton.textContent()));

// Login
await emailField.fill(username);
await passwordField.fill(password);
await loginButton.click();

const currentUser = page.locator(".navbar-right").locator("strong");
await expect(currentUser, "current user should be displayed").toHaveText(
userFullName,
);
});
Loading