Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@
await page.executePaletteCommand("Notifications: Toggle Do Not Disturb Mode");
console.log("Toggled notifications");
}
console.log("Finished")

Check warning on line 60 in workspaces/bi/bi-extension/src/test/e2e-playwright-tests/utils.ts

View workflow job for this annotation

GitHub Actions / Build / Build repo

Missing semicolon
}

export async function setupBallerinaIntegrator() {
await page.selectSidebarItem('WSO2 Integrator: BI');
const webview = await switchToIFrame('WSO2 Integrator: BI', page.page);
const webview = await getWebview('WSO2 Integrator: BI', page);
if (!webview) {
throw new Error('WSO2 Integrator: BI webview not found');
}
Expand All @@ -76,7 +76,7 @@
await createNewIntegrationBtn.click({ force: true });
} catch (error) {
console.log('Create New Integration button not found, will use Set up Ballerina distribution button');
const setupButton = webview.getByRole('button', { name: 'Set up Ballerina distribution' })

Check warning on line 79 in workspaces/bi/bi-extension/src/test/e2e-playwright-tests/utils.ts

View workflow job for this annotation

GitHub Actions / Build / Build repo

Missing semicolon
await setupButton.waitFor();
await setupButton.click({ force: true });
const restartButton = webview.getByRole('button', { name: 'Restart VS Code' });
Expand All @@ -86,10 +86,51 @@
}
}

async function getWebview(viewName: string, page: ExtendedPage) {
let webview;
let retryCount = 0;
const maxRetries = 3;

while (retryCount < maxRetries) {
try {
await page.page.waitForLoadState('domcontentloaded');
await page.page.waitForTimeout(1000);

webview = await switchToIFrame(viewName, page.page);
if (webview) {
return webview;
}
// If webview is falsy, treat it as a failed attempt
console.log(`Attempt ${retryCount + 1} failed: switchToIFrame returned ${webview}`);
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
if (message.includes('Frame was detached')) {
console.log(`Frame was detached, retrying (${retryCount + 1}/${maxRetries})`);
} else {
console.log(`Attempt ${retryCount + 1} failed to access iframe:`, message);
}
}

// Always increment retry count after each attempt
retryCount++;

// Only retry if we haven't reached max retries
if (retryCount < maxRetries) {
await page.page.waitForTimeout(2000);
try {
await page.selectSidebarItem(viewName);
} catch (sidebarError) {
console.log('Failed to reselect sidebar item:', sidebarError);
}
}
}
throw new Error(`Failed to access iframe for ${viewName} after ${maxRetries} attempts`);
}

export async function createProject(page: ExtendedPage, projectName?: string) {
console.log('Creating new project');
await setupBallerinaIntegrator();
const webview = await switchToIFrame('WSO2 Integrator: BI', page.page, 60000);
const webview = await getWebview('WSO2 Integrator: BI', page);
if (!webview) {
throw new Error('WSO2 Integrator: BI webview not found');
}
Expand All @@ -108,7 +149,7 @@
}
});
await form.submit('Create Integration');
const artifactWebView = await switchToIFrame('WSO2 Integrator: BI', page.page);
const artifactWebView = await getWebview('WSO2 Integrator: BI', page);
if (!artifactWebView) {
throw new Error('WSO2 Integrator: BI webview not found');
}
Expand Down Expand Up @@ -148,7 +189,7 @@

export async function addArtifact(artifactName: string, testId: string) {
console.log(`Adding artifact: ${artifactName}`);
const artifactWebView = await switchToIFrame('WSO2 Integrator: BI', page.page);
const artifactWebView = await getWebview('WSO2 Integrator: BI', page);
if (!artifactWebView) {
throw new Error('WSO2 Integrator: BI webview not found');
}
Expand All @@ -162,7 +203,7 @@

export async function enableICP() {
console.log('Enabling ICP');
const webview = await switchToIFrame('WSO2 Integrator: BI', page.page);
const webview = await getWebview('WSO2 Integrator: BI', page);
if (!webview) {
throw new Error('WSO2 Integrator: BI webview not found');
}
Expand Down
Loading