Skip to content

Commit

Permalink
Completing add-cluster UI test
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Grossmann <lgrossma@redhat.com>
  • Loading branch information
lgrossma authored and vrubezhny committed May 14, 2024
1 parent 4aa33e6 commit 06b87fc
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 24 deletions.
23 changes: 22 additions & 1 deletion test/ui/common/conditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*-----------------------------------------------------------------------------------------------*/

import { BottomBarPanel, InputBox, Notification, NotificationType, ViewItem, ViewSection, WebDriver, Workbench } from 'vscode-extension-tester';
import { BottomBarPanel, EditorView, InputBox, Notification, NotificationType, ViewItem, ViewSection, WebDriver, WelcomeContentSection, Workbench } from 'vscode-extension-tester';

export async function waitForInputUpdate(input: InputBox, originalText: string, timeout = 5000): Promise<string> {
return input.getDriver().wait(async () => {
Expand Down Expand Up @@ -80,4 +80,25 @@ export async function terminalHasText(text: string, timeout = 60000, period = 50
}
await new Promise(res => setTimeout(res, period));
}, timeout);
}

export async function welcomeContentButtonsAreLoaded(welcomeContentSection: WelcomeContentSection, timeout = 60_000) {
return welcomeContentSection.getDriver().wait(async () => {
const buttons = await welcomeContentSection.getButtons();
if(buttons.length > 0) {
return buttons
}
}, timeout);
}

export async function webViewIsOpened(name: string, driver: WebDriver, timeout = 10_000) {
return driver.wait(async () => {
try {
const editor = new EditorView();
await editor.openEditor(name)
return true;
} catch(err) {
return null;
}
}, timeout)
}
122 changes: 119 additions & 3 deletions test/ui/common/ui/webview/addClusterWebView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,130 @@ export class AddClusterWebView extends WebViewForm {
await this.enterWebView(async (webView) => {
const button = await this.getStartYourOpenshiftExperienceButton(webView);
await button.click();
})
});
}

public async checkLearningButton(): Promise<void> {
await this.enterWebView(async (webView) => {
await this.getStartLearningButton(webView);
});
}

public async checkRosaButton(): Promise<void> {
await this.enterWebView(async (webView) => {
await this.getRosaButton(webView);
});
}

private async getCreateRefreshClusterButton(webView: WebView): Promise<WebElement> {
return await webView.findWebElement(By.xpath('//span[contains(text(),"Create/Refresh cluster")]'));
return await webView.findWebElement(By.xpath('//*[contains(text(),"Create/Refresh cluster")]'));
}

private async getStartYourOpenshiftExperienceButton(webView: WebView): Promise<WebElement> {
return await webView.findElement(By.xpath('//span[contains(text(),"Start your OpenShift experience")]'));
return await webView.findWebElement(By.xpath('//*[contains(text(),"Start your OpenShift experience")]'));
}

private async getStartLearningButton(webView: WebView): Promise<WebElement> {
return await webView.findWebElement(By.xpath('//*[contains(text(),"Start Learning")]'));
}

private async getRosaButton(webView: WebView): Promise<WebElement> {
return await webView.findWebElement(By.xpath('//*[contains(text(),"Create a ROSA cluster")]'));
}
}

export class LocalClusterWebViewPage extends WebViewForm {

public constructor() {
super('Add OpenShift Cluster');
}

public async checkText(): Promise<void> {
await this.enterWebView(async (webView) => {
await this.getText(webView);
});
}

public async checkDownloadButton(): Promise<void> {
await this.enterWebView(async (webView) => {
await this.getDownloadButton(webView);
});
}

public async checkPathButton(): Promise<void> {
await this.enterWebView(async (webView) => {
await this.getPathButton(webView);
});
}

public async clickBack(): Promise<void> {
await this.enterWebView(async (webView) => {
const button = await this.getBackButton(webView);
await button.click();
})
}

private async getText(webView: WebView): Promise<WebElement> {
return await webView.findWebElement(By.xpath('//*[contains(text(),"Red Hat OpenShift Local brings a minimal OpenShift 4 cluster")]'));
}

private async getDownloadButton(webView: WebView): Promise<WebElement> {
return await webView.findWebElement(By.xpath('//*[@role="button" and contains(text(),"Download OpenShift Local")]'));
}

private async getPathButton(webView: WebView): Promise<WebElement> {
return await webView.findWebElement(By.xpath('//*[contains(text(),"Select Path")]'));
}

private async getBackButton(webView: WebView): Promise<WebElement> {
return await webView.findWebElement(By.xpath('//button[contains(text(),"Back")]'));
}
}

