Playwright - SSO Microsoft (JAVA)

60 Views Asked by At

I am facing issue. I need to write automation test. I am using JAVA with Playwright. Went through a lot of discussions. Trying to login in from my computer. Even when Playwright is starting session in "incognito mode" it still taking my personal credentials from the computer. I need to use some user that we are using for the aut. test. And I am to be honest I just don't know how to handle that. I have tried to use the setArgs, which I think its not working. And we are pushed to use the "msedge" for the testing. Can somebody help me out ? This is my snippet:

public Page initBrowser(Properties prop) {
        String browserName = prop.getProperty("browser").trim();
        System.out.println("browser name is : " + browserName);

        playwright = Playwright.create();
        //browser logic - have to pass the browserName

        switch (browserName.toLowerCase()) {
            case "msedge":
                browser = playwright.chromium().launch(new BrowserType.LaunchOptions().setSlowMo(500).setHeadless(false).setArgs(Collections.singletonList("--auth-server-allowlist=\"_\"")));
                break;
            case "chromium":
            case "chrome":
                browser = playwright.chromium().launch(new BrowserType.LaunchOptions().setHeadless(false).setArgs(Collections.singletonList("--auth-server-allowlist=\"_\"")).setArgs(Collections.singletonList("-inprivate")));
                break;

            default:
                System.out.println("Invalid browser name. Please pass a valid browser name.");
                return null;
        }

        if (browser != null) { // Ensure a valid browser instance
            browserContext = browser.newContext(new Browser.NewContextOptions().setIgnoreHTTPSErrors(true).setHttpCredentials("username", "password"));
            page = browserContext.newPage();
            page.navigate(prop.getProperty("url").trim());
            return page;
        } else {
            // Handle cases where browser launch failed
            return null;
        }
    }

I have tried to implement some solutions which have worked for others from python or typescript.

0

There are 0 best solutions below