Skip to content
Open
Show file tree
Hide file tree
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
16 changes: 13 additions & 3 deletions packages/flex-plugin-e2e-tests/src/tests/step006.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable */
import { replaceInFile } from 'replace-in-file';
import { logger } from '@twilio/flex-dev-utils';

import { TestSuite, TestParams, testParams } from '../core';
import { spawn, Browser, pluginHelper, joinPath, assertion, killChildProcess, retryOnError } from '../utils';
Expand All @@ -21,16 +22,25 @@ const testSuite: TestSuite = async ({ scenario, config, secrets, environment }:
testParams.config.start.timeout,
testParams.config.start.pollInterval,
);
await Browser.create({ flex: plugin.localhostUrl, twilioConsole: config.consoleBaseUrl });

const loginAndAssert = async (firstLoad: boolean) => {
// Recreate browser on each attempt to avoid using detached pages
if (!firstLoad) {
await Browser.kill();
}
await Browser.create({ flex: plugin.localhostUrl, twilioConsole: config.consoleBaseUrl });

await Browser.app.twilioConsole.login('agent-desktop', secrets.api.accountSid, config.localhostPort, firstLoad);
await assertion.app.view.agentDesktop.isVisible();
await assertion.app.view.plugins.plugin.isVisible(plugin.componentText);
};

