Skip to content
Merged
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
145 changes: 145 additions & 0 deletions zeppelin-web-angular/e2e/models/interpreter-page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { Locator, Page } from '@playwright/test';

export class InterpreterPage {
readonly title: Locator;
readonly description: Locator;
readonly search: Locator;
readonly repositoryButton: Locator;
readonly createCard: Locator;
readonly settings: Locator;
readonly settingTitles: Locator;

constructor(readonly page: Page) {
this.title = page.getByRole('heading', { level: 2, name: /^Interpreters(?:\s|$)/ });
this.description = page.getByText('Manage interpreters settings.', { exact: false });
this.search = page.getByPlaceholder('Search interpreters...', { exact: true });
this.repositoryButton = page.getByRole('button', { name: 'Repository', exact: true });
this.createCard = page.getByText('Create', { exact: true });
this.settings = page.getByTestId('interpreter-setting');
this.settingTitles = this.settings
.getByRole('heading', { level: 3 })
.filter({ has: page.getByTestId('interpreter-status') });
}

setting(name: string): InterpreterItemPage {
const escaped = name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
return new InterpreterItemPage(
this.page,
this.settings.filter({
has: this.page.getByRole('heading', { level: 3, name: new RegExp(`^${escaped}\\s+%`) })
})
);
}

createForm(): InterpreterItemPage {
return new InterpreterItemPage(this.page, this.page.getByTestId('interpreter-create-form'));
}
}

