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

Complete SDET assignment #7

Open
wants to merge 7 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
66 changes: 66 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Playwright Tests CI

on:
push:
branches:
- mariia-iakovenko
- 'release/*'
- 'feature/*'
pull_request:
branches:
- mariia-iakovenko
- 'release/*'
- 'feature/*'

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: lts/*

- name: Install dependencies
run: npm install

- name: Load environment variables from test.env
run: |
cp env/test.env .env
export $(grep -v '^#' .env | xargs)

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

- name: Run Playwright tests
env:
TEST_ENV: test
run: npx playwright test --reporter=html

- name: Compress the report
if: always()
run: |
zip -r playwright-report.zip playwright-report/

- name: Upload Playwright Report to Artifactory
if: always()
uses: actions/upload-artifact@v4
with:
name: playwright-report
path: playwright-report.zip

- name: Upload ZIP to Uploadcare
if: always()
run: |
curl -X POST \
-F "UPLOADCARE_STORE=1" \
-F "UPLOADCARE_PUB_KEY=$UPLOADCARE_PUB_KEY" \
-F "file=@playwright-report.zip" \
https://upload.uploadcare.com/base/

- name: Cleanup
run: rm -rf playwright-report.zip playwright-report/
25 changes: 25 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Node modules
node_modules/

# Playwright artifacts
test-results/
playwright-report/
playwright/.cache/

# Log files
*.log

# Build artifacts
dist/
build/

# Playwright storage state
storageState.json
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
7 changes: 7 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": []
}
90 changes: 90 additions & 0 deletions components/form.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
const HomePage = require("../pages/home-page");

/** Form class with functions to populate a form with fields. Currently is used for Signup/Login test */

class Form extends HomePage {
/**Locators */
getSelectOption(optionName) {
return this.page.getByRole("option").filter({ hasText: optionName });
}

/**
* Populates a form with the given fields.
*
* @param {Object[]} fields An array of field objects, each with the following properties:
* @property {string} type The type of field, such as `text` or `select`.
* @property {string} label The label of the field.
* @property {string|number|boolean} value The value of the field.
* @returns {Promise<void>} A promise that resolves when the form has been populated.
* @throws {Error} If an error occurs while populating the form.
*/
async populateForm(fields) {
let field;
try {
for (field of fields) {
await this.setField(field.type, field.label, field.value);
}
} catch (error) {
throw new Error(`Unable to set field: ${error.message}, ${error.stack}`);
}
}

/**
* Sets the value of a field.
*
* @param {string} fieldType The type of field (text, select, dropdown, money, date, lookup, and toggle)
* @param {string} label The label of the field.
* @param {string} value The value to set.
* @throws {Error} If the field type is not supported.
*/
async setField(fieldType, label, value) {
switch (fieldType.toLowerCase()) {
case "text":
await this.setTextField(label, value);
break;
case "select":
await this.setSelectField(label, value);
break;
default:
throw new Error(`${fieldType} is not a supported field type`);
}
}

/**
* Sets the value of a form text field.
* @param {string} label The label of the text field.
* @param {string} value The value to set the text field to.
* @throws {Error} If the text field cannot be found or cannot be set.
*/
async setTextField(label, value) {
try {
const field = this.page.getByLabel(label);
await field.clear();
await field.fill(value);
} catch (error) {
throw new Error(
`Unable to set field ${label}: ${error.message}, ${error.stack}`
);
}
}

/**
* Sets the value of a form select field.
* @param {string} label The label of the select field.
* @param {string} value The value to set the select field to.
* @throws {Error} If the select field cannot be found or cannot be set.
*/
async setSelectField(label, value) {
try {
const element = this.page.getByLabel(label);
await element.click();
await this.getSelectOption(value).click();
} catch (error) {
throw new Error(
`Unable to set field ${label}: ${error.message}, ${error.stack}`
);
}
}
}

module.exports = Form;
8 changes: 8 additions & 0 deletions env/test.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Variables set here are related to the test environment

# CREXI
URL=https://www.crexi.com/
PROFILE_URL=https://www.crexi.com/dashboard/profile
PROPERTY_RECORDS_URL=https://www.crexi.com/property-records/search
TEST_EMAIL=iakovenko.maria@gmail.com
TEST_PASSWORD=vagaBE?EHiG3Pr9c
171 changes: 171 additions & 0 deletions package-lock.json

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

12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"dependencies": {
"@faker-js/faker": "^9.0.0",
"dotenv": "^16.4.5",
"playwright": "^1.47.0"
},
"devDependencies": {
"@playwright/test": "^1.47.0",
"@types/node": "^22.5.4"
},
"scripts": {}
}
Loading