export class DevSandboxWebViewPage extends WebViewForm {

public constructor() {
super('Add OpenShift Cluster');
}

public async checkText(): Promise<void> {
await this.enterWebView(async (webView) => {
await this.getText(webView);
});
}

public async checkLoginButton(): Promise<void> {
await this.enterWebView(async (webView) => {
await this.getLoginButton(webView);
});
}

public async checkSignUpButton(): Promise<void> {
await this.enterWebView(async (webView) => {
await this.getSignUpButton(webView);
});
}

public async clickBack(): Promise<void> {
await this.enterWebView(async (webView) => {
const button = await this.getBackButton(webView);
await button.click();
})
}

private async getText(webView: WebView): Promise<WebElement> {
return await webView.findWebElement(By.xpath('//*[contains(text(),"The sandbox provides you with a private OpenShift environment")]'));
}

private async getLoginButton(webView: WebView): Promise<WebElement> {
return await webView.findWebElement(By.xpath('//*[contains(text(),"Login to Red Hat")]'));
}

private async getSignUpButton(webView: WebView): Promise<WebElement> {
return await webView.findWebElement(By.xpath('//*[contains(text(),"Sign Up")]'));
}

private async getBackButton(webView: WebView): Promise<WebElement> {
return await webView.findWebElement(By.xpath('//button[contains(text(),"Back")]'));
}
}
24 changes: 12 additions & 12 deletions test/ui/public-ui-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*-----------------------------------------------------------------------------------------------*/

//import { checkAboutCommand } from './suite/command-about';
//import path = require('path');
//import { testCreateComponent } from './suite/createComponent';
//import { testDevfileRegistries } from './suite/devfileRegistries';
import { checkAboutCommand } from './suite/command-about';
import path = require('path');
import { testCreateComponent } from './suite/createComponent';
import { testDevfileRegistries } from './suite/devfileRegistries';
import { checkExtension } from './suite/extension';
//import { checkFocusOnCommands } from './suite/focusOn';
import { checkFocusOnCommands } from './suite/focusOn';
import { checkOpenshiftView } from './suite/openshift';
//import { testCreateServerlessFunction } from './suite/serverlessFunction';
import { testCreateServerlessFunction } from './suite/serverlessFunction';
import { testAddCluster } from './suite/addCluster';

require('source-map-support').install();

describe('Extension public-facing UI tests', function() {
//const contextFolder = path.join(__dirname, 'context');
const contextFolder = path.join(__dirname, 'context');

checkExtension();
checkOpenshiftView();
testAddCluster();
//checkAboutCommand();
//testDevfileRegistries();
//checkFocusOnCommands();
//testCreateComponent(contextFolder);
//testCreateServerlessFunction(contextFolder);
checkAboutCommand();
testDevfileRegistries();
checkFocusOnCommands();
testCreateComponent(contextFolder);
testCreateServerlessFunction(contextFolder);
});
44 changes: 36 additions & 8 deletions test/ui/suite/addCluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@
* Copyright (c) Red Hat, Inc. All rights reserved.
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*-----------------------------------------------------------------------------------------------*/
import { ActivityBar, EditorView, SideBarView } from 'vscode-extension-tester';
import { ActivityBar, EditorView, SideBarView, VSBrowser } from 'vscode-extension-tester';
import { VIEWS } from '../common/constants';
import { collapse } from '../common/overdrives';
import { AddClusterWebView } from '../common/ui/webview/addClusterWebView';
import { AddClusterWebView, DevSandboxWebViewPage, LocalClusterWebViewPage } from '../common/ui/webview/addClusterWebView';
import { webViewIsOpened, welcomeContentButtonsAreLoaded } from '../common/conditions';

export function testAddCluster() {
describe('Add Cluster', function () {

let view: SideBarView;
let addClusterView;

before(async function context() {
this.timeout(30_000)
//await new Promise((res) => {setTimeout(res, 20_000)});
await new EditorView().closeAllEditors();
view = await (await new ActivityBar().getViewControl(VIEWS.openshift)).openView();
for (const item of [VIEWS.components, VIEWS.compRegistries, VIEWS.serverlessFunctions, VIEWS.debugSessions]) {
Expand All @@ -21,15 +25,39 @@ export function testAddCluster() {
});

it('Page with options is shown', async function test() {
this.timeout(15_000);
await new Promise((res) => {setTimeout(res, 6_000)});
this.timeout(70_000);
//await new Promise((res) => {setTimeout(res, 15_000)});
const section = await view.getContent().getSection(VIEWS.appExplorer);
const buttons = await (await section.findWelcomeContent()).getButtons();
const welcomeContent = await section.findWelcomeContent();
const buttons = await welcomeContentButtonsAreLoaded(welcomeContent);
await buttons[2].click();

const addClusterView = new AddClusterWebView();
addClusterView = new AddClusterWebView();
await webViewIsOpened(addClusterView.editorName, VSBrowser.instance.driver);

await addClusterView.initializeEditor();
await addClusterView.checkRosaButton();
await addClusterView.checkLearningButton();
});

it('Local Cluster Page shows appropriate content', async function test() {
await addClusterView.addLocalCluster();
})
})
const localClusterPage = new LocalClusterWebViewPage();
await localClusterPage.initializeEditor();
await localClusterPage.checkText();
await localClusterPage.checkDownloadButton();
await localClusterPage.checkPathButton();
await localClusterPage.clickBack();
});

it('Developer Sandbox Page shows appropriate content', async function test() {
await addClusterView.addDevSandbox();
const devSandboxWebViewPage = new DevSandboxWebViewPage();
await devSandboxWebViewPage.initializeEditor();
await devSandboxWebViewPage.checkText();
await devSandboxWebViewPage.checkLoginButton();
await devSandboxWebViewPage.checkSignUpButton();
await devSandboxWebViewPage.clickBack();
});
});
}

0 comments on commit 06b87fc

Please sign in to comment.