Skip to content

Commit

Permalink
playwright test automation framework
Browse files Browse the repository at this point in the history
  • Loading branch information
BakkappaN committed Feb 5, 2024
0 parents commit ddf9ff6
Show file tree
Hide file tree
Showing 15 changed files with 539 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ENV=qa
URL=https://www.google.com/
USER_NAME=1234DF
PASSWORD=DFGHJK67

API_BASE_URI=https://restful-booker.herokuapp.com
27 changes: 27 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Playwright Tests
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- 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: playwright-report/
retention-days: 30
5 changes: 5 additions & 0 deletions .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/
137 changes: 137 additions & 0 deletions package-lock.json

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

20 changes: 20 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "playwrightbaseautomationframework",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@faker-js/faker": "^8.4.0",
"@playwright/test": "^1.41.2",
"@types/node": "^20.11.16"
},
"dependencies": {
"csv-parse": "^5.5.3",
"dotenv": "^16.4.1",
"luxon": "^3.4.4"
}
}
31 changes: 31 additions & 0 deletions pages/homepage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Inlcude playwright module
const { expect } = require('@playwright/test')

// create class
exports.HomePage = class HomePage {

/**
*
* @param {import ('@playwright/test').Page} page
*/
constructor(page){
// Init page object
this.page = page;

// Elements
this.searchTextbox = page.locator('#APjFqb');
}

async goto(){
await this.page.setViewportSize({width:1366, height:728})
await this.page.goto(process.env.URL);
}

async searchKeywords(param1){
await expect(this.searchTextbox).toBeEnabled();
await this.searchTextbox.click();
await this.searchTextbox.fill(param1);
await this.searchTextbox.press('Enter');
}

}
25 changes: 25 additions & 0 deletions pages/playlistpage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Inlcude playwright module
const { expect } = require('@playwright/test')

// create class
exports.PlaylistPage = class PlaylistPage {

/**
*
* @param {import ('@playwright/test').Page} page
*/
constructor(page){
// Init page object
this.page = page;

// Elements
this.videoLink = page.locator('#container > #thumbnail');
}

async clickOnVideo(){
await this.page.waitForTimeout(3000);
await expect(this.videoLink.first()).toBeEnabled();
await this.videoLink.first().click();
}

}
24 changes: 24 additions & 0 deletions pages/resultpage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Inlcude playwright module
const { expect } = require('@playwright/test')

// create class
exports.ResultPage = class ResultPage {

/**
*
* @param {import ('@playwright/test').Page} page
*/
constructor(page){
// Init page object
this.page = page;

// Elements
this.playlistlink = page.getByRole('link',{name:'Playwright by Testers Talk'});
}

async clickOnPlaylist(){
await expect(this.playlistlink.first()).toBeEnabled();
await this.playlistlink.first().click();
}

}
95 changes: 95 additions & 0 deletions playwright.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// @ts-check
const { defineConfig, devices } = require('@playwright/test');

// Read environment variables from file.
require('dotenv').config();

/**
* @see more at https://bit.ly/playwright-tutorial-automation-testing
*/
module.exports = defineConfig({
// test timeout
timeout: 5 * 60 * 1000,

testDir: './tests',
/* Run tests in files in parallel */
fullyParallel: false,
/* 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 : 1,
// Reporter
reporter:[
['html'],
// ['allure-playwright'],
['junit', { outputFile: 'test-results/e2e-junit-results.xml' }],
],

use: {
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://127.0.0.1:3000',

// launchOptions: {
// args: ["--start-fullscreen"]
// },

// video, screenshot, headless mode
video:'on',
screenshot: 'on',
headless : false,

// custom attribute
testIdAttribute: 'autocomplete',

// Collect trace when retrying the failed test
trace: 'on',
},

/* 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: 'npm run start',
// url: 'http://127.0.0.1:3000',
// reuseExistingServer: !process.env.CI,
// },
});
11 changes: 11 additions & 0 deletions test-data/api-requests/post_request_body.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"firstname": "testers talk playwright",
"lastname": "testers talk api testing",
"totalprice": 1000,
"depositpaid": true,
"bookingdates": {
"checkin": "2024-01-01",
"checkout": "2024-02-01"
},
"additionalneeds": "super bowls"
}
Loading

0 comments on commit ddf9ff6

Please sign in to comment.