Skip to content

Commit

Permalink
ApiSecondTest
Browse files Browse the repository at this point in the history
  • Loading branch information
An5hul-Choudhary committed Apr 17, 2024
1 parent ae0e53b commit c1a5d0f
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions tests/ApiSecondTest.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
const {test,expect} = require('@playwright/test');
let webContext;

test.beforeAll(async({browser}) =>{
const context = await browser.newContext();
const page = await context.newPage();
const email = "anshika222@gmail.com";
await page.goto("https://rahulshettyacademy.com/client");
await page.locator("#userEmail").fill(email);
await page.locator("#userPassword").fill("Iamking@000");
await page.locator("[value='Login']").click();
await page.waitForLoadState('networkidle');
await context.storageState({path: 'state.json'});
webContext = await browser.newContext({storageState:'state.json'});
})


test('Login', async() =>{

const email = "anshika222@gmail.com";
const productName = 'ADIDAS ORIGINAL';
const page = await webContext.newPage();
await page.goto("https://rahulshettyacademy.com/client");
const products =await page.locator(".card-body");
const titles = await page.locator(".card-body b").allTextContents();
console.log(titles);
const count = await products.count();
for (let i = 0; i < count; ++i) {
if (await products.nth(i).locator("b").textContent() === productName) {
//add to cart
await products.nth(i).locator("text= Add To Cart").click();
break;
}
}

await page.locator("[routerlink*='cart']").click();
//await page.pause();

await page.locator("div li").first().waitFor();
const bool = await page.locator("h3:has-text('ADIDAS ORIGINAL')").isVisible();
expect(bool).toBeTruthy();
await page.locator("text=Checkout").click();

await page.locator("[placeholder*='Country']").pressSequentially("ind");

const dropdown = page.locator(".ta-results");
await dropdown.waitFor();
const optionsCount = await dropdown.locator("button").count();
for (let i = 0; i < optionsCount; ++i) {
const text = await dropdown.locator("button").nth(i).textContent();
if (text === " India") {
await dropdown.locator("button").nth(i).click();
break;
}
}

await expect(page.locator(".user__name [type='text']").first()).toHaveText(email);
await page.locator(".action__submit").click();
await expect(page.locator(".hero-primary")).toHaveText(" Thankyou for the order. ");
const orderId = await page.locator(".em-spacer-1 .ng-star-inserted").textContent();
console.log(orderId);

await page.locator("button[routerlink*='myorders']").click();
await page.locator("tbody").waitFor();
const rows = await page.locator("tbody tr");


for (let i = 0; i < await rows.count(); ++i) {
const rowOrderId = await rows.nth(i).locator("th").textContent();
if (orderId.includes(rowOrderId)) {
await rows.nth(i).locator("button").first().click();
break;
}
}
const orderIdDetails = await page.locator(".col-text").textContent();
expect(orderId.includes(orderIdDetails)).toBeTruthy();


})

0 comments on commit c1a5d0f

Please sign in to comment.