Generate Code
Last updated
Last updated
Navigate to Testcase and Click on help on the Right side of the screen
Click on Auto Generate Code
Click on Generate Code
Here is the Generated code looks like
You can easily copy the code from here. Here is the sample code from testcase
// const { test, expect } = require('@playwright/test');
test.describe('139', () => {
test('139', async ({ page }) => {
let findLocator = [];
let pwLocator = [];
let url = '';
let urlLoadState = 'networkidle';
/* Visit url*/
pwLocator = [];
findLocator = [];
url = `https://shop.lululemon.com/account/login`;
await page.goto(url);
await page.waitForLoadState(urlLoadState);
/* Click on label*/
pwLocator = [`internal:role=link[name="Men"s]`,`.mega-nav_navWrapperDesktop__2bY3W > .primary_sitePrimaryNav__F-r0d > .unorderedList_ulStyle__18-lg > li > .primary_primaryNavAnchorActive___j-93`,`[role="anchor link"]`];
findLocator = [];
await page.click(`${(findLocator.length) ? findLocator[0] : pwLocator[0]}`, { timeout: 20000 });
/* Visit url*/
pwLocator = [];
findLocator = [];
url = `https://shop.lululemon.com/story/men`;
await page.goto(url);
await page.waitForLoadState(urlLoadState);
/* Click on label if Present*/
pwLocator = [`internal:role=button[name="Close"i]`];
findLocator = [];
if (await page.isVisible(`${pwLocator[0]}`)) {
await page.click(`${pwLocator[0]}`);
}
/* Click on label*/
pwLocator = [`internal:role=button[name="Add to Bag"i]`,`#pdp-summary-wrapper > .purchase-attributes_purchaseAttributes__XJrO3 > .purchase-methods-wrapper > .purchase-methods_purchaseMethodContainer__1DfqM > .button-15h2h`,`[role="Button"]`];
findLocator = [];
await page.click(`${(findLocator.length) ? findLocator[0] : pwLocator[0]}`, { timeout: 20000 });
/* Verify that the label text contains test-data*/
pwLocator = [`internal:text="Please select a size."i`];
findLocator = [];
await expect(page.locator(`${(findLocator.length) ? findLocator[0] : pwLocator[0]}`)).toContainText(`Please select a size`);
/* Verify: Description*/
pwLocator = [];
findLocator = [];
let getResult = await getOpenAIResponse({ imageUrl: '', storePath: image_file_directory, query: `Verify how many items are added to the cart?`, type: 'verification' });
/* Verify that the URL of current page is test-data*/
pwLocator = [];
findLocator = [];
await expect(page).toHaveURL(`https://lululemon.com`);
/* Enter url in the label field*/
pwLocator = [`element`];
findLocator = [];
await page.fill(`${(findLocator.length) ? findLocator[0] : pwLocator[0]}`, ``);
await page.locator(`${(findLocator.length) ? findLocator[0] : pwLocator[0]}`).pressSequentially(`${username}`);
});
});