package com.playwrightdemo.utils;

import com.microsoft.playwright.*;

public class PlayWrightBrowserFactory {

    static Playwright playwright;
    static Browser browser;
    static Page page;

    public static Page init_Browser (String browserName,Boolean isHeadLess, String URL,double slowMotion) {


        playwright=Playwright.create();

        switch(browserName.toLowerCase()) {

            case "firefox":

                browser  = playwright.firefox().launch(new BrowserType.LaunchOptions().setHeadless(isHeadLess).setSlowMo(slowMotion));

                break;

            case "chromium":

                browser = playwright.chromium().launch(new BrowserType.LaunchOptions().setHeadless(isHeadLess).setSlowMo(slowMotion));

                break;

            case "webkit":
                browser = playwright.webkit().launch(new BrowserType.LaunchOptions().setHeadless(isHeadLess).setSlowMo(slowMotion));

                break;

            default:

                System.out.println("No matching browser is found");

        }

        BrowserContext browserContext=  browser.newContext();
        page= browserContext.newPage();
        page.navigate(URL);
        return page;
    }




}
