"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.loginToApp = void 0;
const test_1 = require("@playwright/test");
const LoginPage_1 = require("../pages/8.8/LoginPage");
async function loginToApp(appName, page) {
    await page.goto(appName, { waitUntil: 'domcontentloaded', timeout: 60000 });
    await page.waitForLoadState('networkidle', { timeout: 30000 }).catch(() => { });
    const loginPage = new LoginPage_1.LoginPage(page);
    await (0, test_1.expect)(loginPage.usernameInput).toBeVisible({ timeout: 60000 });
    await loginPage.fillUsername(process.env.C8_USERNAME);
    await (0, test_1.expect)(loginPage.usernameInput).toHaveValue(process.env.C8_USERNAME);
    await (0, test_1.expect)(loginPage.loginMessage).toBeVisible();
    await loginPage.clickContinueButton();
    await (0, test_1.expect)(loginPage.passwordInput).toBeVisible({ timeout: 90000 });
    await loginPage.fillPassword(process.env.C8_PASSWORD);
    await (0, test_1.expect)(loginPage.passwordHeading).toBeVisible({ timeout: 90000 });
    await loginPage.clickLoginButton();
    await page.waitForURL((url) => url.toString().startsWith(appName), {
        timeout: 60000,
        waitUntil: 'commit',
    });
    await page
        .waitForLoadState('domcontentloaded', { timeout: 30000 })
        .catch(() => { });
}
exports.loginToApp = loginToApp;
