TestInfo in Playwright



TestInfo in Playwright

 test(‘search India’,async({page}, testInfo)=>{
    console.log(`search India: ${new Date().toLocaleTimeString()}`);
    console.log(`Worker: ${testInfo.workerIndex}`);    //Getting Worker index from testinfo
    const browser:Browser=await chromium.launch({headless:false, channel:’chrome’});
    const page2:Page=await browser.newPage();
    await page2.goto(‘http://www.google.com’);
    const txtsrch:Locator=await page2.locator(‘[name=”q”]’);
    txtsrch.fill(‘India’);
    const srcEnabed:boolean= await txtsrch.isEnabled();
    console.log(“search text box enabled:” + srcEnabed);
    console.log(await page2.title());
    await page2.screenshot({path:’homepage.jpeg’});
    expect(await page2.title()).toContain(‘Google’);
    expect(await page2.title()).toEqual(‘Google’);
   // browser.close();
  });
  test(‘Getting TestInfo ‘, async ({ page }, testInfo) => {
    console.log(‘test name:’, testInfo.title); //Getting Title of Test case
    console.log(‘test status:’, testInfo.status);  //Getting test status
    console.log(`Time         : ${new Date().toLocaleTimeString()}`);
    console.log(`Worker Index : ${testInfo.workerIndex}`);
    console.log(`Project      : ${testInfo.project.name}`);    //Getting Project name
    console.log(`PID          : ${(globalThis as any).process?.pid ?? ‘unknown’}`);
    await page.goto(‘https://google.com’);
    await expect(page).toHaveTitle(/Google/);
     console.log(‘test duration:’, testInfo.duration); // this will get 0 as test is not finised yet
});
Getting TestInfo in Playwright
Getting TestInfo in Playwright
Tags:
Leave a comment

Your email address will not be published. Required fields are marked *

Subscribe now

Receive weekly newsletter with educational materials, new courses, most popular posts, popular books and much more!