How to use Playwright Framework in aiTest

Language

  • Java Script(Node.js)
  • Python
  • Java

How Playwright Framework is going to be used in aiTest

Playwright Framework enable you to achieve comprehensive test coverage across different layers of your application. Playwright focuses on end-to-end testing and supports multiple browsers, allowing you to validate your application’s functionality and user experience.

  1. Sign up using your E-mail or Google account.
  2. Once you have reached the URL test dashboard, navigate to the left-side menu and select the Multi-Browser Test.
  3. Hit the Create Testrun button.
  4. Configure your test:
    • Name the testrun: Give the name of testrun whatever you want or which is related to your application, So that it will be easy to get that particular testrun details whenever you want. i.e. test-example.com, test-demo.com, etc.
    • Project: Select a project in which you want to run your test or you can create a project by clicking on the red colored plus sign(+) button.
    • Testrun Description: Write some testrun description to make your testrun more informative.
    • AUT URL: Application Under Test URL. e.g. https://example.com
    • Now here you can choose Repo Details or Your Automation Code.
    • Repo Details: Provide the repo details User’s Git Repository URL, User’s Git Username, User’s Git Token or Password, Report File Location and Testrun Command.
    • Your Automation Code: If you select “Your Automation Code” in the previous step, you will need to upload your automation code in a zip file.
    • Testrun Command: 1)In JavaScript Write Testrun Command to Run your testrun Testcases npx playwright test automation.spec.js --project chromium -- --reporter mochawesome --reporter-options reportDir=reports,reportFilename=test-report. 2)In Java Write Testrun Command to Run your Testrun Testcases mvn clean test. 3)In Python Write Testrun Command to Run your Testrun Testcases For headed mode: pytest -v -s --json-report --json-report-indent=4 --json-report-file=report/report.json --html-report=./report/report.html --headed .\test_my_application.py. (where “.\test_my_application.py” is the name of the test file which is to be run) For headless mode: pytest -v -s --json-report --json-report-indent=4 --json-report-file=report/report.json --html-report=./report/report.html .\test_my_application.py.
    • Report Location: Write Report Location to Stored your testrun Testcases Report Files Report/Test_Report.html, Report/Test_Report.json and Report/Test_Report.xml
  5. Select Browsers: At the end select the browser on which you want to run your test. Currently, we have 3 browsers such as, Google Chrome, Mozilla Firefox and Microsoft Edge with their different browser versions.
  6. Once you are done with the above steps you can do either of the following:
    • Run It Now: Immediately run the automation code to test the browser compatibility of your apps with across browsers and versions.
    • Save: Save the configuration for later run as draft testrun.
    • Cancel: Reset and go back to previous page.
    • Update: Update the configurations of the test and run new.

Note:

In Testrun command automation.spec.js is the file name. We need to specify our file name in Testrun command, whatever the file we want to run.

AUT code and can be accessed in aiTest through
  • GIT
  • .zip file

Code Snippets for Reference

Refer the code snippet below:

JavaScript

  
  import { test, expect } from '@playwright/test'

test('Login with valid credential', async ({ page }) => {

    await page.goto('https://app.dev.marxeed.com')
    //await page.pause()
    await page.getByRole('banner').filter({ hasText: 'ServicesSupportCredits(...)Site Guide' }).getByRole('button').nth(1).click();
    await page.getByRole('textbox', { name: 'name@host.com' }).click();
    await page.getByRole('textbox', { name: 'name@host.com' }).fill('rohan.thakre@appliedaiconsulting.com');
    await page.getByRole('textbox', { name: 'Password' }).click();
    await page.getByRole('textbox', { name: 'Password' }).fill('Sulochana@1997');
    await page.getByRole('button', { name: 'submit' }).click();
})
 
