Skip to content

Commit 5ad739f

Browse files
committed
convert all page object access in services to singular service access
1 parent 609f823 commit 5ad739f

33 files changed

+216
-207
lines changed

packages/kbn-test/src/functional_test_runner/public_types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ export interface GenericFtrProviderContext<
7474
getService(serviceName: 'failureMetadata'): FailureMetadata;
7575
getService<T extends keyof ServiceMap>(serviceName: T): ServiceMap[T];
7676

77+
/**
78+
* Get the instance of a page object
79+
* @param pageObjectName
80+
*/
81+
getPageObject<K extends keyof PageObjectMap>(pageObjectName: K): PageObjectMap[K];
82+
7783
/**
7884
* Get a map of PageObjects
7985
* @param pageObjects

test/functional/page_objects/common_page.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class CommonPageObject extends FtrService {
2828
private readonly find = this.ctx.getService('find');
2929
private readonly globalNav = this.ctx.getService('globalNav');
3030
private readonly testSubjects = this.ctx.getService('testSubjects');
31-
private readonly PageObjects = this.ctx.getPageObjects(['login']);
31+
private readonly loginPage = this.ctx.getPageObject('login');
3232

3333
private readonly defaultTryTimeout = this.config.get('timeouts.try');
3434
private readonly defaultFindTimeout = this.config.get('timeouts.find');
@@ -52,12 +52,12 @@ export class CommonPageObject extends FtrService {
5252
if (loginPage && !wantedLoginPage) {
5353
this.log.debug('Found login page');
5454
if (this.config.get('security.disableTestUser')) {
55-
await this.PageObjects.login.login(
55+
await this.loginPage.login(
5656
this.config.get('servers.kibana.username'),
5757
this.config.get('servers.kibana.password')
5858
);
5959
} else {
60-
await this.PageObjects.login.login('test_user', 'changeme');
60+
await this.loginPage.login('test_user', 'changeme');
6161
}
6262

6363
await this.find.byCssSelector(

test/functional/page_objects/context_page.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ export class ContextPageObject extends FtrService {
1919
private readonly config = this.ctx.getService('config');
2020
private readonly retry = this.ctx.getService('retry');
2121
private readonly testSubjects = this.ctx.getService('testSubjects');
22-
private readonly PageObjects = this.ctx.getPageObjects(['header', 'common']);
22+
private readonly header = this.ctx.getPageObject('header');
23+
private readonly common = this.ctx.getPageObject('common');
2324
private readonly log = this.ctx.getService('log');
2425

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

3839
await this.browser.get(appUrl);
39-
await this.PageObjects.header.awaitGlobalLoadingIndicatorHidden();
40+
await this.header.awaitGlobalLoadingIndicatorHidden();
4041
await this.waitUntilContextLoadingHasFinished();
4142
// For lack of a better way, using a sleep to ensure page is loaded before proceeding
42-
await this.PageObjects.common.sleep(1000);
43+
await this.common.sleep(1000);
4344
}
4445

4546
public async getPredecessorCountPicker() {
@@ -65,7 +66,7 @@ export class ContextPageObject extends FtrService {
6566
await predecessorButton.click();
6667
});
6768
await this.waitUntilContextLoadingHasFinished();
68-
await this.PageObjects.header.waitUntilLoadingHasFinished();
69+
await this.header.waitUntilLoadingHasFinished();
6970
}
7071

7172
public async clickSuccessorLoadMoreButton() {
@@ -75,7 +76,7 @@ export class ContextPageObject extends FtrService {
7576
await sucessorButton.click();
7677
});
7778
await this.waitUntilContextLoadingHasFinished();
78-
await this.PageObjects.header.waitUntilLoadingHasFinished();
79+
await this.header.waitUntilLoadingHasFinished();
7980
}
8081

8182
public async waitUntilContextLoadingHasFinished() {

test/functional/page_objects/dashboard_page.ts

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,22 @@ export class DashboardPageObject extends FtrService {
3636
private readonly renderable = this.ctx.getService('renderable');
3737
private readonly listingTable = this.ctx.getService('listingTable');
3838
private readonly elasticChart = this.ctx.getService('elasticChart');
39-
private readonly PageObjects = this.ctx.getPageObjects([
40-
'common',
41-
'header',
42-
'visualize',
43-
'discover',
44-
]);
39+
private readonly common = this.ctx.getPageObject('common');
40+
private readonly header = this.ctx.getPageObject('header');
41+
private readonly visualize = this.ctx.getPageObject('visualize');
42+
private readonly discover = this.ctx.getPageObject('discover');
4543

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

5351
public async preserveCrossAppState() {
5452
const url = await this.browser.getCurrentUrl();
5553
await this.browser.get(url, false);
56-
await this.PageObjects.header.waitUntilLoadingHasFinished();
54+
await this.header.waitUntilLoadingHasFinished();
5755
}
5856

5957
public async clickFullScreenMode() {
@@ -138,9 +136,9 @@ export class DashboardPageObject extends FtrService {
138136
await this.testSubjects.existOrFail(`discard-unsaved-${title.split(' ').join('-')}`);
139137
await this.testSubjects.click(`discard-unsaved-${title.split(' ').join('-')}`);
140138
if (confirmDiscard) {
141-
await this.PageObjects.common.clickConfirmOnModal();
139+
await this.common.clickConfirmOnModal();
142140
} else {
143-
await this.PageObjects.common.clickCancelOnModal();
141+
await this.common.clickCancelOnModal();
144142
}
145143
}
146144

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

335333
// avoids any 'Object with id x not found' errors when switching tests.
336334
public async clearSavedObjectsFromAppLinks() {
337-
await this.PageObjects.header.clickVisualize();
338-
await this.PageObjects.visualize.gotoLandingPage();
339-
await this.PageObjects.header.clickDashboard();
335+
await this.header.clickVisualize();
336+
await this.visualize.gotoLandingPage();
337+
await this.header.clickDashboard();
340338
await this.gotoDashboardLandingPage();
341339
}
342340

@@ -402,15 +400,15 @@ export class DashboardPageObject extends FtrService {
402400
// Confirm that the Dashboard has actually been saved
403401
await this.testSubjects.existOrFail('saveDashboardSuccess');
404402
});
405-
const message = await this.PageObjects.common.closeToast();
406-
await this.PageObjects.header.waitUntilLoadingHasFinished();
407-
await this.PageObjects.common.waitForSaveModalToClose();
403+
const message = await this.common.closeToast();
404+
await this.header.waitUntilLoadingHasFinished();
405+
await this.common.waitForSaveModalToClose();
408406

409407
const isInViewMode = await this.testSubjects.exists('dashboardEditMode');
410408
if (saveOptions.exitFromEditMode && !isInViewMode) {
411409
await this.clickCancelOutOfEditMode();
412410
}
413-
await this.PageObjects.header.waitUntilLoadingHasFinished();
411+
await this.header.waitUntilLoadingHasFinished();
414412

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

484-
await this.PageObjects.common.pressEnterKey();
482+
await this.common.pressEnterKey();
485483
await this.testSubjects.waitForDeleted(modalDialog);
486484
}
487485

@@ -495,7 +493,7 @@ export class DashboardPageObject extends FtrService {
495493
await this.listingTable.searchForItemWithName(dashboardName);
496494
await this.retry.try(async () => {
497495
await this.listingTable.clickItemLink('dashboard', dashboardName);
498-
await this.PageObjects.header.waitUntilLoadingHasFinished();
496+
await this.header.waitUntilLoadingHasFinished();
499497
// check Dashboard landing page is not present
500498
await this.testSubjects.missingOrFail('dashboardLandingPage', { timeout: 10000 });
501499
});

test/functional/page_objects/discover_page.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class DiscoverPageObject extends FtrService {
1313
private readonly testSubjects = this.ctx.getService('testSubjects');
1414
private readonly find = this.ctx.getService('find');
1515
private readonly flyout = this.ctx.getService('flyout');
16-
private readonly header = this.ctx.getPageObjects(['header']).header;
16+
private readonly header = this.ctx.getPageObject('header');
1717
private readonly browser = this.ctx.getService('browser');
1818
private readonly globalNav = this.ctx.getService('globalNav');
1919
private readonly elasticChart = this.ctx.getService('elasticChart');

test/functional/page_objects/error_page.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import expect from '@kbn/expect';
1010
import { FtrService } from '../ftr_provider_context';
1111

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

1515
public async expectForbidden() {
1616
const messageText = await this.common.getBodyText();

test/functional/page_objects/header_page.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ export class HeaderPageObject extends FtrService {
1414
private readonly retry = this.ctx.getService('retry');
1515
private readonly testSubjects = this.ctx.getService('testSubjects');
1616
private readonly appsMenu = this.ctx.getService('appsMenu');
17-
private readonly PageObjects = this.ctx.getPageObjects(['common']);
17+
private readonly common = this.ctx.getPageObject('common');
1818

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

2121
public async clickDiscover(ignoreAppLeaveWarning = false) {
2222
await this.appsMenu.clickLink('Discover', { category: 'kibana' });
2323
await this.onAppLeaveWarning(ignoreAppLeaveWarning);
24-
await this.PageObjects.common.waitForTopNavToBeVisible();
24+
await this.common.waitForTopNavToBeVisible();
2525
await this.awaitGlobalLoadingIndicatorHidden();
2626
}
2727

test/functional/page_objects/home_page.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class HomePageObject extends FtrService {
1212
private readonly testSubjects = this.ctx.getService('testSubjects');
1313
private readonly retry = this.ctx.getService('retry');
1414
private readonly find = this.ctx.getService('find');
15-
private readonly PageObjects = this.ctx.getPageObjects(['common']);
15+
private readonly common = this.ctx.getPageObject('common');
1616

1717
async clickSynopsis(title: string) {
1818
await this.testSubjects.click(`homeSynopsisLink${title}`);
@@ -52,7 +52,7 @@ export class HomePageObject extends FtrService {
5252
// https://github.com/elastic/kibana/issues/65949
5353
// Even after waiting for the "Remove" button to be enabled we still have failures
5454
// where it appears the click just didn't work.
55-
await this.PageObjects.common.sleep(1010);
55+
await this.common.sleep(1010);
5656
await this.testSubjects.click(`removeSampleDataSet${id}`);
5757
await this._waitForSampleDataLoadingAction(id);
5858
}

test/functional/page_objects/management/saved_objects_page.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ export class SavedObjectsPageObject extends FtrService {
1616
private readonly browser = this.ctx.getService('browser');
1717
private readonly find = this.ctx.getService('find');
1818
private readonly testSubjects = this.ctx.getService('testSubjects');
19-
private readonly PageObjects = this.ctx.getPageObjects(['header', 'common']);
19+
private readonly common = this.ctx.getPageObject('common');
20+
private readonly header = this.ctx.getPageObject('header');
2021

2122
async searchForObject(objectName: string) {
2223
const searchBox = await this.testSubjects.find('savedObjectSearchBar');
2324
await searchBox.clearValue();
2425
await searchBox.type(objectName);
2526
await searchBox.pressKeys(this.browser.keys.ENTER);
26-
await this.PageObjects.header.waitUntilLoadingHasFinished();
27+
await this.header.waitUntilLoadingHasFinished();
2728
await this.waitTableIsLoaded();
2829
}
2930

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

3839
this.log.debug(`Clicking importObjects`);
3940
await this.testSubjects.click('importObjects');
40-
await this.PageObjects.common.setFileInputPath(path);
41+
await this.common.setFileInputPath(path);
4142

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

5758
// Wait for all the saves to happen
58-
await this.PageObjects.header.waitUntilLoadingHasFinished();
59+
await this.header.waitUntilLoadingHasFinished();
5960
}
6061

6162
async checkImportSucceeded() {

test/functional/page_objects/newsfeed_page.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ export class NewsfeedPageObject extends FtrService {
1414
private readonly retry = this.ctx.getService('retry');
1515
private readonly flyout = this.ctx.getService('flyout');
1616
private readonly testSubjects = this.ctx.getService('testSubjects');
17-
private readonly PageObjects = this.ctx.getPageObjects(['common']);
17+
private readonly common = this.ctx.getPageObject('common');
1818

1919
async resetPage() {
20-
await this.PageObjects.common.navigateToUrl('home', '', { useActualUrl: true });
20+
await this.common.navigateToUrl('home', '', { useActualUrl: true });
2121
}
2222

2323
async closeNewsfeedPanel() {

0 commit comments

Comments
 (0)