Skip to content

Commit

Permalink
[QA][refactor] Use ui settings - sample data (#114530) (#115549)
Browse files Browse the repository at this point in the history
# Conflicts:
#	test/functional/page_objects/common_page.ts
  • Loading branch information
wayneseymour authored Oct 19, 2021
1 parent 8e6ba27 commit 00c6f11
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
21 changes: 9 additions & 12 deletions test/functional/apps/home/_sample_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {

after(async () => {
await security.testUser.restoreDefaults();
await PageObjects.common.unsetTime();
});

it('should display registered flights sample data sets', async () => {
Expand Down Expand Up @@ -74,6 +75,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {

describe('dashboard', () => {
beforeEach(async () => {
await time();
await PageObjects.common.navigateToUrl('home', '/tutorial_directory/sampleData', {
useActualUrl: true,
});
Expand All @@ -84,10 +86,6 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await PageObjects.home.launchSampleDashboard('flights');
await PageObjects.header.waitUntilLoadingHasFinished();
await renderable.waitForRender();
const todayYearMonthDay = moment().format('MMM D, YYYY');
const fromTime = `${todayYearMonthDay} @ 00:00:00.000`;
const toTime = `${todayYearMonthDay} @ 23:59:59.999`;
await PageObjects.timePicker.setAbsoluteRange(fromTime, toTime);
const panelCount = await PageObjects.dashboard.getPanelCount();
expect(panelCount).to.be(17);
});
Expand All @@ -112,10 +110,6 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await PageObjects.home.launchSampleDashboard('logs');
await PageObjects.header.waitUntilLoadingHasFinished();
await renderable.waitForRender();
const todayYearMonthDay = moment().format('MMM D, YYYY');
const fromTime = `${todayYearMonthDay} @ 00:00:00.000`;
const toTime = `${todayYearMonthDay} @ 23:59:59.999`;
await PageObjects.timePicker.setAbsoluteRange(fromTime, toTime);
const panelCount = await PageObjects.dashboard.getPanelCount();
expect(panelCount).to.be(13);
});
Expand All @@ -124,10 +118,6 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await PageObjects.home.launchSampleDashboard('ecommerce');
await PageObjects.header.waitUntilLoadingHasFinished();
await renderable.waitForRender();
const todayYearMonthDay = moment().format('MMM D, YYYY');
const fromTime = `${todayYearMonthDay} @ 00:00:00.000`;
const toTime = `${todayYearMonthDay} @ 23:59:59.999`;
await PageObjects.timePicker.setAbsoluteRange(fromTime, toTime);
const panelCount = await PageObjects.dashboard.getPanelCount();
expect(panelCount).to.be(15);
});
Expand Down Expand Up @@ -160,5 +150,12 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
expect(isInstalled).to.be(false);
});
});

async function time() {
const today = moment().format('MMM D, YYYY');
const from = `${today} @ 00:00:00.000`;
const to = `${today} @ 23:59:59.999`;
await PageObjects.common.setTime({ from, to });
}
});
}
23 changes: 19 additions & 4 deletions test/functional/page_objects/common_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ 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 login = this.ctx.getPageObject('login');
private readonly loginPage = this.ctx.getPageObject('login');
private readonly kibanaServer = this.ctx.getService('kibanaServer');

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

if (appUrl.includes('/status')) {
Expand Down Expand Up @@ -344,6 +345,12 @@ export class CommonPageObject extends FtrService {
await this.browser.pressKeys(this.browser.keys.TAB);
}

// Pause the browser at a certain place for debugging
// Not meant for usage in CI, only for dev-usage
async pause() {
return this.browser.pause();
}

/**
* Clicks cancel button on modal
* @param overlayWillStay pass in true if your test will show multiple modals in succession
Expand Down Expand Up @@ -402,7 +409,7 @@ export class CommonPageObject extends FtrService {
const toastShown = await this.find.existsByCssSelector('.euiToast');
if (toastShown) {
try {
await this.closeToast();
await this.find.clickByCssSelector('.euiToast__closeButton');
} catch (err) {
// ignore errors, toast clear themselves after timeout
}
Expand Down Expand Up @@ -495,4 +502,12 @@ export class CommonPageObject extends FtrService {
await this.testSubjects.exists(validator);
}
}

async setTime(time: { from: string; to: string }) {
await this.kibanaServer.uiSettings.replace({ 'timepicker:timeDefaults': JSON.stringify(time) });
}

async unsetTime() {
await this.kibanaServer.uiSettings.unset('timepicker:timeDefaults');
}
}

0 comments on commit 00c6f11

Please sign in to comment.