Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FTR: Enable w3c for chromedriver #62542

Merged
merged 13 commits into from
Apr 7, 2020
66 changes: 13 additions & 53 deletions test/functional/page_objects/common_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,42 +43,10 @@ export function CommonPageProvider({ getService, getPageObjects }: FtrProviderCo
appConfig: {};
ensureCurrentUrl: boolean;
shouldLoginIfPrompted: boolean;
shouldAcceptAlert: boolean;
useActualUrl: boolean;
}

class CommonPage {
/**
* Navigates the browser window to provided URL
* @param url URL
* @param shouldAcceptAlert pass 'true' if browser alert should be accepted
*/
private static async navigateToUrlAndHandleAlert(url: string, shouldAcceptAlert: boolean) {
log.debug('Navigate to: ' + url);
try {
await browser.get(url);
} catch (navigationError) {
log.debug('Error navigating to url');
const alert = await browser.getAlert();
if (alert && alert.accept) {
if (shouldAcceptAlert) {
log.debug('Should accept alert');
try {
await alert.accept();
} catch (alertException) {
log.debug('Error accepting alert');
throw alertException;
}
} else {
log.debug('Will not accept alert');
throw navigationError;
}
} else {
throw navigationError;
}
}
}

/**
* Returns Kibana host URL
*/
Expand Down Expand Up @@ -127,21 +95,19 @@ export function CommonPageProvider({ getService, getPageObjects }: FtrProviderCo
}

private async navigate(navigateProps: NavigateProps) {
const {
appConfig,
ensureCurrentUrl,
shouldLoginIfPrompted,
shouldAcceptAlert,
useActualUrl,
} = navigateProps;
const { appConfig, ensureCurrentUrl, shouldLoginIfPrompted, useActualUrl } = navigateProps;
const appUrl = getUrl.noAuth(config.get('servers.kibana'), appConfig);

await retry.try(async () => {
if (useActualUrl) {
log.debug(`navigateToActualUrl ${appUrl}`);
await browser.get(appUrl);
} else {
await CommonPage.navigateToUrlAndHandleAlert(appUrl, shouldAcceptAlert);
log.debug(`navigateToUrl ${appUrl}`);
await browser.get(appUrl);
// accept alert if it pops up
const alert = await browser.getAlert();
await alert?.accept();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to W3C spec driver.get call is not failing if alert pops up as before, but we need to accept it in order to proceed.

}

const currentUrl = shouldLoginIfPrompted
Expand All @@ -167,7 +133,6 @@ export function CommonPageProvider({ getService, getPageObjects }: FtrProviderCo
basePath = '',
ensureCurrentUrl = true,
shouldLoginIfPrompted = true,
shouldAcceptAlert = true,
useActualUrl = false,
} = {}
) {
Expand All @@ -180,7 +145,6 @@ export function CommonPageProvider({ getService, getPageObjects }: FtrProviderCo
appConfig,
ensureCurrentUrl,
shouldLoginIfPrompted,
shouldAcceptAlert,
useActualUrl,
});
}
Expand All @@ -200,7 +164,6 @@ export function CommonPageProvider({ getService, getPageObjects }: FtrProviderCo
basePath = '',
ensureCurrentUrl = true,
shouldLoginIfPrompted = true,
shouldAcceptAlert = true,
useActualUrl = true,
} = {}
) {
Expand All @@ -214,7 +177,6 @@ export function CommonPageProvider({ getService, getPageObjects }: FtrProviderCo
appConfig,
ensureCurrentUrl,
shouldLoginIfPrompted,
shouldAcceptAlert,
useActualUrl,
});
}
Expand All @@ -228,18 +190,12 @@ export function CommonPageProvider({ getService, getPageObjects }: FtrProviderCo
async navigateToActualUrl(
appName: string,
hash?: string,
{
basePath = '',
ensureCurrentUrl = true,
shouldLoginIfPrompted = true,
shouldAcceptAlert = true,
} = {}
{ basePath = '', ensureCurrentUrl = true, shouldLoginIfPrompted = true } = {}
) {
await this.navigateToUrl(appName, hash, {
basePath,
ensureCurrentUrl,
shouldLoginIfPrompted,
shouldAcceptAlert,
useActualUrl: true,
});
}
Expand All @@ -252,7 +208,7 @@ export function CommonPageProvider({ getService, getPageObjects }: FtrProviderCo

async navigateToApp(
appName: string,
{ basePath = '', shouldLoginIfPrompted = true, shouldAcceptAlert = true, hash = '' } = {}
{ basePath = '', shouldLoginIfPrompted = true, hash = '' } = {}
) {
let appUrl: string;
if (config.has(['apps', appName])) {
Expand All @@ -274,7 +230,11 @@ export function CommonPageProvider({ getService, getPageObjects }: FtrProviderCo
await retry.tryForTime(defaultTryTimeout * 2, async () => {
let lastUrl = await retry.try(async () => {
// since we're using hash URLs, always reload first to force re-render
await CommonPage.navigateToUrlAndHandleAlert(appUrl, shouldAcceptAlert);
log.debug('navigate to: ' + appUrl);
await browser.get(appUrl);
// accept alert if it pops up
const alert = await browser.getAlert();
await alert?.accept();
await this.sleep(700);
log.debug('returned from get, calling refresh');
await browser.refresh();
Expand Down
6 changes: 3 additions & 3 deletions test/functional/page_objects/discover_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export function DiscoverPageProvider({ getService, getPageObjects }: FtrProvider

await browser
.getActions()
.move({ x: 200, y: 20, origin: el._webElement })
.move({ x: 0, y: 20, origin: el._webElement })
LeeDr marked this conversation as resolved.
Show resolved Hide resolved
.click()
.perform();
}
Expand All @@ -142,8 +142,8 @@ export function DiscoverPageProvider({ getService, getPageObjects }: FtrProvider
const el = await elasticChart.getCanvas();

await browser.dragAndDrop(
{ location: el, offset: { x: 200, y: 20 } },
{ location: el, offset: { x: 400, y: 30 } }
{ location: el, offset: { x: -300, y: 20 } },
{ location: el, offset: { x: -100, y: 30 } }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change tested on both chromedriver and msedgedriver

);
}

Expand Down
3 changes: 2 additions & 1 deletion test/functional/services/remote/webdriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,10 @@ async function attemptToCreateCommand(
chromeOptions.push('headless', 'disable-gpu', 'remote-debugging-port=9222');
}
chromeCapabilities.set('goog:chromeOptions', {
w3c: false,
w3c: true,
args: chromeOptions,
});
chromeCapabilities.set('unexpectedAlertBehaviour', 'accept');
chromeCapabilities.set('goog:loggingPrefs', { browser: 'ALL' });

const session = await new Builder()
Expand Down