Skip to content

Commit

Permalink
Updated test to use no hard coded waits which could be contributing t…
Browse files Browse the repository at this point in the history
…o CI failures. Expect functions should be in the test file itself so I changed the page objects for page actions and extracted out the expect calls to the test files.
  • Loading branch information
John Dorlus committed Feb 1, 2021
1 parent 2a913e4 commit 245e0f8
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 45 deletions.
29 changes: 19 additions & 10 deletions x-pack/test/functional/apps/upgrade_assistant/upgrade_assistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';

export default function upgradeAssistantFunctionalTests({
Expand All @@ -24,41 +25,49 @@ export default function upgradeAssistantFunctionalTests({
});

after(async () => {
await PageObjects.upgradeAssistant.expectTelemetryHasFinish();
await PageObjects.upgradeAssistant.waitForTelemetryHidden();
await esArchiver.unload('empty_kibana');
await security.testUser.restoreDefaults();
});

it('allows user to navigate to upgrade checkup', async () => {
await PageObjects.upgradeAssistant.navigateToPage();
await PageObjects.upgradeAssistant.expectUpgradeAssistant();
});

it('allows user to toggle deprecation logging', async () => {
await PageObjects.upgradeAssistant.navigateToPage();
log.debug('expect initial state to be ON');
await PageObjects.upgradeAssistant.expectDeprecationLoggingLabel('On');
expect(await PageObjects.upgradeAssistant.deprecationLoggingEnabledLabel()).to.be('On');
expect(await PageObjects.upgradeAssistant.isDeprecationLoggingEnabled()).to.be(true);

log.debug('Now toggle to off');
await PageObjects.upgradeAssistant.toggleDeprecationLogging();
await PageObjects.common.sleep(2000);

log.debug('expect state to be OFF after toggle');
await PageObjects.upgradeAssistant.expectDeprecationLoggingLabel('Off');
expect(await PageObjects.upgradeAssistant.isDeprecationLoggingEnabled()).to.be(false);
expect(await PageObjects.upgradeAssistant.deprecationLoggingEnabledLabel()).to.be('Off');

log.debug('Now toggle back on.');
await PageObjects.upgradeAssistant.toggleDeprecationLogging();
await PageObjects.common.sleep(2000);

log.debug('expect state to be ON after toggle');
await PageObjects.upgradeAssistant.expectDeprecationLoggingLabel('On');
expect(await PageObjects.upgradeAssistant.isDeprecationLoggingEnabled()).to.be(true);
expect(await PageObjects.upgradeAssistant.deprecationLoggingEnabledLabel()).to.be('On');
});

it('allows user to open cluster tab', async () => {
await PageObjects.upgradeAssistant.navigateToPage();
await PageObjects.upgradeAssistant.clickTab('cluster');
await PageObjects.upgradeAssistant.expectIssueSummary('You have no cluster issues.');
expect(await PageObjects.upgradeAssistant.issueSummaryText()).to.be(
'You have no cluster issues.'
);
});

it('allows user to open indices tab', async () => {
await PageObjects.upgradeAssistant.navigateToPage();
await PageObjects.upgradeAssistant.clickTab('indices');
await PageObjects.upgradeAssistant.expectIssueSummary('You have no index issues.');
expect(await PageObjects.upgradeAssistant.issueSummaryText()).to.be(
'You have no index issues.'
);
});
});
}
72 changes: 37 additions & 35 deletions x-pack/test/functional/page_objects/upgrade_assistant_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/

import expect from '@kbn/expect';
import { FtrProviderContext } from '../ftr_provider_context';

export function UpgradeAssistantPageProvider({ getPageObjects, getService }: FtrProviderContext) {
Expand All @@ -24,34 +23,39 @@ export function UpgradeAssistantPageProvider({ getPageObjects, getService }: Ftr
return await retry.try(async () => {
await common.navigateToApp('settings');
await testSubjects.click('upgrade_assistant');
retry.waitFor('url to contain /upgrade_assistant', async () => {
const url = await browser.getCurrentUrl();
return url.includes('/upgrade_assistant');
});
});
}

async expectUpgradeAssistant() {
return await retry.try(async () => {
log.debug(`expectUpgradeAssistant()`);
expect(await testSubjects.exists('upgradeAssistantRoot')).to.equal(true);
const url = await browser.getCurrentUrl();
expect(url).to.contain(`/upgrade_assistant`);
});
async toggleDeprecationLogging() {
log.debug('toggleDeprecationLogging()');
const initialState = await this.isDeprecationLoggingEnabled();
log.debug(`Deprecation logging is set to ${initialState}`);
await testSubjects.click('upgradeAssistantDeprecationToggle');
await retry.try(async () => {});
// const newState = await this.isDeprecationLoggingEnabled();
// await retry.waitFor('Toggle deprecation to switch.', async () => {
// return newState !== initialState;
// });
}

async toggleDeprecationLogging() {
return await retry.try(async () => {
log.debug('toggleDeprecationLogging()');
await testSubjects.click('upgradeAssistantDeprecationToggle');
});
async isDeprecationLoggingEnabled() {
const isDeprecationEnabled = await testSubjects.getAttribute(
'upgradeAssistantDeprecationToggle',
'aria-checked'
);
log.debug(`Deprecation enabled == ${isDeprecationEnabled}`);
return isDeprecationEnabled === 'true';
}

async expectDeprecationLoggingLabel(labelText: string) {
return await retry.try(async () => {
log.debug('expectDeprecationLoggingLabel()');
const label = await find.byCssSelector(
'[data-test-subj="upgradeAssistantDeprecationToggle"] ~ span'
);
const value = await label.getVisibleText();
expect(value).to.equal(labelText);
});
async deprecationLoggingEnabledLabel() {
const loggingEnabledLabel = await find.byCssSelector(
'[data-test-subj="upgradeAssistantDeprecationToggle"] ~ span'
);
return await loggingEnabledLabel.getVisibleText();
}

async clickTab(tabId: string) {
Expand All @@ -61,22 +65,20 @@ export function UpgradeAssistantPageProvider({ getPageObjects, getService }: Ftr
});
}

async expectIssueSummary(summary: string) {
return await retry.try(async () => {
log.debug('expectIssueSummary()');
const summaryElText = await testSubjects.getVisibleText('upgradeAssistantIssueSummary');
expect(summaryElText).to.eql(summary);
async waitForTelemetryHidden() {
const self = this;
retry.waitFor('Telemetry to disappear.', async () => {
return (await self.isTelemetryExists()) === false;
});
}

async expectTelemetryHasFinish() {
return await retry.try(async () => {
log.debug('expectTelemetryHasFinish');
const isTelemetryFinished = !(await testSubjects.exists(
'upgradeAssistantTelemetryRunning'
));
expect(isTelemetryFinished).to.equal(true);
});
async issueSummaryText() {
log.debug('expectIssueSummary()');
return await testSubjects.getVisibleText('upgradeAssistantIssueSummary');
}

async isTelemetryExists() {
return await testSubjects.exists('upgradeAssistantTelemetryRunning');
}
}

Expand Down

0 comments on commit 245e0f8

Please sign in to comment.