Tips for creating a Cypress command chain that includes parameters

Looking for an expander with its caption to click on it.

Successfully working:

cy.get('[caption="Radio Button"] > .expander-container').click();

Want to turn this into a command.

Cypress.Commands.add('findExpanderByName', (Caption: string) => {
    cy.get('[caption=Caption] > .expander-container').click();
    cy.wait(2000);
});

To use it:

cy.findExpanderByName("Radio Button");

However, it's not working because Caption is not being treated as a variable.

How can I get the value of the Caption variable in the command?

Answer №1

One way to achieve this is by utilizing the following code snippet:

Cypress.Commands.add('selectExpansionByName', (Title: string) => {
    cy.get(`[title=${Title}] > .expansion-box`).click();
    cy.wait(3000);
});

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

Angular two - Communication between parent and children components using a shared service

I am currently working on establishing communication between child components, but according to the documentation, I need to utilize services for this purpose. However, I am facing challenges in accessing service information. When I try to assign the retur ...

Issue with Ionic 3 subscribes triggering repeatedly

I've been struggling with the code for an Ionic taxi app for a few weeks now. My main issue is that whenever the page loads, the subscription gets triggered multiple times along with other functions within it. The same problem occurs when any travel i ...

Which specific type should be utilized for the onchange event in checkboxes?

Which type should be used for checkbox event onchange when implementing pure javascript with typescript? const checkbox = document.querySelector("#myCheckbox") as HTMLInputElement; function handleCheckboxChange(event: ChangeEvent<HTMLInputEle ...

Angular: extracting value from forkJoin nested within another observable's pipe

Here is the scenario that needs to be implemented: An API call is made which returns a response containing an array of objects. The objects are then mapped to another array of objects. For each item in this new array, another API call needs to be made. Th ...

Arrange several columns according to the chosen criteria

There is a dropdown feature in my application that has three states - ascending, descending, and none. This dropdown is responsible for rearranging the items in a list. https://i.sstatic.net/xYIfM.png This is my code: list.component.html <div *ngFor= ...

Angular 13: A guide on pulling data from an Excel spreadsheet

I have been encountering issues while trying to display data from a CSV file on a web platform using Angular 13. The errors I am facing are related to binding 'ngModel' and type mismatches in the code. errors Error: src/app/app.component.html:24 ...

Exporting an Angular 2 component to use in a template

I am interested in creating a custom Tabs component that has the ability to display content from [root] within itself. It functions perfectly when using selectors in html tags (<tab1>), but there are instances where the selector is unknown. Since Tab ...

Typescript - A guide on updating the value of a key in a Map object

My Map is designed to store Lectures as keys and Arrays of Todos as values. lecturesWithTodos: Map<Lecture, Todos[]> = new Map<Lecture, Todos[]>(); Initially, I set the key in the Map without any value since I will add the Todos later. student ...

Struggling to center align a button with Bootstrap 5 and Flexbox

I'm having trouble centering the Define New link, and I can't figure out what I'm doing wrong. I'm new to this, so please be patient with me. Below is the code snippet: <div class="col-xl-3 d-flex flex-column justify-content-be ...

"Using Angular, when $event is triggered on multiple child elements, each child

I am facing an issue with my html element in the application: .html <a (click)="onOpen($event)"> <i class="fa fa-file-text-o"></i> <p>Profile</p> </a> .ts onOpen(event):void { console.log( event.target ) ...

Exploring the Contrast of Decorators in Angular 2

Having recently started learning Angular2, I have come across some concepts that are still unclear to me despite reading various posts. The high level language used in tutorials is proving to be a challenge for me to understand, so I am reaching out for ...

Issues with Angular routing after upgrading to Angular 4

After making updates in this way, they can be found here To update on Linux/Mac: run the command npm install @angular/{common,compiler,compiler-cli,core,forms,http,platform-browser,platform-browser-dynamic,platform-server,router,animations}@latest type ...

Does Angular 8 development mode implement tree-shaking?

I am curious to know if tree-shaking occurs during Angular 8 development mode. When running the following command: ng build I understand that tree-shaking happens when I use the command below: ng build --optimization=true|false ...

Storing geolocation information in local variables for future use

I am completely new to Nativescript (with Angular 2/TypeScript). My goal is to utilize the Nativescript geolocation plugin to track a user's location and store the data (latitude and longitude) for future use. Here is a snippet of my code: export cla ...

In Certain Circumstances, Redirects Are Applicable

I have set up Private Routing in my project. With this configuration, if there is a token stored in the localStorage, users can access private routes. If not, they will be redirected to the /404 page: const token = localStorage.getItem('token'); ...

When using console.log in Angular, it displays an object as [object Object]

After receiving advice, I decided to implement a template driven form. However, when I try to log the userForm.value in the console, all I get is " [object Object] ". Can someone please point out what mistake I might be making? <form *ngIf="data" #us ...

Avoiding the restriction of narrowing generic types when employing literals with currying in TypeScript

Trying to design types for Sanctuary (js library focused on functional programming) has posed a challenge. The goal is to define an Ord type that represents any value with a natural order. In essence, an Ord can be: A built-in primitive type: number, str ...

What is the reason behind the angular http client's inability to detect plain text responses?

When I make a call to httpClient.get, I notice in Fiddler that both the request and response headers have text/plain format. Request: Accept: application/json, text/plain, */* Response: Content-Type: text/plain; charset=utf-8 Even though I am returning a ...

Changing the URI for the Apollo client instance

Currently, we are using Angular Apollo in one of our projects. The apollo client is being created like this: this.apollo.create({ link: this.httpLink.create({ uri: `${environment.apiBase}/graphql?access_token=${this.tokenService.token}`}), cache: new ...

Removing items from an array within an object stored in local storage using an Ionic application

One of my challenges involves an Ionic App that stores data in the localStorage. I need to remove specific items from an array within an object in the localStorage when a user clicks on them. Even though I have the code below, it doesn't seem to be f ...