alternative path for upgrade reporting test for headless browser (#143994)

* alternative path for headless browser

* added timing debug output

* fix type error

* [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix'

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Lee Drengenberg 2022-11-01 13:20:49 -05:00 committed by GitHub
parent 58b53d8b5d
commit e17aa78872
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -22,6 +22,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
const PageObjects = getPageObjects(['common', 'header', 'home', 'dashboard', 'share']);
const testSubjects = getService('testSubjects');
const log = getService('log');
const retry = getService('retry');
const spaces = [
{ space: 'default', basePath: '' },
@ -40,7 +41,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
{ name: 'ecommerce', type: 'png', link: 'PNG Reports' },
];
describe('upgrade reporting smoke tests', () => {
describe('reporting ', () => {
let completedReportCount: number;
let usage: UsageStats;
describe('initial state', () => {
@ -54,7 +55,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
});
});
spaces.forEach(({ space, basePath }) => {
describe('generate report for space ' + space, () => {
describe('space ' + space, () => {
beforeEach(async () => {
await PageObjects.common.navigateToActualUrl('home', '/tutorial_directory/sampleData', {
basePath,
@ -65,44 +66,62 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
});
reportingTests.forEach(({ name, type, link }) => {
it('name: ' + name + ' type: ' + type, async () => {
let startTime;
await PageObjects.home.launchSampleDashboard(name);
await PageObjects.share.openShareMenuItem(link);
if (type === 'pdf_optimize') {
await testSubjects.click('usePrintLayout');
}
const advOpt = await find.byXPath(`//button[descendant::*[text()='Advanced options']]`);
await advOpt.click();
// Workaround for: https://github.com/elastic/kibana/issues/126540
const isUrlTooLong = await testSubjects.exists('urlTooLongErrorMessage');
if (isUrlTooLong) {
// Save dashboard
await PageObjects.dashboard.switchToEditMode();
await PageObjects.dashboard.clickQuickSave();
await PageObjects.share.openShareMenuItem(link);
if (type === 'pdf_optimize') {
await testSubjects.click('usePrintLayout');
}
const advOpt2 = await find.byXPath(
const canReadClipboard = await browser.checkBrowserPermission('clipboard-read');
// if we can read the clipboard (not Chrome headless) then get the reporting URL and post it
// else click the reporting button and wait for the count of completed reports to increment
if (canReadClipboard) {
log.debug('We have clipboard access. Getting the POST URL and posting it via API');
const advOpt = await find.byXPath(
`//button[descendant::*[text()='Advanced options']]`
);
await advOpt2.click();
await advOpt.click();
// Workaround for: https://github.com/elastic/kibana/issues/126540
const isUrlTooLong = await testSubjects.exists('urlTooLongErrorMessage');
if (isUrlTooLong) {
// Save dashboard
await PageObjects.dashboard.switchToEditMode();
await PageObjects.dashboard.clickQuickSave();
await PageObjects.share.openShareMenuItem(link);
if (type === 'pdf_optimize') {
await testSubjects.click('usePrintLayout');
}
const advOpt2 = await find.byXPath(
`//button[descendant::*[text()='Advanced options']]`
);
await advOpt2.click();
}
const postUrl = await find.byXPath(`//button[descendant::*[text()='Copy POST URL']]`);
await postUrl.click();
const url = await browser.getClipboardValue();
// Add try/catch for https://github.com/elastic/elastic-stack-testing/issues/1199
// Waiting for job to finish sometimes gets socket hang up error, from what I
// observed during debug testing the command does complete.
// Checking expected report count will still fail if the job did not finish.
try {
await reportingAPI.expectAllJobsToFinishSuccessfully([
await reportingAPI.postJob(parse(url).pathname + '?' + parse(url).query),
]);
} catch (e) {
log.debug(`Error waiting for job to finish: ${e}`);
}
startTime = new Date();
} else {
log.debug(`We don't have clipboard access. Clicking the Generate report button`);
await testSubjects.click('generateReportButton');
startTime = new Date();
}
const postUrl = await find.byXPath(`//button[descendant::*[text()='Copy POST URL']]`);
await postUrl.click();
const url = await browser.getClipboardValue();
// Add try/catch for https://github.com/elastic/elastic-stack-testing/issues/1199
// Waiting for job to finish sometimes gets socket hang up error, from what I
// observed during debug testing the command does complete.
// Checking expected report count will still fail if the job did not finish.
try {
await reportingAPI.expectAllJobsToFinishSuccessfully([
await reportingAPI.postJob(parse(url).pathname + '?' + parse(url).query),
]);
} catch (e) {
log.debug(`Error waiting for job to finish: ${e}`);
}
usage = (await usageAPI.getUsageStats()) as UsageStats;
reportingAPI.expectCompletedReportCount(usage, completedReportCount + 1);
await retry.tryForTime(50000, async () => {
usage = (await usageAPI.getUsageStats()) as UsageStats;
reportingAPI.expectCompletedReportCount(usage, completedReportCount + 1);
});
log.debug(`Elapsed Time: ${new Date().getTime() - startTime.getTime()}`);
});
});
});