Playwright Library: Launch Browser



Playwright Library: Launch Browser:

Playwright module provides a method to launch a browser instance. The following is a typical example of using Playwright to drive automation:

import {test, Locator, Expect, chromium, Browser, Page, expect} from ‘@playwright/test’;
import { googlePage } from ‘./Pages/googlePage’;  //Import page class

test(‘click on Gmail’,async()=>{

    const browser:Browser = await chromium.launch({headless:false, channel:’chrome’});  //Launch chrome browser in headed mode
    const page:Page= await browser.newPage();
    const gpage= new googlePage(page);
    await gpage.NavigateToSite();
    await gpage.clickonGmail();
   });
GooglePage.ts
import {Locator, Page} from ‘@playwright/test’;
export class googlePage
{
readonly url =”https://www.google.com/”;
readonly page: Page;
readonly txtSrch: Locator;
readonly btnSignin: Locator;
readonly linkGmail:Locator;
constructor(page: Page) {
    this.page = page;
    this.txtSrch = page.locator(“xpath=//textarea[@name=’q’]”);
    this.btnSignin = page.locator(“xpath=//a[@aria-label=’Sign in’]”);
    this.linkGmail= page.locator(“//a[@aria-label=’Gmail ‘]”);
    }
async NavigateToSite()
{
    await this.page.goto(this.url);
    }
    async clickonGmail()
        {
            await this.linkGmail.click();
        }
}
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!