const onError = async (e: any) => {
await Browser.app.takeScreenshot(environment.cwd, 'step006_failure.png');
const onError = async () => {
try {
await Browser.app.takeScreenshot(environment.cwd, 'step006_failure.png');
} catch (screenshotError) {
logger.error('Failed to take screenshot:', screenshotError);
}
};

const onFinally = async () => {
Expand Down
35 changes: 21 additions & 14 deletions packages/flex-plugin-e2e-tests/src/tests/step010.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,38 @@ const testSuite: TestSuite = async ({ scenario, config, secrets, environment }:
throw new Error(`Did not find plugin with name: ${plugin.name} in released plugins`);
}

await Browser.create({ flex: config.hostedFlexBaseUrl, twilioConsole: config.consoleBaseUrl });
// Log into Flex
await Browser.app.twilioConsole.login('admin', secrets.api.accountSid, config.localhostPort);
const loginAndAssert = async (firstLoad: boolean) => {
// Recreate browser on each attempt to avoid using detached pages
if (!firstLoad) {
await Browser.kill();
}
await Browser.create({ flex: config.hostedFlexBaseUrl, twilioConsole: config.consoleBaseUrl });

await assertion.app.view.adminDashboard.isVisible();
// Log into Flex
await Browser.app.twilioConsole.login('admin', secrets.api.accountSid, config.localhostPort);

// Verify that user is on the right account
const accountSid = await Browser.app.getFlexAccountSid();
assertion.equal(accountSid, secrets.api.accountSid);
// Make sure that /plugins contain the plugin
await pluginHelper.waitForPluginToRelease(releasedPlugin, PLUGIN_RELEASED_TIMEOUT, PLUGIN_RELEASED_POLL_INTERVAL);
// await assertRetry();
await assertion.app.view.adminDashboard.isVisible();

const loginAndAssert = async () => {
// Load local plugin
// Verify that user is on the right account
const accountSid = await Browser.app.getFlexAccountSid();
assertion.equal(accountSid, secrets.api.accountSid);
// Make sure that /plugins contain the plugin
await pluginHelper.waitForPluginToRelease(releasedPlugin, PLUGIN_RELEASED_TIMEOUT, PLUGIN_RELEASED_POLL_INTERVAL);

// Load local plugin
await Browser.app.agentDesktop.open();
logger.info('Agent Desktop opened');

// Check if the element is visible
await assertion.app.view.plugins.plugin.isVisible(plugin.newlineValue!);
};

const onError = async (e: any) => {
await Browser.app.takeScreenshot(environment.cwd, 'step010_failure.png');
const onError = async () => {
try {
await Browser.app.takeScreenshot(environment.cwd, 'step010_failure.png');
} catch (screenshotError) {
logger.error('Failed to take screenshot:', screenshotError);
}
};

const onFinally = async () => {
Expand Down
17 changes: 13 additions & 4 deletions packages/flex-plugin-e2e-tests/src/tests/step011.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* eslint-disable import/no-unused-modules */
import { logger } from '@twilio/flex-dev-utils';

import { TestSuite, TestParams, testParams } from '../core';
import { spawn, Browser, pluginHelper, assertion, killChildProcess, retryOnError } from '../utils';

Expand Down Expand Up @@ -26,10 +28,13 @@ const testSuite: TestSuite = async ({ scenario, config, secrets, environment }:
{ detached: true, cwd: plugin3.dir },
);
await Promise.all([startPlugin(plugin2.localhostUrl), startPlugin(plugin3.localhostUrl)]);
await Browser.create({ flex: plugin3.localhostUrl, twilioConsole: config.consoleBaseUrl });

const loginAndAssert = async (firstLoad: boolean) => {
// Load local plugin
// Recreate browser on each attempt to avoid using detached pages
if (!firstLoad) {
await Browser.kill();
}
await Browser.create({ flex: plugin3.localhostUrl, twilioConsole: config.consoleBaseUrl });

await Browser.app.twilioConsole.login('agent-desktop', secrets.api.accountSid, config.localhostPort, firstLoad);

Expand All @@ -42,8 +47,12 @@ const testSuite: TestSuite = async ({ scenario, config, secrets, environment }:
await assertion.app.view.plugins.plugin.isVisible(plugin3.componentText);
};

const onError = async (e: any) => {
await Browser.app.takeScreenshot(environment.cwd, 'step011_failure.png');
const onError = async () => {
try {
await Browser.app.takeScreenshot(environment.cwd, 'step011_failure.png');
} catch (screenshotError) {
logger.error('Failed to take screenshot:', screenshotError);
}
};

const onFinally = async () => {
Expand Down
17 changes: 13 additions & 4 deletions packages/flex-plugin-e2e-tests/src/tests/step012.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable import/no-unused-modules */
import semver from 'semver';
import { logger } from '@twilio/flex-dev-utils';

import { TestSuite, TestParams, testParams } from '../core';
import { spawn, Browser, pluginHelper, api, assertion, killChildProcess, retryOnError } from '../utils';
Expand Down Expand Up @@ -51,9 +52,13 @@ const testSuite: TestSuite = async ({ scenario, config, secrets, environment }:
testParams.config.start.pollInterval,
);

await Browser.create({ flex: plugin3.localhostUrl, twilioConsole: config.consoleBaseUrl });

const loginAndAssert = async (firstLoad: boolean) => {
// Recreate browser on each attempt to avoid using detached pages
if (!firstLoad) {
await Browser.kill();
}
await Browser.create({ flex: plugin3.localhostUrl, twilioConsole: config.consoleBaseUrl });

await Browser.app.twilioConsole.login('agent-desktop', secrets.api.accountSid, config.localhostPort, firstLoad);

// Check if local plugin loaded okay
Expand All @@ -65,8 +70,12 @@ const testSuite: TestSuite = async ({ scenario, config, secrets, environment }:
await assertion.app.view.plugins.plugin.isVisible(plugin3.componentText);
};

const onError = async (e: any) => {
await Browser.app.takeScreenshot(environment.cwd, 'step012_failure.png');
const onError = async () => {
try {
await Browser.app.takeScreenshot(environment.cwd, 'step012_failure.png');
} catch (screenshotError) {
logger.error('Failed to take screenshot:', screenshotError);
}
};

const onFinally = async () => {
Expand Down
17 changes: 13 additions & 4 deletions packages/flex-plugin-e2e-tests/src/tests/step013.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable import/no-unused-modules */
import { replaceInFile } from 'replace-in-file';
import semver from 'semver';
import { logger } from '@twilio/flex-dev-utils';

import { TestSuite, TestParams, testParams } from '../core';
import { spawn, Browser, pluginHelper, joinPath, assertion, killChildProcess, api, retryOnError } from '../utils';
Expand Down Expand Up @@ -54,10 +55,14 @@ const testSuite: TestSuite = async ({ scenario, config, secrets, environment }:
cwd: plugin3.dir,
});
await Promise.all([startPlugin(plugin2.localhostUrl), startPlugin(plugin3.localhostUrl)]);
await Browser.create({ flex: plugin3.localhostUrl, twilioConsole: config.consoleBaseUrl });

const loginAndAssert = async (firstLoad: boolean) => {
// Load local plugin
// Recreate browser on each attempt to avoid using detached pages
if (!firstLoad) {
await Browser.kill();
}
await Browser.create({ flex: plugin3.localhostUrl, twilioConsole: config.consoleBaseUrl });

await Browser.app.twilioConsole.login('agent-desktop', secrets.api.accountSid, config.localhostPort, firstLoad);

// Check if local plugin loaded okay
Expand All @@ -69,8 +74,12 @@ const testSuite: TestSuite = async ({ scenario, config, secrets, environment }:
await assertion.app.view.plugins.plugin.isVisible(plugin3.componentText);
};

const onError = async (e: any) => {
await Browser.app.takeScreenshot(environment.cwd, 'step013_failure.png');
const onError = async () => {
try {
await Browser.app.takeScreenshot(environment.cwd, 'step013_failure.png');
} catch (screenshotError) {
logger.error('Failed to take screenshot:', screenshotError);
}
};

const onFinally = async () => {
Expand Down
19 changes: 7 additions & 12 deletions packages/flex-plugin-e2e-tests/src/utils/pages/view/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,21 @@ export abstract class Base {
}): Promise<void> {
const fullPath = path ? `${baseUrl}/${path}` : baseUrl;
try {
await Promise.all([
this.page.waitForNavigation({
waitUntil: 'networkidle2', // condition to consider navigation finished
timeout: Base.DEFAULT_PAGE_LOAD_TIMEOUT,
}),
this.page.goto(fullPath, {
waitUntil: waitUntil || 'networkidle2',
timeout: Base.DEFAULT_PAGE_LOAD_TIMEOUT,
}),
]);
await this.page.goto(fullPath, {
waitUntil: waitUntil || 'networkidle2',
timeout: Base.DEFAULT_PAGE_LOAD_TIMEOUT,
});
} catch (err) {
if (err.message.includes('detached')) {
if (err instanceof Error && err.message.includes('detached')) {
logger.error('Page has been detached. adding a sleep to let other processes finish');
/*
* Just let it wait the rest of the timeout so the other contestants in the rest
* can finish first.
*/
await sleep(5000);
}
// Intentionally doing nothing on error
// Re-throw all errors so they propagate to test error handlers for screenshots
throw err;
}
}

Expand Down
Loading