-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
[BUG] TypeError: Cannot read properties of undefined (reading 'project') when adding projects to playwright.config.js #34559
Comments
Please provide a full repo with a reproduction. I am not able to trivally produce your issue. Two things I noticed: You're not using |
I just tried it with I'll see if I can extract a standalone repo... |
Here's a small repo where I am able to reproduce it: https://github.com/senn/playwright-project-type-error To reproduce run However, while testing this, I noticed an interesting thing: it depends on the directory where the playwright command is run. Our directory structure is like this
When running the tests from inside |
Problem found: it's because the project name is defined like this: const timestamp = new Date().toISOString();
....
name: `Automated Playwright tests ${timestamp}`, Somehow it can't handle the variable being interpolated there. I tried with singular quots and a const now = new Date();
const date = now.getDate();
const month = now.getMonth();
const year = now.getFullYear();
const hours = now.getHours();
const minutes = now.getMinutes();
const seconds = now.getSeconds();
const timestamp = date + '-' + month + '-' + year + ' ' + hours + ':' + minutes + ':' + seconds; and it still fails on the project error (with both backticks string templates or just using However if I set the const timestamp = "2025-01-31T13:08:03.807Z"; Then it works! It seems I cannot add a non-constant in there? I'm not a front-end engineer or JS expert so I have no clue. A solution or workaround to insert a dynamic name in a project would be nice, even if it may not be a PW issue (or is it?) |
I'm glad you found your problem. The config file is executed multiple times in different contexts, so a non-stable value such as the current datetime is not suitable for use in any identifiers. I have added documentation about this, and will be adding a proper error message in this particular case so it isn't a "Cannot read properties of undefined" error. For your particular usecase, why are you trying to create dynamic project names? Project names are intended to be just that; stable names for some representative of "project" (browser, device, selection of tests, etc...). |
Thanks for the docu + error message, good improvements. It doesn't make sense in a traditional Playwright context, I agree. We just need/want it because the zephyr-reporter uses the this.api.createTestCycle({
projectKey,
testPlanKey: key,
name: `${this.options.zephyr.testPlanTitle ?? key} - ${project.title}`, // <--- here
}) We wanted to have the test cycle contain the timestamp of the PW run. |
I am unfamiliar with Zephyr, but I think you might be misusing it:
In any case, this is not functionality we will be supporting. |
Well no, we're not misusing it. Playwright tests will be used to replace a lot of manual BAU and regression testing, which happens before our bi-weekly release moments. Now the tester(s) add cycles each time, and so will Playwright. But without the timestamp then... And not supporting is fine, I'm just glad I know why it's happening. Closing this ticket. Thanks for the followup. |
We have a working playwright setup for which we are using a custom reporter by a 3rd party.
This reporter requires the playwright config to use
projects
.Whenever we add this to our config (in the
use
object):we encounter the following error:
TypeError: Cannot read properties of undefined (reading 'project') when adding projects to playwright.config.js
.The error seems to be coming from PW itself, as even without our custom reporter, the error pops up when we add the projects to the config.
Reproducible on PW version 1.50.
Is there maybe a specific property that is expected in project objects, that we're missing?
We have tried adding quite a few properties, but can't seem to get solve the error. We've tried -on top of
name
-title
,use
,devices
, ...Full config:
The text was updated successfully, but these errors were encountered: