Skip to content

Commit

Permalink
[test/functional] Tsfy page objects (#64887) (#65263)
Browse files Browse the repository at this point in the history
* [test/functional/page_objects] tsfy console, context, header, timepicker & timelion

* [test/functional/page_objects] tsfy shield & error

* fix ts-check issue

Co-authored-by: Elastic Machine <[email protected]>

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
dmlemeshko and elasticmachine authored May 5, 2020
1 parent 957cb0b commit 6cb1070
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 139 deletions.
2 changes: 1 addition & 1 deletion test/functional/apps/discover/_discover_histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default function({ getService, getPageObjects }) {
await PageObjects.common.navigateToApp('discover');
await PageObjects.discover.selectIndexPattern('long-window-logstash-*');
// NOTE: For some reason without setting this relative time, the abs times will not fetch data.
await PageObjects.timePicker.setCommonlyUsedTime('superDatePickerCommonlyUsed_Last_1 year');
await PageObjects.timePicker.setCommonlyUsedTime('Last_1 year');
});
after(async () => {
await esArchiver.unload('long_window_logstash');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,46 +17,47 @@
* under the License.
*/

import Bluebird from 'bluebird';
import { FtrProviderContext } from '../ftr_provider_context';
import { WebElementWrapper } from '../services/lib/web_element_wrapper';

export function ConsolePageProvider({ getService }) {
export function ConsolePageProvider({ getService }: FtrProviderContext) {
const testSubjects = getService('testSubjects');
const retry = getService('retry');

async function getVisibleTextFromAceEditor(editor) {
const lines = await editor.findAllByClassName('ace_line_group');
const linesText = await Bluebird.map(lines, l => l.getVisibleText());
return linesText.join('\n');
}
class ConsolePage {
public async getVisibleTextFromAceEditor(editor: WebElementWrapper) {
const lines = await editor.findAllByClassName('ace_line_group');
const linesText = await Promise.all(lines.map(async line => await line.getVisibleText()));
return linesText.join('\n');
}

return new (class ConsolePage {
async getRequestEditor() {
public async getRequestEditor() {
return await testSubjects.find('request-editor');
}

async getRequest() {
public async getRequest() {
const requestEditor = await this.getRequestEditor();
return await getVisibleTextFromAceEditor(requestEditor);
return await this.getVisibleTextFromAceEditor(requestEditor);
}

async getResponse() {
public async getResponse() {
const responseEditor = await testSubjects.find('response-editor');
return await getVisibleTextFromAceEditor(responseEditor);
return await this.getVisibleTextFromAceEditor(responseEditor);
}

async clickPlay() {
public async clickPlay() {
await testSubjects.click('sendRequestButton');
}

async collapseHelp() {
public async collapseHelp() {
await testSubjects.click('help-close-button');
}

async openSettings() {
public async openSettings() {
await testSubjects.click('consoleSettingsButton');
}

async setFontSizeSetting(newSize) {
public async setFontSizeSetting(newSize: number) {
await this.openSettings();

// while the settings form opens/loads this may fail, so retry for a while
Expand All @@ -70,13 +71,15 @@ export function ConsolePageProvider({ getService }) {
await testSubjects.click('settings-save-button');
}

async getFontSize(editor) {
public async getFontSize(editor: WebElementWrapper) {
const aceLine = await editor.findByClassName('ace_line');
return await aceLine.getComputedStyle('font-size');
}

async getRequestFontSize() {
public async getRequestFontSize() {
return await this.getFontSize(await this.getRequestEditor());
}
})();
}

return new ConsolePage();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
*/

import rison from 'rison-node';

import { FtrProviderContext } from '../ftr_provider_context';
// @ts-ignore not TS yet
import getUrl from '../../../src/test_utils/get_url';

const DEFAULT_INITIAL_STATE = {
columns: ['@message'],
};

export function ContextPageProvider({ getService, getPageObjects }) {
export function ContextPageProvider({ getService, getPageObjects }: FtrProviderContext) {
const browser = getService('browser');
const config = getService('config');
const retry = getService('retry');
Expand All @@ -34,7 +35,7 @@ export function ContextPageProvider({ getService, getPageObjects }) {
const log = getService('log');

class ContextPage {
async navigateTo(indexPattern, anchorId, overrideInitialState = {}) {
public async navigateTo(indexPattern: string, anchorId: string, overrideInitialState = {}) {
const initialState = rison.encode({
...DEFAULT_INITIAL_STATE,
...overrideInitialState,
Expand All @@ -53,23 +54,23 @@ export function ContextPageProvider({ getService, getPageObjects }) {
await PageObjects.common.sleep(1000);
}

async getPredecessorCountPicker() {
public async getPredecessorCountPicker() {
return await testSubjects.find('predecessorsCountPicker');
}

async getSuccessorCountPicker() {
public async getSuccessorCountPicker() {
return await testSubjects.find('successorsCountPicker');
}

async getPredecessorLoadMoreButton() {
public async getPredecessorLoadMoreButton() {
return await testSubjects.find('predecessorsLoadMoreButton');
}

async getSuccessorLoadMoreButton() {
public async getSuccessorLoadMoreButton() {
return await testSubjects.find('successorsLoadMoreButton');
}

async clickPredecessorLoadMoreButton() {
public async clickPredecessorLoadMoreButton() {
log.debug('Click Predecessor Load More Button');
await retry.try(async () => {
const predecessorButton = await this.getPredecessorLoadMoreButton();
Expand All @@ -79,7 +80,7 @@ export function ContextPageProvider({ getService, getPageObjects }) {
await PageObjects.header.waitUntilLoadingHasFinished();
}

async clickSuccessorLoadMoreButton() {
public async clickSuccessorLoadMoreButton() {
log.debug('Click Successor Load More Button');
await retry.try(async () => {
const sucessorButton = await this.getSuccessorLoadMoreButton();
Expand All @@ -89,7 +90,7 @@ export function ContextPageProvider({ getService, getPageObjects }) {
await PageObjects.header.waitUntilLoadingHasFinished();
}

async waitUntilContextLoadingHasFinished() {
public async waitUntilContextLoadingHasFinished() {
return await retry.try(async () => {
const successorLoadMoreButton = await this.getSuccessorLoadMoreButton();
const predecessorLoadMoreButton = await this.getPredecessorLoadMoreButton();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@
* specific language governing permissions and limitations
* under the License.
*/
import expect from '@kbn/expect';

export function ErrorPageProvider({ getPageObjects }) {
const PageObjects = getPageObjects(['common']);
import expect from '@kbn/expect/expect.js';
import { FtrProviderContext } from '../ftr_provider_context';

export function ErrorPageProvider({ getPageObjects }: FtrProviderContext) {
const { common } = getPageObjects(['common']);

class ErrorPage {
async expectForbidden() {
const messageText = await PageObjects.common.getBodyText();
public async expectForbidden() {
const messageText = await common.getBodyText();
expect(messageText).to.eql(
JSON.stringify({
statusCode: 403,
Expand All @@ -32,8 +34,9 @@ export function ErrorPageProvider({ getPageObjects }) {
})
);
}
async expectNotFound() {
const messageText = await PageObjects.common.getBodyText();

public async expectNotFound() {
const messageText = await common.getBodyText();
expect(messageText).to.eql(
JSON.stringify({
statusCode: 404,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
* under the License.
*/

export function HeaderPageProvider({ getService, getPageObjects }) {
import { FtrProviderContext } from '../ftr_provider_context';

export function HeaderPageProvider({ getService, getPageObjects }: FtrProviderContext) {
const config = getService('config');
const log = getService('log');
const retry = getService('retry');
Expand All @@ -29,13 +31,13 @@ export function HeaderPageProvider({ getService, getPageObjects }) {
const defaultFindTimeout = config.get('timeouts.find');

class HeaderPage {
async clickDiscover() {
public async clickDiscover() {
await appsMenu.clickLink('Discover');
await PageObjects.common.waitForTopNavToBeVisible();
await this.awaitGlobalLoadingIndicatorHidden();
}

async clickVisualize() {
public async clickVisualize() {
await appsMenu.clickLink('Visualize');
await this.awaitGlobalLoadingIndicatorHidden();
await retry.waitFor('first breadcrumb to be "Visualize"', async () => {
Expand All @@ -49,7 +51,7 @@ export function HeaderPageProvider({ getService, getPageObjects }) {
});
}

async clickDashboard() {
public async clickDashboard() {
await appsMenu.clickLink('Dashboard');
await retry.waitFor('dashboard app to be loaded', async () => {
const isNavVisible = await testSubjects.exists('top-nav');
Expand All @@ -59,12 +61,12 @@ export function HeaderPageProvider({ getService, getPageObjects }) {
await this.awaitGlobalLoadingIndicatorHidden();
}

async clickStackManagement() {
public async clickStackManagement() {
await appsMenu.clickLink('Management');
await this.awaitGlobalLoadingIndicatorHidden();
}

async waitUntilLoadingHasFinished() {
public async waitUntilLoadingHasFinished() {
try {
await this.isGlobalLoadingIndicatorVisible();
} catch (exception) {
Expand All @@ -77,19 +79,19 @@ export function HeaderPageProvider({ getService, getPageObjects }) {
await this.awaitGlobalLoadingIndicatorHidden();
}

async isGlobalLoadingIndicatorVisible() {
public async isGlobalLoadingIndicatorVisible() {
log.debug('isGlobalLoadingIndicatorVisible');
return await testSubjects.exists('globalLoadingIndicator', { timeout: 1500 });
}

async awaitGlobalLoadingIndicatorHidden() {
public async awaitGlobalLoadingIndicatorHidden() {
await testSubjects.existOrFail('globalLoadingIndicator-hidden', {
allowHidden: true,
timeout: defaultFindTimeout * 10,
});
}

async awaitKibanaChrome() {
public async awaitKibanaChrome() {
log.debug('awaitKibanaChrome');
await testSubjects.find('kibanaChrome', defaultFindTimeout * 10);
}
Expand Down
12 changes: 2 additions & 10 deletions test/functional/page_objects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,22 @@
*/

import { CommonPageProvider } from './common_page';
// @ts-ignore not TS yet
import { ConsolePageProvider } from './console_page';
// @ts-ignore not TS yet
import { ContextPageProvider } from './context_page';
import { DashboardPageProvider } from './dashboard_page';
import { DiscoverPageProvider } from './discover_page';
// @ts-ignore not TS yet
import { ErrorPageProvider } from './error_page';
// @ts-ignore not TS yet
import { HeaderPageProvider } from './header_page';
import { HomePageProvider } from './home_page';
// @ts-ignore not TS yet
import { MonitoringPageProvider } from './monitoring_page';
import { NewsfeedPageProvider } from './newsfeed_page';
// @ts-ignore not TS yet
import { PointSeriesPageProvider } from './point_series_page';
// @ts-ignore not TS yet
import { SettingsPageProvider } from './settings_page';
import { SharePageProvider } from './share_page';
// @ts-ignore not TS yet
import { ShieldPageProvider } from './shield_page';
// @ts-ignore not TS yet
import { TimePickerPageProvider } from './time_picker';
// @ts-ignore not TS yet
import { TimePickerProvider } from './time_picker';
import { TimelionPageProvider } from './timelion_page';
import { VisualBuilderPageProvider } from './visual_builder_page';
import { VisualizePageProvider } from './visualize_page';
Expand All @@ -67,7 +59,7 @@ export const pageObjects = {
share: SharePageProvider,
shield: ShieldPageProvider,
timelion: TimelionPageProvider,
timePicker: TimePickerPageProvider,
timePicker: TimePickerProvider,
visualBuilder: VisualBuilderPageProvider,
visualize: VisualizePageProvider,
visEditor: VisualizeEditorPageProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
* under the License.
*/

export function ShieldPageProvider({ getService }) {
import { FtrProviderContext } from '../ftr_provider_context';

export function ShieldPageProvider({ getService }: FtrProviderContext) {
const testSubjects = getService('testSubjects');

class ShieldPage {
async login(user, pwd) {
async login(user: string, pwd: string) {
await testSubjects.setValue('loginUsername', user);
await testSubjects.setValue('loginPassword', pwd);
await testSubjects.click('loginSubmit');
Expand Down
Loading

0 comments on commit 6cb1070

Please sign in to comment.