export class InterpreterItemPage {
readonly edit: Locator;
readonly restart: Locator;
readonly remove: Locator;
readonly save: Locator;
readonly cancel: Locator;
readonly name: Locator;
readonly group: Locator;
readonly status: Locator;
readonly properties: Locator;
readonly dependencies: Locator;
readonly newProperty: Locator;
readonly propertyKey: Locator;
readonly propertyValue: Locator;
readonly propertyType: Locator;
readonly artifact: Locator;
readonly exclusions: Locator;
readonly existingProcess: Locator;
readonly host: Locator;
readonly port: Locator;
readonly setPermission: Locator;
readonly owners: Locator;
readonly tooltip: Locator;
readonly bindingMenu: Locator;
readonly bindingMode: Locator;

constructor(
readonly page: Page,
readonly card: Locator
) {
this.edit = card.getByRole('button', { name: 'Edit', exact: true });
this.restart = card.getByRole('button', { name: 'Restart', exact: true });
this.remove = card.getByRole('button', { name: 'Remove', exact: true });
this.save = card.getByRole('button', { name: 'Save', exact: true });
this.cancel = card.getByRole('button', { name: 'Cancel', exact: true });
this.name = card.getByPlaceholder('interpreter name', { exact: true });
this.group = card.getByTestId('interpreter-group');
this.status = card.getByTestId('interpreter-status');
this.properties = card.getByTestId('interpreter-properties');
this.dependencies = card.getByTestId('interpreter-dependencies');
this.newProperty = this.properties
.getByRole('row')
.filter({ has: page.getByRole('button', { name: 'Add property', exact: true }) });
this.propertyKey = this.newProperty.getByRole('cell').nth(0).getByRole('textbox');
this.propertyValue = this.newProperty.getByRole('cell').nth(1).locator('input:not([readonly]), textarea');
this.propertyType = this.newProperty.locator('.type-selector');
this.artifact = card.getByPlaceholder('groupId:artifactId:version or local file path', { exact: true });
this.exclusions = card.getByPlaceholder('(Optional) comma separated groupId:artifactId list', { exact: true });
this.existingProcess = card.getByRole('checkbox', { name: 'Connect to existing process', exact: true });
this.host = card.getByRole('textbox', { name: 'Host', exact: true });
this.port = card.getByRole('spinbutton', { name: 'Port', exact: true });
this.setPermission = card.getByRole('checkbox', { name: 'Set permission', exact: true });
this.owners = card.getByTestId('interpreter-owners');
this.tooltip = page.locator('.ant-tooltip-inner:visible');
this.bindingMenu = page.locator('.ant-dropdown:visible');
this.bindingMode = card.locator('.ant-dropdown-trigger').first();
}

propertyRow(key: string): Locator {
return this.properties.getByRole('row').filter({ has: this.page.getByRole('cell', { name: key, exact: true }) });
}

propertyCell(key: string): Locator {
return this.propertyRow(key).getByRole('cell').nth(1);
}

passwordValue(key: string): Locator {
return this.propertyCell(key).locator('input[type="password"]');
}

editableDependencyRow(index: number): Locator {
return this.dependencies
.getByRole('row')
.filter({
has: this.page.getByRole('button', { name: 'Remove dependency', exact: true })
})
.nth(index);
}

dependencyRow(artifact: string): Locator {
return this.dependencies
.getByRole('row')
.filter({ has: this.page.getByRole('cell', { name: artifact, exact: true }) });
}

async selectGroup(name: string): Promise<void> {
await this.group.click();
await this.page.locator('.ant-select-dropdown:visible').getByText(name, { exact: true }).click();
}

async selectPropertyType(name: string): Promise<void> {
await this.propertyType.click();
await this.page.locator('.ant-select-dropdown:visible').getByText(name, { exact: true }).click();
}
}
48 changes: 39 additions & 9 deletions zeppelin-web-angular/e2e/models/interpreter-repository-modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,44 @@ export interface RepositoryProxyCredentials {
export class InterpreterRepositoryModal extends BasePage {
readonly repositoryTrigger: Locator;
readonly createRepositoryTag: Locator;
readonly dialog: Locator;
readonly idInput: Locator;
readonly urlInput: Locator;
readonly urlProtocol: Locator;
readonly snapshotSwitch: Locator;
readonly usernameInput: Locator;
readonly passwordInput: Locator;
readonly proxyHttpRadio: Locator;
readonly proxyHttpsRadio: Locator;
readonly proxyHostInput: Locator;
readonly proxyPortInput: Locator;
readonly proxyLoginInput: Locator;
readonly proxyPasswordInput: Locator;
readonly addButton: Locator;
readonly dismissButton: Locator;

constructor(page: Page) {
super(page);
this.repositoryTrigger = page.locator('button.repository-trigger');
this.createRepositoryTag = page.locator('nz-tag.editable-tag');
this.idInput = page.locator('input[placeholder="Repository id"]');
this.urlInput = page.locator('input[placeholder="Repository url"]');
// Locate the proxy inputs by placeholder, not formControlName: the binding is
// what the regression test exercises, so the locator must not depend on it.
this.proxyLoginInput = page.locator('input[placeholder="proxy login"]');
this.proxyPasswordInput = page.locator('input[placeholder="proxy password"]');
this.addButton = page.getByRole('button', { name: 'Add', exact: true });
this.repositoryTrigger = page.getByRole('button', { name: 'Repository', exact: true });
this.createRepositoryTag = page.getByTestId('create-interpreter-repository');
this.dialog = page.getByRole('dialog').filter({
has: page.getByText('Add New Repository', { exact: true })
});
this.idInput = this.dialog.getByPlaceholder('Repository id', { exact: true });
this.urlInput = this.dialog.getByPlaceholder('Repository url', { exact: true });
this.urlProtocol = this.dialog.getByTestId('repository-url-protocol');
this.snapshotSwitch = this.dialog.locator('.ant-switch');
this.usernameInput = this.dialog.getByPlaceholder('username', { exact: true });
this.passwordInput = this.dialog.getByPlaceholder('password', { exact: true });
this.proxyHttpRadio = this.dialog.getByRole('radio', { name: 'HTTP', exact: true });
this.proxyHttpsRadio = this.dialog.getByRole('radio', { name: 'HTTPS', exact: true });
this.proxyHostInput = this.dialog.getByPlaceholder('proxy host', { exact: true });
this.proxyPortInput = this.dialog.getByPlaceholder('proxy port', { exact: true });
// The proxy binding is under test, so locate it by its user-facing placeholder.
this.proxyLoginInput = this.dialog.getByPlaceholder('proxy login', { exact: true });
this.proxyPasswordInput = this.dialog.getByPlaceholder('proxy password', { exact: true });
this.addButton = this.dialog.getByRole('button', { name: 'Add', exact: true });
this.dismissButton = this.dialog.getByRole('button', { name: 'Cancel', exact: true });
}

async navigate(): Promise<void> {
Expand All @@ -52,6 +73,15 @@ export class InterpreterRepositoryModal extends BasePage {
await this.idInput.waitFor({ state: 'visible' });
}

async selectUrlProtocol(protocol: 'http://' | 'https://' | 'file://'): Promise<void> {
await this.urlProtocol.click();
await this.page.locator('.ant-select-dropdown:visible').getByText(protocol, { exact: true }).click();
}

async selectProxyProtocol(protocol: 'HTTP' | 'HTTPS'): Promise<void> {
await this.dialog.getByText(protocol, { exact: true }).click();
}

async fillProxyRepository(form: RepositoryProxyCredentials): Promise<void> {
await this.fillAndVerifyInput(this.idInput, form.id);
await this.fillAndVerifyInput(this.urlInput, form.url);
Expand Down
51 changes: 51 additions & 0 deletions zeppelin-web-angular/e2e/models/interpreter-repository-page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { Locator, Page } from '@playwright/test';

export class InterpreterRepositoryPage {
readonly repositoryTrigger: Locator;
readonly panel: Locator;
readonly heading: Locator;
readonly repositoryTags: Locator;
readonly createRepositoryTag: Locator;
readonly closeIcons: Locator;
readonly tooltip: Locator;
readonly deleteDialog: Locator;
readonly deleteMessage: Locator;
readonly confirmDeleteButton: Locator;
readonly cancelDeleteButton: Locator;

constructor(private readonly page: Page) {
this.repositoryTrigger = page.getByRole('button', { name: 'Repository', exact: true });
this.panel = page.getByTestId('interpreter-repositories');
this.heading = this.panel.getByRole('heading', { name: 'Repositories', exact: true });
this.repositoryTags = this.panel.getByTestId('interpreter-repository');
this.createRepositoryTag = this.panel.getByTestId('create-interpreter-repository');
this.closeIcons = page.locator('.anticon-close');
this.tooltip = page.locator('.ant-tooltip-inner:visible');
this.deleteDialog = page.getByRole('dialog').filter({
has: page.getByText('Do you want to delete this repository?', { exact: true })
});
this.deleteMessage = this.deleteDialog.getByText('Do you want to delete this repository?', { exact: true });
this.confirmDeleteButton = this.deleteDialog.getByRole('button', { name: 'OK', exact: true });
this.cancelDeleteButton = this.deleteDialog.getByRole('button', { name: 'Cancel', exact: true });
}

repositoryTag(id: string): Locator {
return this.repositoryTags.and(this.page.getByText(id, { exact: true }));
}

repositoryCloseIcon(id: string): Locator {
return this.repositoryTag(id).locator(this.closeIcons);
}
}
117 changes: 117 additions & 0 deletions zeppelin-web-angular/e2e/models/interpreter-test.util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { expect, Page, Response, test as base } from '@playwright/test';
import type { Interpreter, InterpreterMap, InterpreterRepository } from '../../src/app/interfaces/interpreter';
import { waitForZeppelinReady } from '../utils';

export interface InterpreterPageData {
settings: Interpreter[];
availableInterpreters: InterpreterMap;
repositories: Array<Pick<InterpreterRepository, 'id' | 'url'>>;
}

interface InterpreterWrites {
requests: Array<{ method: string; path: string; body: unknown }>;
stub(method: 'POST' | 'PUT' | 'DELETE', path: string, responseBody: unknown): Promise<void>;
}

const readBody = async <T>(response: Response): Promise<T> => {
expect(response.ok(), `${response.request().method()} ${response.url()} returned ${response.status()}`).toBe(true);
const payload: { status: string; body: T } = await response.json();
expect(payload.status).toBe('OK');
return payload.body;
};

export const openInterpreterPage = async (
page: Page,
navigation: 'direct' | 'reload' = 'direct'
): Promise<InterpreterPageData> => {
const responseFor = (path: string): Promise<Response> =>
page.waitForResponse(
response => response.request().method() === 'GET' && new URL(response.url()).pathname === path
);
const settingsResponse = responseFor('/api/interpreter/setting');
const availableResponse = responseFor('/api/interpreter');
const repositoriesResponse = responseFor('/api/interpreter/repository');
if (navigation === 'reload') {
await page.reload();
} else {
await page.goto('/#/interpreter');
}
await waitForZeppelinReady(page);
const [settings, availableInterpreters, repositories] = await Promise.all([
settingsResponse.then(response => readBody<Interpreter[]>(response)),
availableResponse.then(response => readBody<InterpreterMap>(response)),
repositoriesResponse.then(response => readBody<InterpreterPageData['repositories']>(response))
]);
expect(settings, 'The E2E server must provide at least one interpreter setting').not.toEqual([]);
return { settings, availableInterpreters, repositories };
};

export const interpreterTitlePattern = (setting: Interpreter): RegExp => {
const escape = (text: string): string => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const aliases = setting.interpreterGroup.map((group, index) =>
escape(index === 0 ? `%${setting.name}` : `%${setting.name}.${group.name}`)
);
return new RegExp(`^\\s*${escape(setting.name)}\\s+${aliases.join('\\s*,\\s*')}\\s*$`);
};

export const stubInterpreterRead = async (page: Page, path: string, body: unknown): Promise<void> => {
await page.route(`**${path}`, async route => {
if (route.request().method() === 'GET') {
await route.fulfill({ json: { status: 'OK', message: '', body } });
} else {
await route.fallback();
}
});
};

export const test = base.extend<{ interpreterWrites: InterpreterWrites }>({
interpreterWrites: [
async ({ page }, use) => {
const requests: InterpreterWrites['requests'] = [];
const unexpectedWrites: string[] = [];
await page.route(/\/api\/interpreter(?:\/|$)/, async route => {
const request = route.request();
if (request.method() === 'GET') {
await route.fallback();
} else {
unexpectedWrites.push(`${request.method()} ${new URL(request.url()).pathname}`);
await route.abort();
}
});
await use({
requests,
stub: async (method, path, responseBody) => {
await page.route(`**${path}`, async route => {
const request = route.request();
if (request.method() !== method) {
await route.fallback();
return;
}
requests.push({
method: request.method(),
path: new URL(request.url()).pathname,
body: request.postDataJSON()
});
await route.fulfill({ json: { status: 'OK', message: '', body: responseBody } });
});
}
});
expect(unexpectedWrites, 'Only explicitly stubbed interpreter writes are allowed').toEqual([]);
},
{ auto: true }
]
});

export { expect };
Loading
Loading