"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.modelAndRunConnectorsDocHandlingDiagram = exports.expectTextWithPagination = exports.modelDiagramFromFile = exports.findTextWithPagination = exports.modelAndRunConnectorsTimerEventDiagram = exports.assertPageTextWithRetry = exports.assertLocatorVisibleWithRetry = exports.assertLocatorVisibleWithPaginated = exports.modelRestConnector = exports.completeTaskWithRetry = exports.createAndRunProcess = exports.assignMappingToRole = exports.createUserAndAssignToRole = exports.runMultipleProcesses = exports.deleteAllUserGroups = void 0;
const sleep_1 = require("../../utils/sleep");
const test_1 = require("@playwright/test");
const fileUpload_1 = require("../../utils/fileUpload");
const findLocatorInPaginatedList_1 = require("../../utils/findLocatorInPaginatedList");
const KeycloakUtils_1 = require("../SM-8.10/KeycloakUtils");
const expectLocatorWithPagination_1 = require("../../utils/assertionHelpers/expectLocatorWithPagination");
// This step will be skipped until new Identity expected flow is confirmed
async function deleteAllUserGroups() {
    // await navigationPage.goToOCAdmin();
    // await identityPage.clickGroupsTab();
    // await identityPage.deleteAllGroups();
}
exports.deleteAllUserGroups = deleteAllUserGroups;
async function runMultipleProcesses(page, modelerHomePage, modelerCreatePage, numberOfProcesses, processName, processId = '', tenant = '') {
    for (let i = 1; i <= numberOfProcesses; i++) {
        await createAndRunProcess(page, modelerHomePage, modelerCreatePage, processName + i, processId.length > 0 ? processId + i : processId, tenant);
    }
}
exports.runMultipleProcesses = runMultipleProcesses;
async function createUserAndAssignToRole(page, navigationPage, managementIdentityPage, keycloakLoginPage, keycloakAdminPage, ocIdentityHomePage, identityMappingRulesPage, identityRolesPage, username, password, role = 'admin', testMappings) {
    const mappingRuleId = `${username}-user-mapping`;
    const claimName = 'preferred_username';
    await (0, KeycloakUtils_1.createUser)(navigationPage, managementIdentityPage, keycloakLoginPage, keycloakAdminPage, username, password);
    await navigationPage.goToOCAdmin();
    await ocIdentityHomePage.clickMappingRulesTab();
    await identityMappingRulesPage.createMappingRule(mappingRuleId, mappingRuleId, claimName, username);
    await (0, expectLocatorWithPagination_1.expectLocatorWithPagination)(page, identityMappingRulesPage.mappingRuleRow(mappingRuleId).first());
    if (testMappings && mappingRuleId.toLowerCase() != 'demo-user-mapping') {
        testMappings.mappingIds.push(mappingRuleId);
    }
    await assignMappingToRole(page, ocIdentityHomePage, identityRolesPage, role, mappingRuleId, testMappings);
    await (0, expectLocatorWithPagination_1.expectLocatorWithPagination)(page, identityMappingRulesPage
        .mappingRuleRow(mappingRuleId)
        .filter({
        hasText: `${mappingRuleId}${mappingRuleId}${claimName}${username}`,
    })
        .first());
}
exports.createUserAndAssignToRole = createUserAndAssignToRole;
async function assignMappingToRole(page, ocIdentityHomePage, ocIdentityRolesPage, role, mappingRuleId, testMappings) {
    await ocIdentityHomePage.clickRolesTab();
    try {
        await (0, test_1.expect)(ocIdentityRolesPage.roleCell(role).first()).toBeVisible({
            timeout: 20000,
        });
    }
    catch (error) {
        await ocIdentityRolesPage.createRole({ id: role, name: role });
        if (testMappings && role.toLowerCase() != 'admin') {
            testMappings.roleIds.push(role);
        }
    }
    await ocIdentityRolesPage.assignMappingRuleToRole(role, mappingRuleId);
    await assertLocatorVisibleWithPaginated(page, ocIdentityRolesPage.mappingRuleRow(mappingRuleId).first(), `${mappingRuleId} Mapping Rule`);
}
exports.assignMappingToRole = assignMappingToRole;
async function createAndRunProcess(page, modelerHomePage, modelerCreatePage, processName, processId = '', tenant = '') {
    await modelerHomePage.clickDiagramTypeDropdown();
    await modelerHomePage.clickBpmnTemplateOption();
    await modelerCreatePage.modelCamundaUserTaskDiagram(processName, processId);
    await modelerCreatePage.runProcessInstance('', tenant);
    await modelerHomePage.clickProjectBreadcrumb();
}
exports.createAndRunProcess = createAndRunProcess;
async function completeTaskWithRetry(page, taskPanelPage, taskDetailsPage, taskName, taskPriority, maxRetries = 7) {
    // Dismiss any lingering "Task completed" toast from a previous completion
    // to avoid strict mode violations and stale UI state
    try {
        const toastCloseButton = page
            .locator('.cds--toast-notification')
            .getByRole('button', { name: /close/i })
            .first();
        if (await toastCloseButton.isVisible({ timeout: 2000 })) {
            await toastCloseButton.click();
        }
    }
    catch {
        // No toast to dismiss, continue
    }
    for (let attempt = 0; attempt < maxRetries; attempt++) {
        try {
            await page.waitForLoadState('networkidle');
            const taskLocator = taskPanelPage.availableTasks
                .getByText(taskName, { exact: true })
                .first();
            try {
                await taskLocator.waitFor({ state: 'visible', timeout: 10000 });
            }
            catch {
                throw new Error(`Task ${taskName} not found in available tasks`);
            }
            // Click the task directly instead of using openTask's 30-retry loop
            // (this outer loop already provides retry logic)
            await taskLocator.click({ timeout: 10000 });
            await (0, test_1.expect)(taskDetailsPage.detailsPanel).toBeVisible({ timeout: 30000 });
            // Verify the correct task is loaded by checking the task name appears
            // in the details-info section (the task name heading is outside the
            // complementary panel, so we use detailsInfo instead of detailsPanel)
            await (0, test_1.expect)(taskDetailsPage.detailsInfo.getByText(taskName)).toBeVisible({ timeout: 30000 });
            if (!(await taskDetailsPage.assignedToMeText.isVisible({ timeout: 5000 }))) {
                await taskDetailsPage.clickAssignToMeButton();
            }
            await (0, test_1.expect)(taskDetailsPage.detailsPanel.getByText(taskPriority)).toBeVisible({ timeout: 30000 });
            await taskDetailsPage.completeTaskButton.click({ timeout: 30000 });
            await (0, test_1.expect)(taskDetailsPage.taskCompletedBanner).toBeVisible({
                timeout: 30000,
            });
            await (0, test_1.expect)(taskPanelPage.availableTasks.getByText(taskName, { exact: true }).first()).not.toBeVisible({ timeout: 15000 });
            console.log(`Successfully completed task: ${taskName}`);
            return;
        }
        catch (error) {
            console.warn(`Attempt ${attempt + 1} failed for completing task ${taskName}:`, error instanceof Error ? error.message : error);
            if (attempt < maxRetries - 1) {
                // Dismiss any toast before reloading
                try {
                    const toastCloseButton = page
                        .locator('.cds--toast-notification')
                        .getByRole('button', { name: /close/i })
                        .first();
                    if (await toastCloseButton.isVisible({ timeout: 1000 })) {
                        await toastCloseButton.click();
                    }
                }
                catch {
                    // No toast to dismiss
                }
                // A transient backend 500 while opening the task can leave the page on
                // the raw Tasklist API URL (the JSON error renders as the top-level
                // document). A bare reload then re-requests that broken URL and never
                // restores the SPA, so every remaining attempt is wasted. Re-navigate
                // to the Tasklist list — which uses a different endpoint than the
                // single-task fetch that 500s — so the app re-mounts and the task can
                // be re-opened once the blip clears. Progressive backoff gives the
                // backend time to recover between attempts.
                await (0, sleep_1.sleep)(2000 * (attempt + 1));
                const orchestrationContextPath = process.env.ORCHESTRATION_CONTEXT_PATH ?? '/orchestration';
                const normalizedOrchestrationPath = orchestrationContextPath.startsWith('/')
                    ? orchestrationContextPath
                    : `/${orchestrationContextPath}`;
                try {
                    await page.goto(`${normalizedOrchestrationPath}/tasklist`, {
                        timeout: 60000,
                        waitUntil: 'domcontentloaded',
                    });
                }
                catch {
                    await page.reload();
                }
                await page.waitForLoadState('networkidle');
            }
            else {
                console.error(`All ${maxRetries} attempts failed for task ${taskName}`);
                throw new Error(`Completion of task ${taskName} failed after ${maxRetries} attempts`);
            }
        }
    }
}
exports.completeTaskWithRetry = completeTaskWithRetry;
async function modelRestConnector(modelerCreatePage, connectorSettingsPage, connectorMarketplacePage, processName, url, auth, resultExpression, { resultVariable = '', basicAuthCredentials = { username: '', password: '' }, recoverSession, } = {}) {
    await (0, test_1.expect)(modelerCreatePage.generalPanel).toBeVisible({
        timeout: 120000,
    });
    await modelerCreatePage.enterDiagramName(processName);
    await (0, sleep_1.sleep)(1000);
    await modelerCreatePage.clickCanvas();
    await modelerCreatePage.clickGeneralPropertiesPanel();
    await modelerCreatePage.clickIdInput();
    await modelerCreatePage.fillIdInput(processName);
    await modelerCreatePage.assertNameInput(processName);
    await (0, sleep_1.sleep)(1000);
    await modelerCreatePage.clickStartEventElement();
    try {
        await (0, test_1.expect)(modelerCreatePage.appendElementButton).toBeVisible({
            timeout: 1000,
        });
    }
    catch {
        await modelerCreatePage.clickStartEventElement();
    }
    await modelerCreatePage.clickAppendElementButton();
    await modelerCreatePage.clickAppendTaskButton();
    // The REST connector template requires engines.camunda ^8.10 (since connector v15).
    // New diagrams default to "Check problems against: Camunda 8.9", which moves the
    // connector into the "Requires newer Camunda version" section where clicking it
    // has no effect. Set the diagram version to 8.10 before opening the picker.
    await modelerCreatePage.setEngineVersion('8.10');
    await modelerCreatePage.clickChangeTypeButton();
    try {
        // The change-element popup virtualizes its list: connector templates render
        // below the built-in BPMN tasks and are not in the queryable DOM slice until
        // the list is filtered. Type "REST Outbound" into the popup search box so the
        // bundled REST Outbound Connector (compatible with the 8.10 engine set above)
        // renders and is selected directly. Without this filter the off-screen entry
        // is missed and the flow falls back to the marketplace unnecessarily,
        // exposing it to transient marketplace-API errors even though the connector
        // is already bundled in the modeler.
        await (0, test_1.expect)(modelerCreatePage.changeElementSearchInput).toBeVisible({
            timeout: 30000,
        });
        await modelerCreatePage.changeElementSearchInput.click();
        await modelerCreatePage.changeElementSearchInput.fill('');
        await modelerCreatePage.changeElementSearchInput.pressSequentially('REST Outbound', { delay: 50 });
        await (0, test_1.expect)(modelerCreatePage.restConnectorOption).toBeVisible({
            timeout: 15000,
        });
    }
    catch (error) {
        await modelerCreatePage.clickMarketPlaceButton();
        await connectorMarketplacePage.clickSearchForConnectorTextbox();
        await connectorMarketplacePage.fillSearchForConnectorTextbox('REST Connector');
        await connectorMarketplacePage.waitForConnectorSearchResults();
        await connectorMarketplacePage.downloadConnectorToProject();
        // Marketplace modal closes the change-type dropdown. The task may remain in
        // a selected state (class includes "djs-selected") which breaks the exact
        // class-attribute match used by secondElement. Click the canvas background
        // first to deselect, then re-select the task and reopen the dropdown.
        await modelerCreatePage.clickCanvas();
        await modelerCreatePage.secondElement.click({ timeout: 30000 });
        await modelerCreatePage.clickChangeTypeButton();
    }
    await modelerCreatePage.clickRestConnectorOption(recoverSession);
    // Guard: wait for the connector settings panel to render before proceeding.
    // On slow clusters the properties panel can take several seconds to update
    // after the change-type click; if it doesn't appear, re-select the element
    // and try once more before letting the tab click time out.
    try {
        await (0, test_1.expect)(connectorSettingsPage.authenticationTab).toBeVisible({
            timeout: 30000,
        });
    }
    catch {
        await modelerCreatePage.secondElement
            .click({ timeout: 30000 })
            .catch(() => { });
        await modelerCreatePage.clickChangeTypeButton();
        await modelerCreatePage.clickRestConnectorOption(recoverSession);
    }
    await connectorSettingsPage.clickAuthenticationTab();
    await connectorSettingsPage.clickHTTPEndpointTab();
    if (auth == 'bearer') {
        await connectorSettingsPage.selectAuthenticationType('bearer');
        await (0, test_1.expect)(connectorSettingsPage.bearerTokenInput).toBeVisible({
            timeout: 60000,
        });
        await connectorSettingsPage.clickBearerTokenInput();
        await connectorSettingsPage.fillBearerTokenInput('thisisabearertoken');
        await (0, test_1.expect)(connectorSettingsPage.methodTypeDropdown).toBeVisible({
            timeout: 30000,
        });
        await connectorSettingsPage.selectMethodType('POST');
    }
    else if (auth == 'basic') {
        await connectorSettingsPage.selectAuthenticationType('basic');
        await (0, test_1.expect)(connectorSettingsPage.usernameInput).toBeVisible({
            timeout: 60000,
        });
        await connectorSettingsPage.clickUsernameInput();
        (0, test_1.expect)(basicAuthCredentials['username'].length).toBeGreaterThan(0);
        (0, test_1.expect)(basicAuthCredentials['password'].length).toBeGreaterThan(0);
        await connectorSettingsPage.fillUsernameInput(basicAuthCredentials['username']);
        await (0, test_1.expect)(connectorSettingsPage.passwordInput).toBeVisible({
            timeout: 30000,
        });
        await connectorSettingsPage.clickPasswordInput();
        await connectorSettingsPage.fillPasswordInput(basicAuthCredentials['password']);
        await (0, test_1.expect)(connectorSettingsPage.methodTypeDropdown).toBeVisible({
            timeout: 30000,
        });
        await connectorSettingsPage.selectMethodType('POST');
    }
    await connectorSettingsPage.clickUrlInput();
    await connectorSettingsPage.fillUrlInput(url);
    await (0, sleep_1.sleep)(3000);
    await connectorSettingsPage.clickOutputMappingTab();
    if (resultVariable.length > 0) {
        await (0, test_1.expect)(connectorSettingsPage.resultVariableInput).toBeVisible({
            timeout: 60000,
        });
        await connectorSettingsPage.clickResultVariableInput();
        await connectorSettingsPage.fillResultVariableInput('result');
        await (0, sleep_1.sleep)(5000);
    }
    await connectorSettingsPage.clickResultExpressionInput();
    await connectorSettingsPage.fillResultExpressionInput(resultExpression);
    await (0, sleep_1.sleep)(5000);
    await modelerCreatePage.clickAppendElementButton();
    await modelerCreatePage.clickAppendEndEventButton();
    await (0, sleep_1.sleep)(10000);
}
exports.modelRestConnector = modelRestConnector;
async function assertLocatorVisibleWithPaginated(page, locator, text) {
    const maxRetries = 6;
    for (let attempt = 0; attempt < maxRetries; attempt++) {
        try {
            await page.reload();
            await (0, sleep_1.sleep)(5000);
            if (attempt > 2) {
                await (0, findLocatorInPaginatedList_1.findLocatorInPaginatedList)(page, locator);
            }
            await (0, test_1.expect)(locator).toBeVisible();
            return;
        }
        catch (error) {
            if (attempt < maxRetries - 1) {
                console.warn(`Attempt ${attempt + 1} failed for asserting ${text}. Retrying...`);
            }
            else {
                throw new Error(`Assertion ${text} failed after ${maxRetries} attempts`);
            }
        }
    }
}
exports.assertLocatorVisibleWithPaginated = assertLocatorVisibleWithPaginated;
async function assertLocatorVisibleWithRetry(page, locator, text, timeout = 30000, notVisible, maxRetries = 3, clickLocator) {
    for (let attempt = 0; attempt < maxRetries; attempt++) {
        try {
            await page.reload();
            await page.waitForLoadState('domcontentloaded');
            if (clickLocator) {
                await (0, test_1.expect)(clickLocator).toBeVisible({
                    timeout: 30000,
                });
                await clickLocator.click();
            }
            if (notVisible == true) {
                await (0, test_1.expect)(locator.first()).not.toBeVisible({
                    timeout: timeout,
                });
            }
            else {
                await (0, test_1.expect)(locator).toBeVisible({
                    timeout: timeout,
                });
            }
            return;
        }
        catch (error) {
            if (attempt < maxRetries - 1) {
                console.warn(`Attempt ${attempt + 1} failed for asserting ${text}. Retrying...`);
            }
            else {
                throw new Error(`Assertion failed after ${maxRetries} attempts`);
            }
        }
    }
}
exports.assertLocatorVisibleWithRetry = assertLocatorVisibleWithRetry;
async function assertPageTextWithRetry(page, text, notVisible, timeout = 30000, maxRetries = 3) {
    for (let attempt = 0; attempt < maxRetries; attempt++) {
        try {
            await page.reload();
            await page.waitForLoadState('domcontentloaded');
            if (notVisible == true) {
                await (0, test_1.expect)(page.getByText(text, { exact: true }).first()).not.toBeVisible({
                    timeout: timeout,
                });
            }
            else {
                await (0, test_1.expect)(page.getByText(text, { exact: true }).first()).toBeVisible({
                    timeout: timeout,
                });
            }
            return;
        }
        catch (error) {
            if (attempt < maxRetries - 1) {
                console.warn(`Attempt ${attempt + 1} failed for asserting ${text}. Retrying...`);
            }
            else {
                throw new Error(`Assertion failed after ${maxRetries} attempts`);
            }
        }
    }
}
exports.assertPageTextWithRetry = assertPageTextWithRetry;
async function modelAndRunConnectorsTimerEventDiagram(modelerCreatePage, modelerHomePage, processName, page, connectorMarketplacePage, connectorTemplatePage, tenant = '') {
    await modelerHomePage.clickCrossComponentProjectFolder();
    await modelerHomePage.clickDiagramTypeDropdown();
    await modelerHomePage.clickUploadFilesButton();
    await (0, fileUpload_1.uploadFile)(page, 'Rest Connector Timer Event.bpmn');
    await modelerHomePage.clickProcessDiagram('Rest Connector Timer Event');
    await modelerCreatePage.clickDiagramBreadcrumb();
    await modelerCreatePage.clickEditDiagramNameButton();
    await modelerCreatePage.enterDiagramName(processName);
    await modelerCreatePage.clickStartEventElement();
    await modelerCreatePage.clickGeneralPropertiesPanel();
    await modelerCreatePage.clickIdInput();
    await modelerCreatePage.fillIdInput(processName);
    await (0, sleep_1.sleep)(2000);
    await page.reload();
    await modelerCreatePage.clickEighthPlacedElement();
    await modelerCreatePage.clickChangeTypeButton();
    await (0, test_1.expect)(modelerCreatePage.marketPlaceButton).toBeVisible({
        timeout: 120000,
    });
    await modelerCreatePage.clickMarketPlaceButton();
    await connectorMarketplacePage.clickSearchForConnectorTextbox();
    await connectorMarketplacePage.fillSearchForConnectorTextbox('REST Connector');
    await (0, sleep_1.sleep)(10000);
    await (0, test_1.expect)(page.getByText('REST ConnectorBy CamundaConnect, interact, and synchronize processes')).toBeVisible({
        timeout: 60000,
    });
    await connectorMarketplacePage.downloadConnectorToProject();
    await modelerHomePage.clickProjectBreadcrumb();
    await modelerHomePage.clickProcessDiagram('REST Outbound Connector');
    await connectorTemplatePage.publishConnector();
    await modelerHomePage.clickProjectBreadcrumb();
    await modelerHomePage.clickProcessDiagram(processName);
    await (0, sleep_1.sleep)(5000);
    await page.reload();
    await (0, sleep_1.sleep)(5000);
    await modelerCreatePage.runProcessInstance('', tenant);
}
exports.modelAndRunConnectorsTimerEventDiagram = modelAndRunConnectorsTimerEventDiagram;
async function findTextWithPagination(page, text, timeout = 30000, action) {
    const maxPages = 10;
    const startTime = Date.now();
    for (let pageNum = 0; pageNum < maxPages; pageNum++) {
        if (Date.now() - startTime > timeout) {
            console.log(`Overall timeout of ${timeout}ms exceeded`);
            break;
        }
        const locator = page.getByText(text).last();
        const textExists = await locator
            .isVisible({ timeout: 2000 })
            .catch(() => false);
        if (textExists) {
            console.log(`Found text "${text}" on page ${pageNum + 1}`);
            if (action) {
                await action(locator);
            }
            return true;
        }
        const loadMoreButton = page
            .getByRole('button', { name: 'Load more', exact: true })
            .last();
        const isVisible = await loadMoreButton
            .isVisible({ timeout: 1000 })
            .catch(() => false);
        const isEnabled = isVisible
            ? await loadMoreButton.isEnabled().catch(() => false)
            : false;
        if (!isVisible || !isEnabled) {
            console.log(`No more pages available after page ${pageNum + 1} (visible: ${isVisible}, enabled: ${isEnabled})`);
            break;
        }
        console.log(`Text "${text}" not found on page ${pageNum + 1}, going to next page...`);
        await loadMoreButton.click();
        await page.waitForTimeout(1000);
    }
    return false;
}
exports.findTextWithPagination = findTextWithPagination;
async function modelDiagramFromFile(page, modelerHomePage, modelerCreatePage, processName, fileName = '', nrOfRenamedUserTasks = 0, taskName = '') {
    await modelerHomePage.clickDiagramTypeDropdown();
    await modelerHomePage.clickUploadFilesButton();
    await (0, fileUpload_1.uploadFile)(page, fileName + '.bpmn');
    await modelerHomePage.clickProcessDiagram(fileName);
    await modelerCreatePage.clickDiagramBreadcrumb();
    await modelerCreatePage.clickEditDiagramNameButton();
    await modelerCreatePage.enterDiagramName(processName);
    await (0, sleep_1.sleep)(1000);
    await modelerCreatePage.clickGeneralPropertiesPanel();
    await modelerCreatePage.clickNameInput();
    await modelerCreatePage.fillNameInput(processName);
    await modelerCreatePage.clickIdInput();
    await modelerCreatePage.fillIdInput(processName);
    if (nrOfRenamedUserTasks > 0) {
        for (let i = 1; i <= nrOfRenamedUserTasks; i++) {
            await modelerCreatePage.clickUserTask('process' + i);
            await modelerCreatePage.clickNameInput();
            await modelerCreatePage.fillNameInput(taskName + i);
            await modelerCreatePage.clickIdInput();
            await modelerCreatePage.fillIdInput(taskName + i);
            await modelerCreatePage.clickCanvas();
        }
    }
    await (0, sleep_1.sleep)(10000);
}
exports.modelDiagramFromFile = modelDiagramFromFile;
async function expectTextWithPagination(page, text, shouldExist = true, timeout = 30000) {
    const found = await findTextWithPagination(page, text, timeout);
    if (shouldExist && !found) {
        throw new Error(`Text "${text}" not found on any page within ${timeout}ms`);
    }
    if (!shouldExist && found) {
        throw new Error(`Text "${text}" should not exist but was found`);
    }
    if (shouldExist && found) {
        await (0, test_1.expect)(page.getByText(text).last()).toBeVisible({ timeout: 5000 });
    }
}
exports.expectTextWithPagination = expectTextWithPagination;
async function modelAndRunConnectorsDocHandlingDiagram(modelerCreatePage, modelerHomePage, processName, page, connectorMarketplacePage, zeebeUrl, zeebeClientId, zeebeClientSecret, endpoint, tenant = '') {
    await modelerHomePage.clickCrossComponentProjectFolder();
    await modelerHomePage.clickDiagramTypeDropdown();
    await modelerHomePage.clickUploadFilesButton();
    await (0, fileUpload_1.uploadFile)(page, 'SM_Document_Handling_Connectors_User_Flow.bpmn');
    await modelerHomePage.clickProcessDiagram('SM_Document_Handling_Connectors_User_Flow');
    await modelerCreatePage.clickDiagramBreadcrumb();
    await modelerCreatePage.clickEditDiagramNameButton();
    await modelerCreatePage.enterDiagramName(processName);
    await modelerCreatePage.clickGeneralPropertiesPanel();
    await modelerCreatePage.clickNameInput();
    await modelerCreatePage.fillNameInput(processName);
    await modelerCreatePage.clickIdInput();
    await modelerCreatePage.fillIdInput(processName);
    await (0, sleep_1.sleep)(10000);
    await modelerCreatePage.clickFirstPlaceRESTConnector();
    await modelerCreatePage.clickChangeTypeButton();
    await modelerCreatePage.clickMarketPlaceButton();
    await connectorMarketplacePage.clickSearchForConnectorTextbox();
    await connectorMarketplacePage.fillSearchForConnectorTextbox('REST Connector');
    await connectorMarketplacePage.waitForConnectorSearchResults();
    await connectorMarketplacePage.downloadConnectorToProject();
    await page.reload();
    await page.waitForLoadState('networkidle');
    await modelerCreatePage.fillStartEventVariablesForDocHandling(zeebeUrl, zeebeClientId, zeebeClientSecret);
    await modelerCreatePage.setOAuthTokenEndpoint(page.locator('.djs-hit').first(), endpoint);
    await (0, sleep_1.sleep)(2000);
    await modelerCreatePage.setOAuthTokenEndpoint(page.locator('g:nth-child(3) > .djs-element > .djs-hit'), endpoint);
    await (0, sleep_1.sleep)(2000);
    await modelerCreatePage.setOAuthTokenEndpoint(page.locator('g:nth-child(6) > .djs-element > .djs-hit'), endpoint);
    await (0, sleep_1.sleep)(2000);
    await modelerCreatePage.clickCloseDetailsPanel();
    await modelerCreatePage.setOAuthTokenEndpoint(page.locator('g:nth-child(7) > .djs-element > .djs-hit'), endpoint, { openPanel: true });
    await (0, sleep_1.sleep)(2000);
    await modelerCreatePage.clickCloseDetailsPanel();
    await modelerCreatePage.setOAuthTokenEndpoint(page.locator('g:nth-child(9) > .djs-element > .djs-hit'), endpoint, { openPanel: true });
    await (0, sleep_1.sleep)(2000);
    await modelerCreatePage.runProcessInstance('', tenant);
}
exports.modelAndRunConnectorsDocHandlingDiagram = modelAndRunConnectorsDocHandlingDiagram;
