Skip to content

Commit

Permalink
test: introduce global setup (#3544)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman authored Aug 20, 2020
1 parent eab5ff4 commit db2e66a
Show file tree
Hide file tree
Showing 75 changed files with 375 additions and 298 deletions.
30 changes: 15 additions & 15 deletions test/accessibility.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ it('should work', async function({page}) {
// autofocus happens after a delay in chrome these days
await page.waitForFunction(() => document.activeElement.hasAttribute('autofocus'));

const golden = options.FIREFOX() ? {
const golden = options.FIREFOX ? {
role: 'document',
name: 'Accessibility Test',
children: [
Expand All @@ -48,7 +48,7 @@ it('should work', async function({page}) {
{role: 'textbox', name: '', value: 'and a value'}, // firefox doesn't use aria-placeholder for the name
{role: 'textbox', name: '', value: 'and a value', description: 'This is a description!'}, // and here
]
} : options.CHROMIUM() ? {
} : options.CHROMIUM ? {
role: 'WebArea',
name: 'Accessibility Test',
children: [
Expand Down Expand Up @@ -82,7 +82,7 @@ it('should work with regular text', async({page}) => {
await page.setContent(`<div>Hello World</div>`);
const snapshot = await page.accessibility.snapshot();
expect(snapshot.children[0]).toEqual({
role: options.FIREFOX() ? 'text leaf' : 'text',
role: options.FIREFOX ? 'text leaf' : 'text',
name: 'Hello World',
});
});
Expand Down Expand Up @@ -124,7 +124,7 @@ it('should not report text nodes inside controls', async function({page}) {
<div role="tab">Tab2</div>
</div>`);
const golden = {
role: options.FIREFOX() ? 'document' : 'WebArea',
role: options.FIREFOX ? 'document' : 'WebArea',
name: '',
children: [{
role: 'tab',
Expand All @@ -139,12 +139,12 @@ it('should not report text nodes inside controls', async function({page}) {
});

// WebKit rich text accessibility is iffy
it.skip(options.WEBKIT())('rich text editable fields should have children', async function({page}) {
it.skip(options.WEBKIT)('rich text editable fields should have children', async function({page}) {
await page.setContent(`
<div contenteditable="true">
Edit this image: <img src="fakeimage.png" alt="my fake image">
</div>`);
const golden = options.FIREFOX() ? {
const golden = options.FIREFOX ? {
role: 'section',
name: '',
children: [{
Expand All @@ -170,12 +170,12 @@ it.skip(options.WEBKIT())('rich text editable fields should have children', asyn
expect(snapshot.children[0]).toEqual(golden);
});
// WebKit rich text accessibility is iffy
it.skip(options.WEBKIT())('rich text editable fields with role should have children', async function({page}) {
it.skip(options.WEBKIT)('rich text editable fields with role should have children', async function({page}) {
await page.setContent(`
<div contenteditable="true" role='textbox'>
Edit this image: <img src="fakeimage.png" alt="my fake image">
</div>`);
const golden = options.FIREFOX() ? {
const golden = options.FIREFOX ? {
role: 'textbox',
name: '',
value: 'Edit this image: my fake image',
Expand All @@ -199,7 +199,7 @@ it.skip(options.WEBKIT())('rich text editable fields with role should have child
expect(snapshot.children[0]).toEqual(golden);
});

it.skip(options.FIREFOX() || options.WEBKIT())('plain text field with role should not have children', async function({page}) {
it.skip(options.FIREFOX || options.WEBKIT)('plain text field with role should not have children', async function({page}) {
// Firefox does not support contenteditable="plaintext-only".
// WebKit rich text accessibility is iffy
await page.setContent(`
Expand All @@ -212,7 +212,7 @@ it.skip(options.FIREFOX() || options.WEBKIT())('plain text field with role shoul
});
});

it.skip(options.FIREFOX() || options.WEBKIT())('plain text field without role should not have content', async function({page}) {
it.skip(options.FIREFOX || options.WEBKIT)('plain text field without role should not have content', async function({page}) {
await page.setContent(`
<div contenteditable="plaintext-only">Edit this image:<img src="fakeimage.png" alt="my fake image"></div>`);
const snapshot = await page.accessibility.snapshot();
Expand All @@ -222,7 +222,7 @@ it.skip(options.FIREFOX() || options.WEBKIT())('plain text field without role sh
});
});

it.skip(options.FIREFOX() || options.WEBKIT())('plain text field with tabindex and without role should not have content', async function({page}) {
it.skip(options.FIREFOX || options.WEBKIT)('plain text field with tabindex and without role should not have content', async function({page}) {
await page.setContent(`
<div contenteditable="plaintext-only" tabIndex=0>Edit this image:<img src="fakeimage.png" alt="my fake image"></div>`);
const snapshot = await page.accessibility.snapshot();
Expand All @@ -238,11 +238,11 @@ it('non editable textbox with role and tabIndex and label should not have childr
this is the inner content
<img alt="yo" src="fakeimg.png">
</div>`);
const golden = options.FIREFOX() ? {
const golden = options.FIREFOX ? {
role: 'textbox',
name: 'my favorite textbox',
value: 'this is the inner content yo'
} : options.CHROMIUM() ? {
} : options.CHROMIUM ? {
role: 'textbox',
name: 'my favorite textbox',
value: 'this is the inner content '
Expand Down Expand Up @@ -276,7 +276,7 @@ it('checkbox without label should not have children', async function({page}) {
this is the inner content
<img alt="yo" src="fakeimg.png">
</div>`);
const golden = options.FIREFOX() ? {
const golden = options.FIREFOX ? {
role: 'checkbox',
name: 'this is the inner content yo',
checked: true
Expand Down Expand Up @@ -327,7 +327,7 @@ it('should work on a menu', async({page}) => {
[ { role: 'menuitem', name: 'First Item' },
{ role: 'menuitem', name: 'Second Item' },
{ role: 'menuitem', name: 'Third Item' } ],
orientation: options.WEBKIT() ? 'vertical' : undefined
orientation: options.WEBKIT ? 'vertical' : undefined
});
});

Expand Down
2 changes: 1 addition & 1 deletion test/browser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ it('should throw upon second create new page', async function({browser}) {

it('version should work', async function({browser}) {
const version = browser.version();
if (options.CHROMIUM())
if (options.CHROMIUM)
expect(version.match(/^\d+\.\d+\.\d+\.\d+$/)).toBeTruthy();
else
expect(version.match(/^\d+\.\d+/)).toBeTruthy();
Expand Down
2 changes: 1 addition & 1 deletion test/browsercontext-add-cookies.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ it('should(not) block third party cookies', async({context, page, server}) => {
}, server.CROSS_PROCESS_PREFIX + '/grid.html');
await page.frames()[1].evaluate(`document.cookie = 'username=John Doe'`);
await page.waitForTimeout(2000);
const allowsThirdParty = options.CHROMIUM() || options.FIREFOX();
const allowsThirdParty = options.CHROMIUM || options.FIREFOX;
const cookies = await context.cookies(server.CROSS_PROCESS_PREFIX + '/grid.html');
if (allowsThirdParty) {
expect(cookies).toEqual([
Expand Down
2 changes: 1 addition & 1 deletion test/browsercontext-basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ it('should disable javascript', async({browser}) => {
await page.goto('data:text/html, <script>var something = "forbidden"</script>');
let error = null;
await page.evaluate('something').catch(e => error = e);
if (options.WEBKIT())
if (options.WEBKIT)
expect(error.message).toContain('Can\'t find variable: something');
else
expect(error.message).toContain('something is not defined');
Expand Down
4 changes: 2 additions & 2 deletions test/browsercontext-cookies.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ it('should properly report httpOnly cookie', async({context, page, server}) => {
expect(cookies[0].httpOnly).toBe(true);
});

it.fail(options.WEBKIT() && WIN)('should properly report "Strict" sameSite cookie', async({context, page, server}) => {
it.fail(options.WEBKIT && WIN)('should properly report "Strict" sameSite cookie', async({context, page, server}) => {
server.setRoute('/empty.html', (req, res) => {
res.setHeader('Set-Cookie', 'name=value;SameSite=Strict');
res.end();
Expand All @@ -83,7 +83,7 @@ it.fail(options.WEBKIT() && WIN)('should properly report "Strict" sameSite cooki
expect(cookies[0].sameSite).toBe('Strict');
});

it.fail(options.WEBKIT() && WIN)('should properly report "Lax" sameSite cookie', async({context, page, server}) => {
it.fail(options.WEBKIT && WIN)('should properly report "Lax" sameSite cookie', async({context, page, server}) => {
server.setRoute('/empty.html', (req, res) => {
res.setHeader('Set-Cookie', 'name=value;SameSite=Lax');
res.end();
Expand Down
6 changes: 3 additions & 3 deletions test/browsercontext-credentials.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
import { options } from './playwright.fixtures';

it.fail(options.CHROMIUM() && !options.HEADLESS)('should fail without credentials', async({browser, server}) => {
it.fail(options.CHROMIUM && !options.HEADLESS)('should fail without credentials', async({browser, server}) => {
server.setAuth('/empty.html', 'user', 'pass');
const context = await browser.newContext();
const page = await context.newPage();
Expand All @@ -25,7 +25,7 @@ it.fail(options.CHROMIUM() && !options.HEADLESS)('should fail without credential
await context.close();
});

it.fail(options.CHROMIUM() && !options.HEADLESS)('should work with setHTTPCredentials', async({browser, server}) => {
it.fail(options.CHROMIUM && !options.HEADLESS)('should work with setHTTPCredentials', async({browser, server}) => {
server.setAuth('/empty.html', 'user', 'pass');
const context = await browser.newContext();
const page = await context.newPage();
Expand All @@ -48,7 +48,7 @@ it('should work with correct credentials', async({browser, server}) => {
await context.close();
});

it.fail(options.CHROMIUM() && !options.HEADLESS)('should fail with wrong credentials', async({browser, server}) => {
it.fail(options.CHROMIUM && !options.HEADLESS)('should fail with wrong credentials', async({browser, server}) => {
server.setAuth('/empty.html', 'user', 'pass');
const context = await browser.newContext({
httpCredentials: { username: 'foo', password: 'bar' }
Expand Down
6 changes: 3 additions & 3 deletions test/browsercontext-device.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
import { options } from './playwright.fixtures';

it.skip(options.FIREFOX())('should work', async({playwright, browser, server}) => {
it.skip(options.FIREFOX)('should work', async({playwright, browser, server}) => {
const iPhone = playwright.devices['iPhone 6'];
const context = await browser.newContext({ ...iPhone });
const page = await context.newPage();
Expand All @@ -26,7 +26,7 @@ it.skip(options.FIREFOX())('should work', async({playwright, browser, server}) =
await context.close();
});

it.skip(options.FIREFOX())('should support clicking', async({playwright, browser, server}) => {
it.skip(options.FIREFOX)('should support clicking', async({playwright, browser, server}) => {
const iPhone = playwright.devices['iPhone 6'];
const context = await browser.newContext({ ...iPhone });
const page = await context.newPage();
Expand All @@ -38,7 +38,7 @@ it.skip(options.FIREFOX())('should support clicking', async({playwright, browser
await context.close();
});

it.skip(options.FIREFOX())('should scroll to click', async({browser, server}) => {
it.skip(options.FIREFOX)('should scroll to click', async({browser, server}) => {
const context = await browser.newContext({
viewport: {
width: 400,
Expand Down
2 changes: 1 addition & 1 deletion test/browsercontext-locale.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ it('should be isolated between contexts', async({browser, server}) => {
]);
});

it.fail(options.FIREFOX())('should not change default locale in another context', async({browser, server}) => {
it.fail(options.FIREFOX)('should not change default locale in another context', async({browser, server}) => {
async function getContextLocale(context) {
const page = await context.newPage();
return await page.evaluate(() => (new Intl.NumberFormat()).resolvedOptions().locale);
Expand Down
4 changes: 2 additions & 2 deletions test/browsercontext-page-event.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ it('should fire page lifecycle events', async function({browser, server}) {
await context.close();
});

it.fail(options.WEBKIT())('should work with Shift-clicking', async({browser, server}) => {
it.fail(options.WEBKIT)('should work with Shift-clicking', async({browser, server}) => {
// WebKit: Shift+Click does not open a new window.
const context = await browser.newContext();
const page = await context.newPage();
Expand All @@ -170,7 +170,7 @@ it.fail(options.WEBKIT())('should work with Shift-clicking', async({browser, ser
await context.close();
});

it.fail(options.WEBKIT() || options.FIREFOX())('should work with Ctrl-clicking', async({browser, server}) => {
it.fail(options.WEBKIT || options.FIREFOX)('should work with Ctrl-clicking', async({browser, server}) => {
// Firefox: reports an opener in this case.
// WebKit: Ctrl+Click does not open a new tab.
const context = await browser.newContext();
Expand Down
2 changes: 1 addition & 1 deletion test/browsercontext-timezone-id.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ it('should work for multiple pages sharing same process', async({browser, server
await context.close();
});

it.fail(options.FIREFOX())('should not change default timezone in another context', async({browser, server}) => {
it.fail(options.FIREFOX)('should not change default timezone in another context', async({browser, server}) => {
async function getContextTimezone(context) {
const page = await context.newPage();
return await page.evaluate(() => Intl.DateTimeFormat().resolvedOptions().timeZone);
Expand Down
18 changes: 9 additions & 9 deletions test/browsercontext-viewport-mobile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import { options } from './playwright.fixtures';

it.skip(options.FIREFOX())('should support mobile emulation', async({playwright, browser, server}) => {
it.skip(options.FIREFOX)('should support mobile emulation', async({playwright, browser, server}) => {
const iPhone = playwright.devices['iPhone 6'];
const context = await browser.newContext({ ...iPhone });
const page = await context.newPage();
Expand All @@ -28,7 +28,7 @@ it.skip(options.FIREFOX())('should support mobile emulation', async({playwright,
await context.close();
});

it.skip(options.FIREFOX())('should support touch emulation', async({playwright, browser, server}) => {
it.skip(options.FIREFOX)('should support touch emulation', async({playwright, browser, server}) => {
const iPhone = playwright.devices['iPhone 6'];
const context = await browser.newContext({ ...iPhone });
const page = await context.newPage();
Expand All @@ -51,7 +51,7 @@ it.skip(options.FIREFOX())('should support touch emulation', async({playwright,
}
});

it.skip(options.FIREFOX())('should be detectable by Modernizr', async({playwright, browser, server}) => {
it.skip(options.FIREFOX)('should be detectable by Modernizr', async({playwright, browser, server}) => {
const iPhone = playwright.devices['iPhone 6'];
const context = await browser.newContext({ ...iPhone });
const page = await context.newPage();
Expand All @@ -60,7 +60,7 @@ it.skip(options.FIREFOX())('should be detectable by Modernizr', async({playwrigh
await context.close();
});

it.skip(options.FIREFOX())('should detect touch when applying viewport with touches', async({browser, server}) => {
it.skip(options.FIREFOX)('should detect touch when applying viewport with touches', async({browser, server}) => {
const context = await browser.newContext({ viewport: { width: 800, height: 600 }, hasTouch: true });
const page = await context.newPage();
await page.goto(server.EMPTY_PAGE);
Expand All @@ -69,7 +69,7 @@ it.skip(options.FIREFOX())('should detect touch when applying viewport with touc
await context.close();
});

it.skip(options.FIREFOX())('should support landscape emulation', async({playwright, browser, server}) => {
it.skip(options.FIREFOX)('should support landscape emulation', async({playwright, browser, server}) => {
const iPhone = playwright.devices['iPhone 6'];
const iPhoneLandscape = playwright.devices['iPhone 6 landscape'];
const context1 = await browser.newContext({ ...iPhone });
Expand All @@ -83,7 +83,7 @@ it.skip(options.FIREFOX())('should support landscape emulation', async({playwrig
await context2.close();
});

it.skip(options.FIREFOX())('should support window.orientation emulation', async({browser, server}) => {
it.skip(options.FIREFOX)('should support window.orientation emulation', async({browser, server}) => {
const context = await browser.newContext({ viewport: { width: 300, height: 400 }, isMobile: true });
const page = await context.newPage();
await page.goto(server.PREFIX + '/mobile.html');
Expand All @@ -93,7 +93,7 @@ it.skip(options.FIREFOX())('should support window.orientation emulation', async(
await context.close();
});

it.skip(options.FIREFOX())('should fire orientationchange event', async({browser, server}) => {
it.skip(options.FIREFOX)('should fire orientationchange event', async({browser, server}) => {
const context = await browser.newContext({ viewport: { width: 300, height: 400 }, isMobile: true });
const page = await context.newPage();
await page.goto(server.PREFIX + '/mobile.html');
Expand All @@ -112,15 +112,15 @@ it.skip(options.FIREFOX())('should fire orientationchange event', async({browser
await context.close();
});

it.skip(options.FIREFOX())('default mobile viewports to 980 width', async({browser, server}) => {
it.skip(options.FIREFOX)('default mobile viewports to 980 width', async({browser, server}) => {
const context = await browser.newContext({ viewport: {width: 320, height: 480 }, isMobile: true });
const page = await context.newPage();
await page.goto(server.PREFIX + '/empty.html');
expect(await page.evaluate(() => window.innerWidth)).toBe(980);
await context.close();
});

it.skip(options.FIREFOX())('respect meta viewport tag', async({browser, server}) => {
it.skip(options.FIREFOX)('respect meta viewport tag', async({browser, server}) => {
const context = await browser.newContext({ viewport: {width: 320, height: 480 }, isMobile: true });
const page = await context.newPage();
await page.goto(server.PREFIX + '/mobile.html');
Expand Down
6 changes: 3 additions & 3 deletions test/browsertype-basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ it.skip(Boolean(process.env.CRPATH || process.env.FFPATH || process.env.WKPATH))
});

it('browserType.name should work', async({browserType}) => {
if (options.WEBKIT())
if (options.WEBKIT)
expect(browserType.name()).toBe('webkit');
else if (options.FIREFOX())
else if (options.FIREFOX)
expect(browserType.name()).toBe('firefox');
else if (options.CHROMIUM())
else if (options.CHROMIUM)
expect(browserType.name()).toBe('chromium');
else
throw new Error('Unknown browser');
Expand Down
2 changes: 1 addition & 1 deletion test/browsertype-connect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ it.skip(options.WIRE).slow()('should be able to reconnect to a browser', async({
await browserServer.close();
});

it.skip(options.WIRE).fail(options.CHROMIUM() && WIN).slow()('should handle exceptions during connect', async({browserType, defaultBrowserOptions}) => {
it.skip(options.WIRE).fail(options.CHROMIUM && WIN).slow()('should handle exceptions during connect', async({browserType, defaultBrowserOptions}) => {
const browserServer = await browserType.launchServer(defaultBrowserOptions);
const __testHookBeforeCreateBrowser = () => { throw new Error('Dummy') };
const error = await browserType.connect({ wsEndpoint: browserServer.wsEndpoint(), __testHookBeforeCreateBrowser } as any).catch(e => e);
Expand Down
2 changes: 1 addition & 1 deletion test/browsertype-launch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ it('should throw if userDataDir option is passed', async({browserType, defaultBr
expect(waitError.message).toContain('launchPersistentContext');
});

it.skip(options.FIREFOX())('should throw if page argument is passed', async({browserType, defaultBrowserOptions}) => {
it.skip(options.FIREFOX)('should throw if page argument is passed', async({browserType, defaultBrowserOptions}) => {
let waitError = null;
const options = Object.assign({}, defaultBrowserOptions, { args: ['http://example.com'] });
await browserType.launch(options).catch(e => waitError = e);
Expand Down
Loading

0 comments on commit db2e66a

Please sign in to comment.