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

test: migrate page tests to new folio #6054

Merged
merged 1 commit into from
Apr 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,7 @@ jobs:
- name: Start Android Emulator
run: utils/avd_start.sh
- name: Run tests
run: npm run build-folio && node tests/folio/cli.js --config=tests/config/android.config.ts
env:
FOLIO_JSON_OUTPUT_NAME: "test-results/report-new.json"
- name: Run page tests
run: npx folio test/page -p browserName=chromium --workers=1 --forbid-only --timeout=120000 --global-timeout=5400000 --retries=3 --reporter=dot,json
run: npm run build-folio && node tests/folio/cli.js --config=tests/config/android.config.ts --reporter=dot,json
- run: ./utils/upload_flakiness_dashboard.sh ./test-results/report.json
if: always() && github.repository == 'microsoft/playwright' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-'))
- uses: actions/upload-artifact@v1
Expand Down
5 changes: 5 additions & 0 deletions test/browsercontext-set-extra-http-headers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@ it('should override extra headers from browser context', async ({browser, server
expect(request.headers['foo']).toBe('Bar');
expect(request.headers['bar']).toBe('foO');
});

it('should throw for non-string header values', async ({browser}) => {
const error3 = await browser.newContext({ extraHTTPHeaders: { 'foo': null } }).catch(e => e);
expect(error3.message).toContain('Expected value of header "foo" to be String, but "object" is found.');
});
1 change: 0 additions & 1 deletion test/page/README.md

This file was deleted.

2 changes: 2 additions & 0 deletions tests/config/androidEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export class AndroidEnv implements Env<AndroidTestArgs> {
isChromium: true,
isFirefox: false,
isWebKit: false,
browserName: 'chromium' as const,
browserChannel: undefined,
isWindows: os.platform() === 'win32',
isMac: os.platform() === 'darwin',
isLinux: os.platform() === 'linux',
Expand Down
2 changes: 2 additions & 0 deletions tests/config/pageTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export type CommonTestArgs = {

playwright: typeof import('../../index');
toImpl: (rpcObject: any) => any;
browserName: 'chromium' | 'firefox' | 'webkit';
browserChannel: string | undefined;

isChromium: boolean;
isFirefox: boolean;
Expand Down
2 changes: 0 additions & 2 deletions tests/config/playwrightTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ import { RemoteServer, RemoteServerOptions } from './remoteServer';
export { expect } from 'folio';

export type PlaywrightTestArgs = CommonTestArgs & {
browserName: 'chromium' | 'firefox' | 'webkit';
browserType: BrowserType<Browser>;
browserChannel: string | undefined;
browserOptions: LaunchOptions;
headful: boolean;
createUserDataDir: () => Promise<string>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { it, expect } from '../fixtures';
import { test as it, expect } from './config/pageTest';

it('should work', async ({ page, server }) => {
await page.goto(server.PREFIX + '/input/button.html');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
* limitations under the License.
*/

import { it, expect } from '../fixtures';
import { attachFrame } from '../utils';
import { test as it, expect } from './config/pageTest';
import { attachFrame } from '../test/utils';

it('should work', async ({ page, server }) => {
await page.goto(server.EMPTY_PAGE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { it, expect } from '../fixtures';
import { test as it, expect } from './config/pageTest';

it('should have a nice preview', async ({ page, server }) => {
await page.goto(`${server.PREFIX}/dom.html`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { it, expect } from '../fixtures';
import { test as it, expect } from './config/pageTest';

it('should work', async ({page, server}) => {
await page.setContent('<html><body><div class="tweet"><div class="like">100</div><div class="retweets">10</div></div></body></html>');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { it, expect } from '../fixtures';
import { test as it, expect } from './config/pageTest';

it('should hover', async ({ page, server }) => {
await page.goto(server.PREFIX + '/input/scrollable.html');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
* limitations under the License.
*/

import { it, expect } from '../fixtures';
import { attachFrame } from '../utils';
import { test as it, expect } from './config/pageTest';
import { attachFrame } from '../test/utils';

it('should work', async ({ page, server }) => {
await page.goto(server.EMPTY_PAGE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { it, expect } from '../fixtures';
import { test as it, expect } from './config/pageTest';

it('should work', async ({ page }) => {
await page.setContent(`<input type='text' />`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { it, expect } from '../fixtures';
import { test as it, expect } from './config/pageTest';

it('should query existing element', async ({page, server}) => {
await page.goto(server.PREFIX + '/playground.html');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
* limitations under the License.
*/

import { it, expect } from '../fixtures';
import { test as it, expect } from './config/pageTest';

it('should work', async ({ page, server }) => {
it.fixme(process.env.PW_ANDROID_TESTS);

it('should work', test => {
test.fixme(process.env.PW_ANDROID_TESTS);
}, async ({ page, server }) => {
await page.goto(server.PREFIX + '/offscreenbuttons.html');
for (let i = 0; i < 11; ++i) {
const button = await page.$('#btn' + i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { it, expect } from '../fixtures';
import { test as it, expect } from './config/pageTest';

it('should select textarea', async ({ page, server, isFirefox }) => {
await page.goto(server.PREFIX + '/input/textarea.html');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { it, expect } from '../fixtures';
import { test as it, expect } from './config/pageTest';

it('should work', async ({ page }) => {
await page.setContent(`<input type='text' />`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { it, expect } from '../fixtures';
import { test as it, expect } from './config/pageTest';

async function giveItAChanceToResolve(page) {
for (let i = 0; i < 5; i++)
Expand Down Expand Up @@ -114,9 +114,9 @@ it('should wait for disabled button', async ({page}) => {
await promise;
});

it('should wait for stable position', (test, { browserName, platform }) => {
test.fixme(browserName === 'firefox' && platform === 'linux');
}, async ({page, server}) => {
it('should wait for stable position', async ({page, server, isFirefox, platform}) => {
it.fixme(isFirefox && platform === 'linux');

await page.goto(server.PREFIX + '/input/button.html');
const button = await page.$('button');
await page.$eval('button', button => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { it, expect } from '../fixtures';
import { test as it, expect } from './config/pageTest';

it('should work with css selector', async ({page, server}) => {
await page.setContent('<div>hello</div><div>beautiful</div><div>world!</div>');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { it, expect } from '../fixtures';
import { test as it, expect } from './config/pageTest';

it('should work with css selector', async ({page, server}) => {
await page.setContent('<section id="testAttribute">43543</section>');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { it, expect } from '../fixtures';
import { test as it, expect } from './config/pageTest';

it('should work with function', async ({page}) => {
const windowHandle = await page.evaluateHandle(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { it, expect } from '../fixtures';
import { test as it, expect } from './config/pageTest';

it('should work', async ({page}) => {
const aHandle = await page.evaluateHandle(() => ({foo: 'bar'}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
* limitations under the License.
*/

import { it, expect } from '../fixtures';
import type { ElementHandle } from '../..';
import { test as it, expect } from './config/pageTest';
import type { ElementHandle } from '../index';

it('should work', async ({page}) => {
const aHandle = await page.evaluateHandle(() => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { it, expect } from '../fixtures';
import { test as it, expect } from './config/pageTest';

it('should work for primitives', async ({page}) => {
const numberHandle = await page.evaluateHandle(() => 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { it, expect } from '../fixtures';
import { test as it, expect } from './config/pageTest';
import path from 'path';

it('should evaluate before anything else on the page', async ({ page, server }) => {
Expand All @@ -27,7 +27,7 @@ it('should evaluate before anything else on the page', async ({ page, server })
});

it('should work with a path', async ({ page, server }) => {
await page.addInitScript({ path: path.join(__dirname, '../assets/injectedfile.js') });
await page.addInitScript({ path: path.join(__dirname, '../test/assets/injectedfile.js') });
await page.goto(server.PREFIX + '/tamperable.html');
expect(await page.evaluate(() => window['result'])).toBe(123);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { it, expect } from '../fixtures';
import { test as it, expect } from './config/pageTest';
import path from 'path';

it('should throw an error if no options are provided', async ({page, server}) => {
Expand Down Expand Up @@ -44,7 +44,7 @@ it('should work with a url and type=module', async ({page, server}) => {

it('should work with a path and type=module', async ({page, server}) => {
await page.goto(server.EMPTY_PAGE);
await page.addScriptTag({ path: path.join(__dirname, '../assets/es6/es6pathimport.js'), type: 'module' });
await page.addScriptTag({ path: path.join(__dirname, '../test/assets/es6/es6pathimport.js'), type: 'module' });
await page.waitForFunction('window.__es6injected');
expect(await page.evaluate(() => window['__es6injected'])).toBe(42);
});
Expand All @@ -69,16 +69,16 @@ it('should throw an error if loading from url fail', async ({page, server}) => {

it('should work with a path', async ({page, server}) => {
await page.goto(server.EMPTY_PAGE);
const scriptHandle = await page.addScriptTag({ path: path.join(__dirname, '../assets/injectedfile.js') });
const scriptHandle = await page.addScriptTag({ path: path.join(__dirname, '../test/assets/injectedfile.js') });
expect(scriptHandle.asElement()).not.toBeNull();
expect(await page.evaluate(() => window['__injected'])).toBe(42);
});

it('should include sourceURL when path is provided', (test, { browserName }) => {
test.skip(browserName === 'webkit');
}, async ({page, server}) => {
it('should include sourceURL when path is provided', async ({page, server, isWebKit}) => {
it.skip(isWebKit);

await page.goto(server.EMPTY_PAGE);
await page.addScriptTag({ path: path.join(__dirname, '../assets/injectedfile.js') });
await page.addScriptTag({ path: path.join(__dirname, '../test/assets/injectedfile.js') });
const result = await page.evaluate(() => window['__injectedError'].stack);
expect(result).toContain(path.join('assets', 'injectedfile.js'));
});
Expand All @@ -98,9 +98,9 @@ it('should throw when added with content to the CSP page', async ({page, server}
expect(error).toBeTruthy();
});

it('should throw when added with URL to the CSP page', test => {
test.skip(process.env.PW_ANDROID_TESTS);
}, async ({page, server}) => {
it('should throw when added with URL to the CSP page', async ({page, server}) => {
it.skip(process.env.PW_ANDROID_TESTS);

await page.goto(server.PREFIX + '/csp.html');
let error = null;
await page.addScriptTag({ url: server.CROSS_PROCESS_PREFIX + '/injectedfile.js' }).catch(e => error = e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { it, expect } from '../fixtures';
import { test as it, expect } from './config/pageTest';
import path from 'path';

it('should throw an error if no options are provided', async ({page, server}) => {
Expand Down Expand Up @@ -49,14 +49,14 @@ it('should throw an error if loading from url fail', async ({page, server}) => {

it('should work with a path', async ({page, server}) => {
await page.goto(server.EMPTY_PAGE);
const styleHandle = await page.addStyleTag({ path: path.join(__dirname, '../assets/injectedstyle.css') });
const styleHandle = await page.addStyleTag({ path: path.join(__dirname, '../test/assets/injectedstyle.css') });
expect(styleHandle.asElement()).not.toBeNull();
expect(await page.evaluate(`window.getComputedStyle(document.querySelector('body')).getPropertyValue('background-color')`)).toBe('rgb(255, 0, 0)');
});

it('should include sourceURL when path is provided', async ({page, server}) => {
await page.goto(server.EMPTY_PAGE);
await page.addStyleTag({ path: path.join(__dirname, '../assets/injectedstyle.css') });
await page.addStyleTag({ path: path.join(__dirname, '../test/assets/injectedstyle.css') });
const styleHandle = await page.$('style');
const styleContent = await page.evaluate(style => style.innerHTML, styleHandle);
expect(styleContent).toContain(path.join('assets', 'injectedstyle.css'));
Expand All @@ -76,9 +76,9 @@ it('should throw when added with content to the CSP page', async ({page, server}
expect(error).toBeTruthy();
});

it('should throw when added with URL to the CSP page', test => {
test.skip(process.env.PW_ANDROID_TESTS);
}, async ({page, server}) => {
it('should throw when added with URL to the CSP page', async ({page, server}) => {
it.skip(process.env.PW_ANDROID_TESTS);

await page.goto(server.PREFIX + '/csp.html');
let error = null;
await page.addStyleTag({ url: server.CROSS_PROCESS_PREFIX + '/injectedstyle.css' }).catch(e => error = e);
Expand Down
3 changes: 2 additions & 1 deletion test/page/page-check.spec.ts → tests/page-check.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { it, expect } from '../fixtures';

import { test as it, expect } from './config/pageTest';

it('should check the box', async ({page}) => {
await page.setContent(`<input id='checkbox' type='checkbox'></input>`);
Expand Down
Loading