[BUG] @playwright/test@next build from 1.19.0-alpha-feb-2-2022 onwards is bad
See original GitHub issueContext:
- Playwright Version: [1.19.0-alpha-feb-2-2022]
- Operating System: [Mac]
- Node.js version: [v17.2.0]
- Browser: [e.g. All]
- Extra: [Feb-1-2022 builds works correctly]
Code Snippet
playwright-config.js
pw_global_setup_demo.js
const fs = require('fs');
const path = require('path');
const delay_time = ms => new Promise(res => setTimeout(res, ms));
module.exports = async () => {
const opSys = process.platform;
console.log(opSys);
process.env.JSONPath = path.resolve('./common/data_config_json/test.json');
console.log(process.env.JSONPath);
};
pw_sample.js
const { test, expect } = require('@playwright/test');
const fs = require("fs");
const path = require('path');
console.log('PRINT ENV VARIABLE FROM GLOBAL SETUP ' + process.env.JSONPath);
let JSONPath_Working = JSON.parse(fs.readFileSync('/Users/ravuri/Documents/pw-automation-bitbucket/kb-automation-playwright/common/data_config_json/test.json'));
console.log(JSONPath_Working);
let JSONPath_NotWorking = JSON.parse(fs.readFileSync(process.env.JSONPath));
console.log(JSONPath_NotWorking);
test.describe.serial('suite', () => {
test('basic test1', async ({ page,browser },testInfo) => {
await page.goto('https://playwright.dev/');
const title = page.locator('.navbar__inner .navbar__title');
await expect(title).toHaveText('Playwright');
});
});
Describe the bug It appears something got changed in 1.19.0-alpha-feb-2-2022 build onwards. Environment variables set in global setup are no longer resolved in spec file. In the output you can see the value of file path set by environment variable is undefined.
Log output - 1.19.0-alpha-feb-2-2022 - Failed Test Case
{ test_json: 'playwright' }
Running 0 test using 0 worker
TypeError: The "path" argument must be of type string or an instance of Buffer or URL. Received undefined
at Object.openSync (node:fs:577:10)
at Object.readFileSync (node:fs:453:35)
at Object.<anonymous> (/Users/ravuri/Documents/pw-automation-bitbucket/kb-automation-playwright/test/demo/pw_sample.js:10:42)
at Module._compile (node:internal/modules/cjs/loader:1097:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1149:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:999:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Loader._requireOrImport (/Users/ravuri/Documents/pw-automation-bitbucket/kb-automation-playwright/node_modules/@playwright/test/lib/loader.js:269:14)
at Loader.loadTestFile (/Users/ravuri/Documents/pw-automation-bitbucket/kb-automation-playwright/node_modules/@playwright/test/lib/loader.js:139:18)
at Runner._runFiles (/Users/ravuri/Documents/pw-automation-bitbucket/kb-automation-playwright/node_modules/@playwright/test/lib/runner.js:275:44)
at Runner._run (/Users/ravuri/Documents/pw-automation-bitbucket/kb-automation-playwright/node_modules/@playwright/test/lib/runner.js:208:23)
at TimeoutRunner.run (/Users/ravuri/Documents/pw-automation-bitbucket/kb-automation-playwright/node_modules/playwright-core/lib/utils/async.js:38:14)
at raceAgainstTimeout (/Users/ravuri/Documents/pw-automation-bitbucket/kb-automation-playwright/node_modules/playwright-core/lib/utils/async.js:85:15)
=================
no tests found.
=================
Log output - 1.19.0-alpha-feb-2-2022 - if i comment out the environment variable in spec file to read the JSON file
PRINT ENV VARIABLE FROM GLOBAL SETUP undefined
{ test_json: 'playwright' }
Running 1 test using 1 worker
darwin
/Users/ravuri/Documents/pw-automation-bitbucket/kb-automation-playwright/common/data_config_json/test.json
PRINT ENV VARIABLE FROM GLOBAL SETUP /Users/ravuri/Documents/pw-automation-bitbucket/kb-automation-playwright/common/data_config_json/test.json
{ test_json: 'playwright' }
✓ [demo1] › test/demo/pw_sample.js:15:5 › suite › basic test1 (3s)
Logout - 1.19.0-alpha-feb-1-2022
darwin
/Users/ravuri/Documents/pw-automation-bitbucket/kb-automation-playwright/common/data_config_json/test.json
PRINT ENV VARIABLE FROM GLOBAL SETUP /Users/ravuri/Documents/pw-automation-bitbucket/kb-automation-playwright/common/data_config_json/test.json
{ test_json: 'playwright' }
Running 1 test using 1 worker
PRINT ENV VARIABLE FROM GLOBAL SETUP /Users/ravuri/Documents/pw-automation-bitbucket/kb-automation-playwright/common/data_config_json/test.json
{ test_json: 'playwright' }
✓ [demo1] › test/demo/pw_sample.js:15:5 › suite › basic test1 (3s)
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (6 by maintainers)
Top Results From Across the Web
Error: Cannot find module '@playwright/test' - Stack Overflow
It is a very short script but something is wrong with that. const { chromium } = require("playwright"); const { expect } =...
Read more >End-to-End Testing with Playwright (an Intro) - YouTube
Playwright is a fantastic solution-for-end to end testing web apps and games. You can use it to write scripts that emulate real user ......
Read more >Playwright - Quality Thoughts
How good are our Playwright tests at catching regressions? How much manual regression testing do we perform? And finally some metrics to answer...
Read more >Testing Next.js with Playwright - Frontend Digest
This step is going to be a bit controversial as most test runners run against your development setup or sort of build your...
Read more >How to Use Playwright with Next.js, Vercel, and GitHub
Learn how to integrate Playwright tests into the deployment process of your Next.js site hosted on Vercel.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@yury-s I’ll correct the repro steps. Trying to simplify the steps.
For the record, here is a description of the changes made in v1.19 and possible solutions. Thank you for reporting the issue!