From 56c6f095df2f7e68fdda3bf9dd3e56eb1dca1d20 Mon Sep 17 00:00:00 2001 From: Keith Chong Date: Fri, 3 Jan 2025 14:37:55 -0500 Subject: [PATCH] test: Update ui test to fix logic for headless mode, add logs (#21361) Signed-off-by: Keith Chong --- ui-test/src/UiTestUtilities.ts | 11 +++--- .../application-create-panel.ts | 39 ++++++++++++------- .../applications-list/applications-list.ts | 14 +++---- .../applications-sync-panel.ts | 4 +- ui-test/src/navigation.ts | 8 ++-- 5 files changed, 43 insertions(+), 33 deletions(-) diff --git a/ui-test/src/UiTestUtilities.ts b/ui-test/src/UiTestUtilities.ts index ac38790ca1e4e..bdc1e201e10bc 100644 --- a/ui-test/src/UiTestUtilities.ts +++ b/ui-test/src/UiTestUtilities.ts @@ -49,21 +49,20 @@ export default class UiTestUtilities { */ public static async init(): Promise { const options = new chrome.Options(); - if (process.env.IS_HEADLESS) { + UiTestUtilities.log('Env var IS_HEADLESS = ' + process.env.IS_HEADLESS); + if (process.env.IS_HEADLESS !== 'false') { + UiTestUtilities.log('Adding headless option'); options.addArguments('headless'); } options.addArguments('window-size=1400x1200'); - const driver = await new Builder() - .forBrowser('chrome') - .setChromeOptions(options) - .build(); + const driver = await new Builder().forBrowser('chrome').setChromeOptions(options).build(); UiTestUtilities.log('Environment variables are:'); UiTestUtilities.log(require('dotenv').config({path: __dirname + '/../.env'})); // Navigate to the ArgoCD URL await driver.get(Configuration.ARGOCD_URL); - + UiTestUtilities.log('Navigate to Argo CD URL successful: driver.get'); return new Navigation(driver); } diff --git a/ui-test/src/application-create-panel/application-create-panel.ts b/ui-test/src/application-create-panel/application-create-panel.ts index a153611aa47bd..713845c2dfabc 100644 --- a/ui-test/src/application-create-panel/application-create-panel.ts +++ b/ui-test/src/application-create-panel/application-create-panel.ts @@ -31,7 +31,8 @@ export class ApplicationCreatePanel extends Base { try { const appNameField = await UiTestUtilities.findUiElement(this.driver, CREATE_APPLICATION_FIELD_APP_NAME); await appNameField.sendKeys(appName); - } catch (err) { + } catch (err: any) { + UiTestUtilities.log('Error caught while setting app name: ' + err); throw new Error(err); } } @@ -40,7 +41,8 @@ export class ApplicationCreatePanel extends Base { try { const project = await UiTestUtilities.findUiElement(this.driver, CREATE_APPLICATION_FIELD_PROJECT); await project.sendKeys(projectName); - } catch (err) { + } catch (err: any) { + UiTestUtilities.log('Error caught while setting project name: ' + err); throw new Error(err); } } @@ -49,7 +51,8 @@ export class ApplicationCreatePanel extends Base { try { const reposUrl = await UiTestUtilities.findUiElement(this.driver, CREATE_APPLICATION_FIELD_REPOSITORY_URL); await reposUrl.sendKeys(sourceRepoUrl); - } catch (err) { + } catch (err: any) { + UiTestUtilities.log('Error caught while setting source repo URL: ' + err); throw new Error(err); } } @@ -58,7 +61,8 @@ export class ApplicationCreatePanel extends Base { try { const path = await UiTestUtilities.findUiElement(this.driver, CREATE_APPLICATION_FIELD_REPOSITORY_PATH); await path.sendKeys(sourceRepoPath); - } catch (err) { + } catch (err: any) { + UiTestUtilities.log('Error caught while setting source repo path: ' + err); throw new Error(err); } } @@ -78,7 +82,8 @@ export class ApplicationCreatePanel extends Base { if (destinationClusterFieldValue) { await this.setDestinationClusterUrl(destinationClusterFieldValue); } - } catch (err) { + } catch (err: any) { + UiTestUtilities.log('Error caught while selecting destination cluster URL menu: ' + err); throw new Error(err); } } @@ -98,7 +103,8 @@ export class ApplicationCreatePanel extends Base { if (destinationClusterFieldValue) { await this.setDestinationClusterName(destinationClusterFieldValue); } - } catch (err) { + } catch (err: any) { + UiTestUtilities.log('Error caught while selecting destination cluster name menu: ' + err); throw new Error(err); } } @@ -108,7 +114,8 @@ export class ApplicationCreatePanel extends Base { const clusterName = await UiTestUtilities.findUiElement(this.driver, CREATE_APPLICATION_FIELD_CLUSTER_NAME); await clusterName.sendKeys(destinationClusterName); // await clusterName.sendKeys('\r'); - } catch (err) { + } catch (err: any) { + UiTestUtilities.log('Error caught while setting destination cluster name: ' + err); throw new Error(err); } } @@ -117,7 +124,8 @@ export class ApplicationCreatePanel extends Base { try { const clusterUrl = await UiTestUtilities.findUiElement(this.driver, CREATE_APPLICATION_FIELD_CLUSTER_URL); await clusterUrl.sendKeys(destinationClusterUrl); - } catch (err) { + } catch (err: any) { + UiTestUtilities.log('Error caught while setting destination cluster URL: ' + err); throw new Error(err); } } @@ -126,7 +134,8 @@ export class ApplicationCreatePanel extends Base { try { const namespace = await UiTestUtilities.findUiElement(this.driver, CREATE_APPLICATION_FIELD_CLUSTER_NAMESPACE); await namespace.sendKeys(destinationNamespace); - } catch (err) { + } catch (err: any) { + UiTestUtilities.log('Error caught while setting destination namespace: ' + err); throw new Error(err); } } @@ -140,12 +149,13 @@ export class ApplicationCreatePanel extends Base { await createButton.click(); // Wait until the Create Application Sliding Panel disappears - await this.driver.wait(until.elementIsNotVisible(createButton), Const.TEST_SLIDING_PANEL_TIMEOUT).catch(e => { + await this.driver.wait(until.elementIsNotVisible(createButton), Const.TEST_SLIDING_PANEL_TIMEOUT).catch((e) => { UiTestUtilities.logError('The Create Application Sliding Panel did not disappear'); throw e; }); await this.driver.sleep(1000); - } catch (err) { + } catch (err: any) { + UiTestUtilities.log('Error caught while clicking Create button: ' + err); throw new Error(err); } } @@ -159,11 +169,12 @@ export class ApplicationCreatePanel extends Base { await cancelButton.click(); // Wait until the Create Application Sliding Panel disappears - await this.driver.wait(until.elementIsNotVisible(cancelButton), Const.TEST_SLIDING_PANEL_TIMEOUT).catch(e => { + await this.driver.wait(until.elementIsNotVisible(cancelButton), Const.TEST_SLIDING_PANEL_TIMEOUT).catch((e) => { UiTestUtilities.logError('The Create Application Sliding Panel did not disappear'); throw e; }); - } catch (err) { + } catch (err: any) { + UiTestUtilities.log('Error caught while clicking Cancel button: ' + err); throw new Error(err); } } @@ -198,7 +209,7 @@ export class ApplicationCreatePanel extends Base { await this.selectDestinationClusterNameMenu(destinationClusterName); await this.setDestinationNamespace(destinationNamespace); await this.clickCreateButton(); - } catch (err) { + } catch (err: any) { throw new Error(err); } } diff --git a/ui-test/src/applications-list/applications-list.ts b/ui-test/src/applications-list/applications-list.ts index ae76b9d80c045..90dfb791a93cb 100644 --- a/ui-test/src/applications-list/applications-list.ts +++ b/ui-test/src/applications-list/applications-list.ts @@ -27,7 +27,7 @@ export class ApplicationsList extends Base { try { const tile = await UiTestUtilities.findUiElement(this.driver, this.getApplicationTileLocator(appName)); await tile.click(); - } catch (err) { + } catch (err: any) { throw new Error(err); } } @@ -39,7 +39,7 @@ export class ApplicationsList extends Base { try { const newAppButton = await UiTestUtilities.findUiElement(this.driver, NEW_APP_BUTTON); await newAppButton.click(); - } catch (err) { + } catch (err: any) { throw new Error(err); } return this.applicationCreatePanel; @@ -57,7 +57,7 @@ export class ApplicationsList extends Base { // Wait until the Synchronize sliding panel appears const synchronizeButton = await this.driver.wait(until.elementLocated(SYNC_PANEL_SYNCHRONIZE_BUTTON), Const.TEST_TIMEOUT); await this.driver.wait(until.elementIsVisible(synchronizeButton), Const.TEST_TIMEOUT); - } catch (err) { + } catch (err: any) { throw new Error(err); } return this.applicationsSyncPanel; @@ -72,7 +72,7 @@ export class ApplicationsList extends Base { try { const deleteButton = await UiTestUtilities.findUiElement(this.driver, this.getDeleteButtonLocatorForApp(appName)); await deleteButton.click(); - } catch (err) { + } catch (err: any) { throw new Error(err); } return this.popupManager; @@ -95,7 +95,7 @@ export class ApplicationsList extends Base { const refreshButton = await UiTestUtilities.findUiElement(this.driver, this.getRefreshButtonLocatorForApp(appName)); await this.driver.wait(until.elementIsVisible(refreshButton), Const.TEST_TIMEOUT); await refreshButton.click(); - } catch (err) { + } catch (err: any) { throw new Error(err); } } @@ -111,7 +111,7 @@ export class ApplicationsList extends Base { await this.driver.wait(async () => { return UiTestUtilities.untilAttributeIs(healthStatusElement, 'title', 'Healthy'); }, Const.TEST_TIMEOUT); - } catch (err) { + } catch (err: any) { throw new Error(err); } } @@ -127,7 +127,7 @@ export class ApplicationsList extends Base { await this.driver.wait(async () => { return UiTestUtilities.untilAttributeIs(statusElement, 'title', 'Synced'); }, Const.TEST_TIMEOUT); - } catch (err) { + } catch (err: any) { throw new Error(err); } } diff --git a/ui-test/src/applications-sync-panel/applications-sync-panel.ts b/ui-test/src/applications-sync-panel/applications-sync-panel.ts index 9a5f266de58f3..dfd4b8c6010d3 100644 --- a/ui-test/src/applications-sync-panel/applications-sync-panel.ts +++ b/ui-test/src/applications-sync-panel/applications-sync-panel.ts @@ -23,12 +23,12 @@ export class ApplicationsSyncPanel extends Base { await this.driver.wait(until.elementIsEnabled(synchronizeButton), Const.TEST_TIMEOUT); await synchronizeButton.click(); - await this.driver.wait(until.elementIsNotVisible(synchronizeButton), Const.TEST_SLIDING_PANEL_TIMEOUT).catch(e => { + await this.driver.wait(until.elementIsNotVisible(synchronizeButton), Const.TEST_SLIDING_PANEL_TIMEOUT).catch((e) => { UiTestUtilities.logError('The Synchronization Sliding Panel did not disappear'); throw e; }); UiTestUtilities.log('Synchronize sliding panel disappeared'); - } catch (err) { + } catch (err: any) { throw new Error(err); } } diff --git a/ui-test/src/navigation.ts b/ui-test/src/navigation.ts index 8baaff37e4d38..79618405f3761 100644 --- a/ui-test/src/navigation.ts +++ b/ui-test/src/navigation.ts @@ -31,7 +31,7 @@ export class Navigation extends Base { try { const navBarButton = await UiTestUtilities.findUiElement(this.driver, NAVBAR_APPLICATIONS_BUTTON); await navBarButton.click(); - } catch (err) { + } catch (err: any) { throw new Error(err); } return this.applicationsList; @@ -45,7 +45,7 @@ export class Navigation extends Base { try { const navBarButton = await UiTestUtilities.findUiElement(this.driver, NAVBAR_SETTINGS_BUTTON); await navBarButton.click(); - } catch (err) { + } catch (err: any) { throw new Error(err); } } @@ -58,7 +58,7 @@ export class Navigation extends Base { try { const navBarButton = await UiTestUtilities.findUiElement(this.driver, NAVBAR_USER_INFO_BUTTON); await navBarButton.click(); - } catch (err) { + } catch (err: any) { throw new Error(err); } } @@ -71,7 +71,7 @@ export class Navigation extends Base { try { const navBarButton = await UiTestUtilities.findUiElement(this.driver, NAVBAR_DOCS_BUTTON); await navBarButton.click(); - } catch (err) { + } catch (err: any) { throw new Error(err); } }