Tips for specifying which project starts the setup process in Playwright

I have multiple projects in my playwright.config file, all of which have the same setup project as a dependency.

Is there a way to determine at runtime which parent project is initiating the setup process?

playwright.config

projects: [
    { name: "setup", testMatch: /.*\.setup\.ts/ },
    {
      name: "foo",
      dependencies: ["setup"],
    },
    {
      name: "bar",
      dependencies: ["setup"],
    },
]

setup test

setup("setup test", async ({ page }, testInfo) => {
  console.log(testInfo.project.name); // output: "setup"

  /* Desired output: */
  // console.log(testInfo.paretProject.name);

  /* Or */
  // console.log(testInfo.project.parentName)
});

(Possibly by providing the initiator name within the project dependency properties somehow)

Answer №1

To retrieve all parent projects, you can filter out projects that have the current project as a dependency.

Keep in mind that this approach will not exclude projects that are not currently being executed. For example, if you are running

npx playwright test --project "foo"
, both parent projects will still be included in the results.

import { test as setup } from "@playwright/test";

setup("Setup", async ({}, testInfo) => {
  const parentProjects = testInfo.config.projects
    .filter((project) => project.dependencies.includes(testInfo.project.name))
    .map((project) => project.name);

  // Output: ['foo', 'bar']
  console.log(parentProjects);
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Removing entries in a Google spreadsheet by utilizing the API and executing a BatchUpdateRequest

Currently, I am working on sending a BatchUpdateRequest to the Google Sheets API in order to delete a row of data from a spreadsheet. Here is how my request is structured: var spreadsheetId = '1EV8S8AaAmxF3vP0F6RWxKIUlvF6uFEmsrOFWA1oNBYI'; ...

Error in Node.js: Unable to access properties of null value within Express

While using Express (with node.js) and MongoDB, I encountered an error when trying to view or update a user profile. The middleware token check worked fine getProfileFields:::::::::::::>>>>e: TypeError: Cannot read properties of null (rea ...

Which jquery version is the best fit for my script?

I wanted to figure out which version of jQuery I am using based on a script that my friend wrote for me. Unfortunately, he is on holiday and I can't reach him. I included the following code within my body tag and called it below: $(document).ready(f ...

HTML/CSS - Enhances user experience by zooming in on select tag when tapped on mobile devices

I am experiencing an issue with a select menu on mobile devices. Whenever I tap on the menu, it seems to zoom in slightly. Is there a particular -webkit property causing this behavior? How can I prevent the screen from zooming when I tap on the select me ...

Console displays null as the attribute value

When I check the console, I notice that the data-postid attribute is displaying 'null'. What could be causing this issue? I would like to view the data-id in the console when clicking on the button with the id modal-save. I have reviewed my cod ...

Tips for validating an object with unspecified properties in RunTypes (lowercase object type in TypeScript)

Can someone please confirm if the following code is correct for validating an object: export const ExternalLinks = Record({}) I'm specifically asking in relation to the repository. ...

Generating ChartJS in Real-time

I have a straightforward form where the user selects a start date and an end date. Once these dates are selected, the tool automatically fetches data from a website in JSON format. Below is the code for my Angular controller: (function () { angular.m ...

Ordering an Array of JavaScript Objects in a Custom Sequence (utilizing pre-existing methods)

Imagine we have an array of objects: ["c", "a", "b", "d"] Is there a way in ECMAScript or through a third-party JavaScript library to rearrange the objects in the first array to match the order specified by the second array, all within one line or functi ...

Is it possible for me to include the id attribute in an HTML element that has been generated using React

While working with Selenium to create end-to-end tests for a React-based web application, I noticed that very few HTML elements have the id property set. Since our development team is preoccupied with other tasks, I've taken it upon myself to address ...

Bidirectional communication linking an Angular 2 component and service utilizing the power of Observables

I'm having difficulties establishing a simple connection between an Angular 2 component and service using Observable. I've been trying to achieve this, but I can't seem to get it right. Here's the scenario: My component HeroViewerCompo ...

AngularJS Error: $element.find(...) does not support iteration

I'm attempting to utilize a datatable in my AngularJS application. Below is the HTML code I've implemented: <div ng-app="datatable"> <div ng-controller="voucherlistcontroller"> ...

HTML: Base64 image not displaying properly due to incorrect height specification

I have a straightforward base64 image that I am having trouble with. The issue is that only the upper half of the image is displaying. If I try to adjust the height using the "style" attribute in the img tag: style="height: 300px;" it shows correctly. Ho ...

Looking for solutions to manage mouseenter, mouseleave events and ensuring content dropdowns stay visible in Vue.js 2?

Hey there, I'm trying to figure out how to keep dropdown content from disappearing when using @mouseenter and @mouseleave. Here's what I have so far: <div class="wrapper"> <div class="link" @mouseenter="show = ...

The functionality of cloning in jQuery may encounter an issue where the text field remains enabled if the user selects an option labeled "other

Currently, I am working on a jQuery clone with my existing code and everything is functioning well. In the first scenario, if the user selects other from the dropdown menu, the text field becomes enabled. In the second scenario, when the user clicks ...

The URL for the form action does not match the URL of the current page

Issue: I'm encountering an issue with a form where the form action URL is different from the page URL where the form is located. Page URL = www.page.com Form action = "" Problem: After submitting the form, it redirects to the form action URL inst ...

Is Javascript the best choice for managing multiple instances of similar HTML code?

I am currently facing the challenge of dealing with a lengthy HTML page consisting of around 300 lines of code. The majority of the code involves repetitive forms, each identical except for the ID (which varies by number). Is it considered appropriate or ...

Navigating through various product categories in Angular's routing system

Greetings! I am currently building a Shop Page in Angular 4 and encountering an obstacle with Angular routing. The issue arises when a user clicks on a product category, the intention is for the website to direct them to the shop page. On the homepage, th ...

Trouble with rendering inline images from markdown files in GatsbyJS

I've been trying to include inline images in my markdown file with the gatsby-remark-images plugin. However, I'm facing an issue where the image is not loading on my local host. I'm not sure if it's a syntax error or if I'm missing ...

Issue with pre-selected default value in AngularJS TypeScript Kendo UI DropDownList

I have successfully implemented a list of objects for items, but now I am facing a challenge in adding a default selected value. Below is the HTML code for the drop-down: <select kendo-drop-down-list k-options="selectItems" k-ng-mode ...

Incorporating JSON Objects within AngularJS

Currently, I am using AngularJS to fetch JSON data like this: $http.get('/balance').then(function (response) { $scope.balance = response.data; }); The value of response.data is as follows: { "pending": [{ "amount": 16, "currency": ...