test('login with invalid password', async ({ page }) => {
    await page.goto('https://app.dev.marxeed.com')
    //await page.pause()
    await page.getByRole('banner').filter({ hasText: 'ServicesSupportCredits(...)Site Guide' }).getByRole('button').nth(1).click();
    await page.getByRole('textbox', { name: 'name@host.com' }).click();
    await page.getByRole('textbox', { name: 'name@host.com' }).fill('rohan.thakre@appliedaiconsulting.com');
    await page.getByRole('textbox', { name: 'Password' }).click();
    await page.getByRole('textbox', { name: 'Password' }).fill('Asdhdjs@1997');
    await page.getByRole('button', { name: 'submit' }).click();
    await page.getByRole('paragraph').filter({ hasText: 'The username or password you entered is invalid' }).click();
  
})
  

Python

  
import playwright
from playwright.sync_api import Page, expect

#Login with Vaid Details
def test_example(page: Page) -> None:
    page.goto("https://app.marxeed.com/")
    page.goto("https://app.marxeed.com/home")
    page.get_by_role("banner").filter(has_text="ServicesSupportCredits(...)Site Guide").get_by_role("button").nth(1).click()
    page.get_by_role("textbox", name="name@host.com").click()
    page.get_by_role("textbox", name="name@host.com").fill("rohan.thakre@appliedaiconsulting.com")
    page.get_by_role("textbox", name="Password").click()
    page.get_by_role("textbox", name="Password").fill("Rohan@1997")
    page.get_by_role("button", name="submit").click()
    page.locator("html").click()

#Login with Invalid details
def test_invalid(page: Page) -> None:
    page.goto("https://app.marxeed.com/")
    page.goto("https://app.marxeed.com/home")
    page.get_by_role("banner").filter(has_text="ServicesSupportCredits(...)Site Guide").get_by_role("button").nth(1).click()
    page.get_by_role("textbox", name="name@host.com").click()
    page.get_by_role("textbox", name="name@host.com").fill("rohan.thakre@appliedaiconsulting.com")
    page.get_by_role("textbox", name="Password").click()
    page.get_by_role("textbox", name="Password").fill("Rhdo@1799")
    page.get_by_role("button", name="submit").click()
    page.locator("html").click()
  

Java

  
  package com.java.playwright;
import com.microsoft.playwright.*;

import com.microsoft.playwright.options.*;
import org.junit.jupiter.api.*;


public class TestLoginpage {
	
	 @Test
	 void shouldCheckErrorMessage() throws InterruptedException {

    try (Playwright playwright = Playwright.create()) {
      Browser browser = playwright.chromium().launch(new BrowserType.LaunchOptions()
        .setHeadless(false));
      BrowserContext context = browser.newContext();
      Page page = context.newPage();
      page.navigate("https://app.marxeed.com/");
      page.navigate("https://app.marxeed.com/home");
      page.getByRole(AriaRole.BANNER).filter(new Locator.FilterOptions().setHasText("ServicesSupportCredits(...)Site Guide")).getByRole(AriaRole.BUTTON).nth(1).click();
      page.getByRole(AriaRole.TEXTBOX, new Page.GetByRoleOptions().setName("name@host.com")).click();
      page.getByRole(AriaRole.TEXTBOX, new Page.GetByRoleOptions().setName("name@host.com")).fill("suvarna.kanawade@appliedaiconsulting.com");
      page.getByRole(AriaRole.TEXTBOX, new Page.GetByRoleOptions().setName("Password")).click();
      page.getByRole(AriaRole.TEXTBOX, new Page.GetByRoleOptions().setName("Password")).fill("SK@1997");
      page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("submit")).click();
      
      String currentURL = page.url();
    System.out.println("Current page url: " + currentURL);
    Thread.sleep(2000);
    String Errormsg = page.innerText("(//p[@id='loginErrorMessage'])[2]");
    System.out.println("Error Message: " + Errormsg);
    String currentTitle = page.title();
    
    System.out.println("Current Page Title: " + currentTitle);
    }
  }
}
  

Questions Answered

  • How Playwright Framework is going to be used in aiTest?
×

Subscribe

The latest tutorials sent straight to your inbox.