Run Playwright tests on QA, Staging & PROD Environments
Run playwright test on QA, Staging or PROD environments

Run Playwright tests on QA, Staging & PROD Environments

This is an example how we need to utilize automation effectively by running automated tests on different environments such as QA or Dev or Staging or PROD to make sure of the good quality of the product and in a simplest way explained below.




1. Create test-data folder then create 2 environment folder such as qa & stage then create JSON files in each environment.


playwright by testers talk
2. Add the below content in qa->google.json file
{
    "qaTestData":{
        "skill1":"playwright by testers talk",
        "skill2":"cypress by testers talk",
        "skill3":"javascript by testers talk",
        "skill4":"postman by testers talk",
        "skill5":"rest assured by testers talk",
        "skill6":"specflow by testers talk",
        "skill7":"easyrepro by testers talk",
        "skill8":"api testing by testers talk"
    }
}        
3. Add the below content in stage->google.json file
{
    "stageTestData":{
        "skill1":"cypress by testers talk",
        "skill2":"playwright by testers talk",
        "skill3":"javascript by testers talk",
        "skill4":"postman by testers talk",
        "skill5":"rest assured by testers talk",
        "skill6":"specflow by testers talk",
        "skill7":"easyrepro by testers talk",
        "skill8":"api testing by testers talk"
    }
}        
4. Set required in environment in .env file.
ENV=qa        
5. Create a spec file and import stage->google.json & qa->google.json file.
import { qaTestData } from '../test-data/qa/google.json';
import { stageTestData } from '../test-data/stage/google.json';        
6. Read test data based on environment value passed from .env file
let testData = null;

test.beforeAll('Running before all tests', () => {
    if (process.env.ENV == 'qa') {
        testData = qaTestData;
    } else {
        testData = stageTestData;
    }
})        
7. Create a test which open browser & searches with some keywords.
// Write a test
test('Read Test data based on different env in playwright ', async ({ page }) => {
    // Go to URL
    await page.goto(process.env.URL);

    // search with keywords
    await page.locator('#APjFqb').click();
    await page.locator('#APjFqb').fill(testData.skill1);
    await page.locator('#APjFqb').press('Enter');
    await page.waitForTimeout(5000);
})        
8. Now this is how whole playwright spec file looks like.
// Include playwright module
const { test, expect } = require('@playwright/test');
import { qaTestData } from '../test-data/qa/google.json';
import { stageTestData } from '../test-data/stage/google.json';

let testData = null;

test.beforeAll('Running before all tests', () => {
    if (process.env.ENV == 'qa') {
        testData = qaTestData;
    } else {
        testData = stageTestData;
    }
})

// Write a test
test('Read Test data based on different env in playwright ', async ({ page }) => {
    // Go to URL
    await page.goto(process.env.URL);

    // search with keywords
    await page.locator('#APjFqb').click();
    await page.locator('#APjFqb').fill(testData.skill1);
    await page.locator('#APjFqb').press('Enter');
    await page.waitForTimeout(5000);
})        
9. Run the test, as we set qa environment firstly. In google our test will search with "playwright by testers talk"


playwright qa environment
10. Updated env. to stage. Now, this time our test will with search "cypress by testers talk".
playwright stage environment

In a similar way we need any configurations based on the environment it can be URL, test data or any configurations.

Reference: https://playwright.dev/docs


TO RECEIVE DAILY UPDATES, SUBSCRIBE CHANNEL - https://www.youtube.com/c/BakkappaN_SoftwareTesting_Videos?sub_confirmation=1


===== Playwright Automation Full Courses =====

-> Playwright Full Course - https://youtube.com/playlist?list=PLUeDIlio4THEgPRVJRqZRS8uw8hhVNQCM&si=65JRAAG-SkkfphDm

-> Playwright API Testing Crash Course - https://youtube.com/playlist?list=PLUeDIlio4THF3rnYZ63qkbHwMTXiG67vz&si=hNd_ji_kXVmIAr_R

-> Playwright with Azure DeveOps Pipeline - https://youtube.com/playlist?list=PLUeDIlio4THG8irTXJn-Z02nYzmi6dUOF&si=3b4G5tvemlPy0--j

-> Playwright with CRM application testing - https://youtu.be/WwovRRp0f4o?si=w0rzJlUI9BhfP4KS


===== Playwright GitHub Repositories =====

-> Playwright Full Course - https://github.com/BakkappaN/PlaywrightTutorialFullCourse

-> Playwright API Testing Crash Course - https://github.com/BakkappaN/PlaywrightAPITestingTutorial

-> Playwright with Azure DeveOps Pipeline - https://github.com/BakkappaN/PlaywrightAzureDevopsPipeline

-> Playwright with CRM application testing -https://github.com/BakkappaN/MicrosoftD365CRMPlaywrightFramework

-> Playwright with JavaScript Framework [UI + API] - https://github.com/BakkappaN/PlaywrightBaseAutomationFramework

-> Playwright with TypeScript Framework [UI + API]- https://github.com/BakkappaN/Playwright-TypeScript-Framework


Learn more about Playwright:


-> Playwright API Testing Crash Course


-> Playwright with Azure DevOps Complete guide


-> Testing Microsoft CRM application using Playwright


#playwright #apitesting #qa #softwaretesting #crm #javascript #typescript #ado #azuredeveops #framework #fullcourse #codegen #test #e2e #testing #automation #testerstalk #bakkappan #git #github #testautomation #selenium #cypress #microsoft


SUBSCRIBE CHANNEL TO GET LATEST SOFTWARE TESTING UPDATES - https://www.youtube.com/c/BakkappaN_SoftwareTesting_Videos?sub_confirmation=1

要查看或添加评论,请登录

Bakkappa N的更多文章