How to use Rest Assured Framework in aiTest
How to use Rest Assured Automation Framework in aiTest.
Knowledge Base for aiTest
This How-To provides detailed instructions on how to integrate and use the Playwright Framework for automation testing within aiTest. It covers the setup process, configuration, execution steps, and provides code snippets for reference in JavaScript, Python, and Java.
The Playwright Framework enables comprehensive test coverage across different application layers. It focuses on end-to-end testing and supports multiple browsers, allowing you to validate your application’s functionality and user experience.
test-example.com
, test-demo.com
.https://example.com
.npx playwright test automation.spec.js --project chromium -- --reporter mochawesome --reporter-options reportDir=reports,reportFilename=test-report
mvn clean test
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
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/Test_Report.html
, Report/Test_Report.json
, Report/Test_Report.xml
.automation.spec.js
, which is the file you want to run.Refer the code snippet below:
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();
})
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()
package com.java.playwright;
import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;
import com.aventstack.extentreports.reporter.ExtentHtmlReporter;
import com.aventstack.extentreports.reporter.ExtentSparkReporter;
import com.microsoft.playwright.*;
import com.microsoft.playwright.options.AriaRole;
import org.junit.jupiter.api.*;
public class TestDashboardpage {
static ExtentReports extent;
ExtentTest test;
private static BrowserType.LaunchOptions browserOptions;
private static String browserName;
private static Playwright playwright;
private static Browser browser;
private BrowserContext context;
private Page page;
@BeforeAll
static void globalSetup() {
extent = new ExtentReports();
ExtentSparkReporter htmlReporter = new ExtentSparkReporter("target/extent-report.html");
extent.attachReporter(htmlReporter);
ExtentSparkReporter sparkReporter = new ExtentSparkReporter("target/extent-report.json");
extent.attachReporter(sparkReporter);
// Set browser options
browserOptions = new BrowserType.LaunchOptions().setHeadless(true);
// Read the browser name from the system property
browserName = System.getProperty("browser", "chromium");
System.out.println("Browser specified: " + browserName);
playwright = Playwright.create();
switch (browserName.toLowerCase()) {
case "chromium":
case "chrome":
browser = playwright.chromium().launch(browserOptions);
break;
case "firefox":
browser = playwright.firefox().launch(browserOptions);
break;
case "edge":
browser = playwright.chromium().launch(new BrowserType.LaunchOptions().setChannel("msedge"));
break;
default:
throw new IllegalArgumentException("Unsupported browser: " + browserName);
}
}
@AfterAll
static void globalCleanup() {
if (browser != null) {
browser.close();
}
if (playwright != null) {
playwright.close();
}
extent.flush();
}
@BeforeEach
void setup() {
context = browser.newContext();
page = context.newPage();
}
@AfterEach
void cleanup() {
if (context != null) {
context.close();
}
}
@Test
void shouldClickButton() throws InterruptedException {
test = extent.createTest("Marxeed Logo");
test.log(Status.INFO, "Test started");
try {
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("omkar.jodh@appliedaiconsulting.com");
page.getByRole(AriaRole.TEXTBOX, new Page.GetByRoleOptions().setName("Password")).click();
page.getByRole(AriaRole.TEXTBOX, new Page.GetByRoleOptions().setName("Password")).fill("Omkar@12345");
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 currentTitle = page.title();
System.out.println("Current Page Title: " + currentTitle);
if (currentTitle.equals("Signin")) {
test.log(Status.PASS, "Test Passed");
} else {
test.log(Status.FAIL, "Test Failed");
}
} catch (Exception e) {
e.printStackTrace();
test.log(Status.FAIL, "Test Failed");
}
}
@Test
void validatetitletext() throws InterruptedException {
test = extent.createTest("Marxeed Title Text");
test.log(Status.INFO, "Test started");
try {
page.navigate("https://app.marxeed.com/");
page.navigate("https://app.marxeed.com/home");
Locator logoElement = page.locator("img[alt='Marxeed Logo']");
logoElement.click();
String currentURL = page.url();
System.out.println("Current page url: " + currentURL);
Thread.sleep(2000);
String currentTitle = page.title();
System.out.println("Current Page Title: " + currentTitle);
if (currentTitle.equals("marXeed")) {
test.log(Status.PASS, "Test Passed");
} else {
test.log(Status.FAIL, "Test Failed");
}
} catch (Exception e) {
e.printStackTrace();
test.log(Status.FAIL, "Test Failed");
}
}
@Test
void Click_on_continue_with_google_Button() throws InterruptedException {
test = extent.createTest("Click on Continue with Google Button");
test.log(Status.INFO, "Test started");
try {
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();
Locator googleButton = page.locator("(//button[@name='googleSignUpButton'])[2]");
googleButton.click();
String currentURL = page.url();
System.out.println("Current page url: " + currentURL);
Thread.sleep(4000);
String currentTitle = page.title();
System.out.println("Current Page Title: " + currentTitle);
if (currentTitle.equals("Sign in - Google Accounts")) {
test.log(Status.PASS, "Test Passed");
} else {
test.log(Status.FAIL, "Test Failed");
}
} catch (Exception e) {
e.printStackTrace();
test.log(Status.FAIL, "Test Failed");
}
}
@Test
void Click_on_ai_generated_blog_Button() throws InterruptedException {
test = extent.createTest("Click on ai generated blog");
test.log(Status.INFO, "Test started");
try {
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();
Locator googleButton = page.locator("//*[@id=\"aigeneratedblogs\"]/div");
googleButton.click();
String currentURL = page.url();
System.out.println("Current page url: " + currentURL);
Thread.sleep(4000);
String currentTitle = page.title();
System.out.println("Current Page Title: " + currentTitle);
if (currentTitle.equals("AI Generated Blogs")) {
test.log(Status.PASS, "Test Passed");
} else {
test.log(Status.FAIL, "Test Failed");
}
} catch (Exception e) {
e.printStackTrace();
test.log(Status.FAIL, "Test Failed");
}
}
@Test
void Click_on_trending_blog() throws InterruptedException {
test = extent.createTest("Click on trending blog");
test.log(Status.INFO, "Test started");
try {
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();
Locator googleButton = page.locator("//*[@id=\"trendingBlogs\"]/div/p");
googleButton.click();
String currentURL = page.url();
System.out.println("Current page url: " + currentURL);
Thread.sleep(4000);
String currentTitle = page.title();
System.out.println("Current Page Title: " + currentTitle);
if (currentTitle.equals("marXeed")) {
test.log(Status.PASS, "Test Passed");
} else {
test.log(Status.FAIL, "Test Failed");
}
} catch (Exception e) {
e.printStackTrace();
test.log(Status.FAIL, "Test Failed");
}
}
public static void main(String[] args) {
if (System.getProperty("browser") == null) {
System.setProperty("browser", "chromium");
} else {
System.out.println("Browser from system property: " + System.getProperty("browser"));
}
}
}