Skip to content

Commit

Permalink
convert all page object access in services to singular service access
Browse files Browse the repository at this point in the history
  • Loading branch information
spalger committed Jun 4, 2021
1 parent 609f823 commit 5ad739f
Show file tree
Hide file tree
Showing 33 changed files with 216 additions and 207 deletions.
6 changes: 6 additions & 0 deletions packages/kbn-test/src/functional_test_runner/public_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ export interface GenericFtrProviderContext<
getService(serviceName: 'failureMetadata'): FailureMetadata;
getService<T extends keyof ServiceMap>(serviceName: T): ServiceMap[T];

/**
* Get the instance of a page object
* @param pageObjectName
*/
getPageObject<K extends keyof PageObjectMap>(pageObjectName: K): PageObjectMap[K];

/**
* Get a map of PageObjects
* @param pageObjects
Expand Down
6 changes: 3 additions & 3 deletions test/functional/page_objects/common_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class CommonPageObject extends FtrService {
private readonly find = this.ctx.getService('find');
private readonly globalNav = this.ctx.getService('globalNav');
private readonly testSubjects = this.ctx.getService('testSubjects');
private readonly PageObjects = this.ctx.getPageObjects(['login']);
private readonly loginPage = this.ctx.getPageObject('login');

private readonly defaultTryTimeout = this.config.get('timeouts.try');
private readonly defaultFindTimeout = this.config.get('timeouts.find');
Expand All @@ -52,12 +52,12 @@ export class CommonPageObject extends FtrService {
if (loginPage && !wantedLoginPage) {
this.log.debug('Found login page');
if (this.config.get('security.disableTestUser')) {
await this.PageObjects.login.login(
await this.loginPage.login(
this.config.get('servers.kibana.username'),
this.config.get('servers.kibana.password')
);
} else {
await this.PageObjects.login.login('test_user', 'changeme');
await this.loginPage.login('test_user', 'changeme');
}

await this.find.byCssSelector(
Expand Down
11 changes: 6 additions & 5 deletions test/functional/page_objects/context_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export class ContextPageObject extends FtrService {
private readonly config = this.ctx.getService('config');
private readonly retry = this.ctx.getService('retry');
private readonly testSubjects = this.ctx.getService('testSubjects');
private readonly PageObjects = this.ctx.getPageObjects(['header', 'common']);
private readonly header = this.ctx.getPageObject('header');
private readonly common = this.ctx.getPageObject('common');
private readonly log = this.ctx.getService('log');

public async navigateTo(indexPattern: string, anchorId: string, overrideInitialState = {}) {
Expand All @@ -36,10 +37,10 @@ export class ContextPageObject extends FtrService {
this.log.debug(`browser.get(${appUrl})`);

await this.browser.get(appUrl);
await this.PageObjects.header.awaitGlobalLoadingIndicatorHidden();
await this.header.awaitGlobalLoadingIndicatorHidden();
await this.waitUntilContextLoadingHasFinished();
// For lack of a better way, using a sleep to ensure page is loaded before proceeding
await this.PageObjects.common.sleep(1000);
await this.common.sleep(1000);
}

public async getPredecessorCountPicker() {
Expand All @@ -65,7 +66,7 @@ export class ContextPageObject extends FtrService {
await predecessorButton.click();
});
await this.waitUntilContextLoadingHasFinished();
await this.PageObjects.header.waitUntilLoadingHasFinished();
await this.header.waitUntilLoadingHasFinished();
}

public async clickSuccessorLoadMoreButton() {
Expand All @@ -75,7 +76,7 @@ export class ContextPageObject extends FtrService {
await sucessorButton.click();
});
await this.waitUntilContextLoadingHasFinished();
await this.PageObjects.header.waitUntilLoadingHasFinished();
await this.header.waitUntilLoadingHasFinished();
}

public async waitUntilContextLoadingHasFinished() {
Expand Down
38 changes: 18 additions & 20 deletions test/functional/page_objects/dashboard_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,22 @@ export class DashboardPageObject extends FtrService {
private readonly renderable = this.ctx.getService('renderable');
private readonly listingTable = this.ctx.getService('listingTable');
private readonly elasticChart = this.ctx.getService('elasticChart');
private readonly PageObjects = this.ctx.getPageObjects([
'common',
'header',
'visualize',
'discover',
]);
private readonly common = this.ctx.getPageObject('common');
private readonly header = this.ctx.getPageObject('header');
private readonly visualize = this.ctx.getPageObject('visualize');
private readonly discover = this.ctx.getPageObject('discover');

async initTests({ kibanaIndex = 'dashboard/legacy', defaultIndex = 'logstash-*' } = {}) {
this.log.debug('load kibana index with visualizations and log data');
await this.esArchiver.load(kibanaIndex);
await this.kibanaServer.uiSettings.replace({ defaultIndex });
await this.PageObjects.common.navigateToApp('dashboard');
await this.common.navigateToApp('dashboard');
}

public async preserveCrossAppState() {
const url = await this.browser.getCurrentUrl();
await this.browser.get(url, false);
await this.PageObjects.header.waitUntilLoadingHasFinished();
await this.header.waitUntilLoadingHasFinished();
}

public async clickFullScreenMode() {
Expand Down Expand Up @@ -138,9 +136,9 @@ export class DashboardPageObject extends FtrService {
await this.testSubjects.existOrFail(`discard-unsaved-${title.split(' ').join('-')}`);
await this.testSubjects.click(`discard-unsaved-${title.split(' ').join('-')}`);
if (confirmDiscard) {
await this.PageObjects.common.clickConfirmOnModal();
await this.common.clickConfirmOnModal();
} else {
await this.PageObjects.common.clickCancelOnModal();
await this.common.clickCancelOnModal();
}
}

Expand Down Expand Up @@ -227,7 +225,7 @@ export class DashboardPageObject extends FtrService {
*/
public async expectToolbarPaginationDisplayed() {
const isLegacyDefault = this.PageObjects.discover.useLegacyTable();
const isLegacyDefault = this.discover.useLegacyTable();
if (isLegacyDefault) {
const subjects = ['btnPrevPage', 'btnNextPage', 'toolBarPagerText'];
await Promise.all(subjects.map(async (subj) => await this.testSubjects.existOrFail(subj)));
Expand Down Expand Up @@ -334,9 +332,9 @@ export class DashboardPageObject extends FtrService {

// avoids any 'Object with id x not found' errors when switching tests.
public async clearSavedObjectsFromAppLinks() {
await this.PageObjects.header.clickVisualize();
await this.PageObjects.visualize.gotoLandingPage();
await this.PageObjects.header.clickDashboard();
await this.header.clickVisualize();
await this.visualize.gotoLandingPage();
await this.header.clickDashboard();
await this.gotoDashboardLandingPage();
}

Expand Down Expand Up @@ -402,15 +400,15 @@ export class DashboardPageObject extends FtrService {
// Confirm that the Dashboard has actually been saved
await this.testSubjects.existOrFail('saveDashboardSuccess');
});
const message = await this.PageObjects.common.closeToast();
await this.PageObjects.header.waitUntilLoadingHasFinished();
await this.PageObjects.common.waitForSaveModalToClose();
const message = await this.common.closeToast();
await this.header.waitUntilLoadingHasFinished();
await this.common.waitForSaveModalToClose();

const isInViewMode = await this.testSubjects.exists('dashboardEditMode');
if (saveOptions.exitFromEditMode && !isInViewMode) {
await this.clickCancelOutOfEditMode();
}
await this.PageObjects.header.waitUntilLoadingHasFinished();
await this.header.waitUntilLoadingHasFinished();

return message;
}
Expand Down Expand Up @@ -481,7 +479,7 @@ export class DashboardPageObject extends FtrService {
this.log.debug('entering new title');
await this.testSubjects.setValue('savedObjectTitle', dashboardTitle);

await this.PageObjects.common.pressEnterKey();
await this.common.pressEnterKey();
await this.testSubjects.waitForDeleted(modalDialog);
}

Expand All @@ -495,7 +493,7 @@ export class DashboardPageObject extends FtrService {
await this.listingTable.searchForItemWithName(dashboardName);
await this.retry.try(async () => {
await this.listingTable.clickItemLink('dashboard', dashboardName);
await this.PageObjects.header.waitUntilLoadingHasFinished();
await this.header.waitUntilLoadingHasFinished();
// check Dashboard landing page is not present
await this.testSubjects.missingOrFail('dashboardLandingPage', { timeout: 10000 });
});
Expand Down
2 changes: 1 addition & 1 deletion test/functional/page_objects/discover_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class DiscoverPageObject extends FtrService {
private readonly testSubjects = this.ctx.getService('testSubjects');
private readonly find = this.ctx.getService('find');
private readonly flyout = this.ctx.getService('flyout');
private readonly header = this.ctx.getPageObjects(['header']).header;
private readonly header = this.ctx.getPageObject('header');
private readonly browser = this.ctx.getService('browser');
private readonly globalNav = this.ctx.getService('globalNav');
private readonly elasticChart = this.ctx.getService('elasticChart');
Expand Down
2 changes: 1 addition & 1 deletion test/functional/page_objects/error_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import expect from '@kbn/expect';
import { FtrService } from '../ftr_provider_context';

export class ErrorPageObject extends FtrService {
private readonly common = this.ctx.getPageObjects(['common']).common;
private readonly common = this.ctx.getPageObject('common');

public async expectForbidden() {
const messageText = await this.common.getBodyText();
Expand Down
4 changes: 2 additions & 2 deletions test/functional/page_objects/header_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ export class HeaderPageObject extends FtrService {
private readonly retry = this.ctx.getService('retry');
private readonly testSubjects = this.ctx.getService('testSubjects');
private readonly appsMenu = this.ctx.getService('appsMenu');
private readonly PageObjects = this.ctx.getPageObjects(['common']);
private readonly common = this.ctx.getPageObject('common');

private readonly defaultFindTimeout = this.config.get('timeouts.find');

public async clickDiscover(ignoreAppLeaveWarning = false) {
await this.appsMenu.clickLink('Discover', { category: 'kibana' });
await this.onAppLeaveWarning(ignoreAppLeaveWarning);
await this.PageObjects.common.waitForTopNavToBeVisible();
await this.common.waitForTopNavToBeVisible();
await this.awaitGlobalLoadingIndicatorHidden();
}

Expand Down
4 changes: 2 additions & 2 deletions test/functional/page_objects/home_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class HomePageObject extends FtrService {
private readonly testSubjects = this.ctx.getService('testSubjects');
private readonly retry = this.ctx.getService('retry');
private readonly find = this.ctx.getService('find');
private readonly PageObjects = this.ctx.getPageObjects(['common']);
private readonly common = this.ctx.getPageObject('common');

async clickSynopsis(title: string) {
await this.testSubjects.click(`homeSynopsisLink${title}`);
Expand Down Expand Up @@ -52,7 +52,7 @@ export class HomePageObject extends FtrService {
// https://github.com/elastic/kibana/issues/65949
// Even after waiting for the "Remove" button to be enabled we still have failures
// where it appears the click just didn't work.
await this.PageObjects.common.sleep(1010);
await this.common.sleep(1010);
await this.testSubjects.click(`removeSampleDataSet${id}`);
await this._waitForSampleDataLoadingAction(id);
}
Expand Down
9 changes: 5 additions & 4 deletions test/functional/page_objects/management/saved_objects_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ export class SavedObjectsPageObject extends FtrService {
private readonly browser = this.ctx.getService('browser');
private readonly find = this.ctx.getService('find');
private readonly testSubjects = this.ctx.getService('testSubjects');
private readonly PageObjects = this.ctx.getPageObjects(['header', 'common']);
private readonly common = this.ctx.getPageObject('common');
private readonly header = this.ctx.getPageObject('header');

async searchForObject(objectName: string) {
const searchBox = await this.testSubjects.find('savedObjectSearchBar');
await searchBox.clearValue();
await searchBox.type(objectName);
await searchBox.pressKeys(this.browser.keys.ENTER);
await this.PageObjects.header.waitUntilLoadingHasFinished();
await this.header.waitUntilLoadingHasFinished();
await this.waitTableIsLoaded();
}

Expand All @@ -37,7 +38,7 @@ export class SavedObjectsPageObject extends FtrService {

this.log.debug(`Clicking importObjects`);
await this.testSubjects.click('importObjects');
await this.PageObjects.common.setFileInputPath(path);
await this.common.setFileInputPath(path);

if (!overwriteAll) {
this.log.debug(`Toggling overwriteAll`);
Expand All @@ -55,7 +56,7 @@ export class SavedObjectsPageObject extends FtrService {
this.log.debug(`done importing the file`);

// Wait for all the saves to happen
await this.PageObjects.header.waitUntilLoadingHasFinished();
await this.header.waitUntilLoadingHasFinished();
}

async checkImportSucceeded() {
Expand Down
4 changes: 2 additions & 2 deletions test/functional/page_objects/newsfeed_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ export class NewsfeedPageObject extends FtrService {
private readonly retry = this.ctx.getService('retry');
private readonly flyout = this.ctx.getService('flyout');
private readonly testSubjects = this.ctx.getService('testSubjects');
private readonly PageObjects = this.ctx.getPageObjects(['common']);
private readonly common = this.ctx.getPageObject('common');

async resetPage() {
await this.PageObjects.common.navigateToUrl('home', '', { useActualUrl: true });
await this.common.navigateToUrl('home', '', { useActualUrl: true });
}

async closeNewsfeedPanel() {
Expand Down
Loading

0 comments on commit 5ad739f

Please sign in to comment.