Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

chore(jest): convert browser tests to jest (#3000)

Joel Einbinderdf8b27069e8e
diff --git a/test/browser.spec.js b/test/browser.jest.js
similarity index 94%
rename from test/browser.spec.js
rename to test/browser.jest.js
index 3047c71621..445fc22347 100644
--- a/test/browser.spec.js
+++ b/test/browser.jest.js
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-const {FFOX, CHROMIUM, WEBKIT} = require('./utils').testOptions(browserType);
+const {FFOX, CHROMIUM, WEBKIT} = testOptions;
describe('Browser.newPage', function() {
it('should create new page', async function({browser}) {
diff --git a/test/browsercontext.spec.js b/test/browsercontext.jest.js
similarity index 99%
rename from test/browsercontext.spec.js
rename to test/browsercontext.jest.js
index 13253f6ae9..73939805ab 100644
--- a/test/browsercontext.spec.js
+++ b/test/browsercontext.jest.js
@@ -16,7 +16,8 @@
*/
const utils = require('./utils');
-const {FFOX, CHROMIUM, WEBKIT, MAC, CHANNEL} = utils.testOptions(browserType);
+const {FFOX, CHROMIUM, WEBKIT, MAC, CHANNEL, HEADLESS} = testOptions;
+const {devices} = require('..');
describe('BrowserContext', function() {
it('should create new context', async function({browser}) {
@@ -194,7 +195,7 @@ describe('BrowserContext({userAgent})', function() {
await context.close();
}
{
- const context = await browser.newContext({ userAgent: playwright.devices['iPhone 6'].userAgent });
+ const context = await browser.newContext({ userAgent: devices['iPhone 6'].userAgent });
const page = await context.newPage();
await page.goto(server.PREFIX + '/mobile.html');
expect(await page.evaluate(() => navigator.userAgent)).toContain('iPhone');
diff --git a/test/channels.spec.js b/test/channels.jest.js
similarity index 98%
rename from test/channels.spec.js
rename to test/channels.jest.js
index 950266a84b..7873efc8b4 100644
--- a/test/channels.spec.js
+++ b/test/channels.jest.js
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-const { FFOX, CHROMIUM, WEBKIT, WIN, CHANNEL } = require('./utils').testOptions(browserType);
+const { FFOX, CHROMIUM, WEBKIT, WIN, CHANNEL } = testOptions;
describe.skip(!CHANNEL)('Channels', function() {
it('should work', async({browser}) => {
diff --git a/test/ignorehttpserrors.spec.js b/test/ignorehttpserrors.jest.js
similarity index 97%
rename from test/ignorehttpserrors.spec.js
rename to test/ignorehttpserrors.jest.js
index 5657ae22fb..3c83091844 100644
--- a/test/ignorehttpserrors.spec.js
+++ b/test/ignorehttpserrors.jest.js
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-const {FFOX, CHROMIUM, WEBKIT, MAC} = require('./utils').testOptions(browserType);
+const {FFOX, CHROMIUM, WEBKIT, MAC} = testOptions;
describe('ignoreHTTPSErrors', function() {
it('should work', async({browser, httpsServer}) => {
diff --git a/test/popup.spec.js b/test/popup.jest.js
similarity index 99%
rename from test/popup.spec.js
rename to test/popup.jest.js
index a142dd3458..fe0f00aa85 100644
--- a/test/popup.spec.js
+++ b/test/popup.jest.js
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-const {FFOX, CHROMIUM, WEBKIT, MAC} = require('./utils').testOptions(browserType);
+const {FFOX, CHROMIUM, WEBKIT, MAC} = testOptions;
describe('Link navigation', function() {
it('should inherit user agent from browser context', async function({browser, server}) {
diff --git a/test/test.config.js b/test/test.config.js
index 3a76858f63..65cf323a8d 100644
--- a/test/test.config.js
+++ b/test/test.config.js
@@ -99,17 +99,6 @@ module.exports = {
environments: [customEnvironment, 'page'],
},
- {
- files: [
- './browser.spec.js',
- './browsercontext.spec.js',
- './channels.spec.js',
- './ignorehttpserrors.spec.js',
- './popup.spec.js',
- ],
- environments: [customEnvironment, 'browser'],
- },
-
{
files: [
'./defaultbrowsercontext.spec.js',
diff --git a/test/test.js b/test/test.js
index cde1db4453..6e7ea45a40 100644
--- a/test/test.js
+++ b/test/test.js
@@ -127,9 +127,7 @@ function collect(browserNames) {
const skip = spec.browsers && !spec.browsers.includes(browserName);
(skip ? xdescribe : describe)(spec.title || '', () => {
for (const e of spec.environments || ['page']) {
- if (e === 'browser') {
- testRunner.collector().useEnvironment(browserEnvironment);
- } else if (e === 'page') {
+ if (e === 'page') {
testRunner.collector().useEnvironment(browserEnvironment);
testRunner.collector().useEnvironment(pageEnvironment);
} else {