Cookie Consent by Free Privacy Policy Generator 📌 How to involve your customers in Cypress Testing?

🏠 Team IT Security News

TSecurity.de ist eine Online-Plattform, die sich auf die Bereitstellung von Informationen,alle 15 Minuten neuste Nachrichten, Bildungsressourcen und Dienstleistungen rund um das Thema IT-Sicherheit spezialisiert hat.
Ob es sich um aktuelle Nachrichten, Fachartikel, Blogbeiträge, Webinare, Tutorials, oder Tipps & Tricks handelt, TSecurity.de bietet seinen Nutzern einen umfassenden Überblick über die wichtigsten Aspekte der IT-Sicherheit in einer sich ständig verändernden digitalen Welt.

16.12.2023 - TIP: Wer den Cookie Consent Banner akzeptiert, kann z.B. von Englisch nach Deutsch übersetzen, erst Englisch auswählen dann wieder Deutsch!

Google Android Playstore Download Button für Team IT Security



📚 How to involve your customers in Cypress Testing?


💡 Newskategorie: Programmierung
🔗 Quelle: dev.to

I'm working as a consultant for an IT company, Some customer projects are not ready for E2E tests and it is not always easy to include them if you haven’t a clear idea of the code business domain flow.

It is also common, that we don't know how the customers use the application from the front-end side, and this could lead to some discrepancies between the devs and the customer's teams in the use cases.

That is why it could be useful to make our customers write tests on their own.

In these cases, Cypress helps us, providing some great features for writing some E2E tests.

One of these features is Cypress Studio, which allows you to write tests simply by clicking on the web page and tracking the interactions with your software.

How to enable Cypress Studio?

If we want to enable Cypress Studio we first need to add Cypress to our React project, which can be done with the command npm install cypress -D.

Once installed, you can run Cypress with npx cypress open and make the initial configuration.

After that, open the file "cypress.config.ts" and in the entry e2e insert this line: experimentalStudio: true.

The file should look like this now:

Cypress config

Problems:

  • If the elements we want to click are not distinguished by an id, Cypress Studio can't always keep track of the button interactions consistently.
  • As developers, our input values for tests are not the real values that the customers use.

How can we solve these problems?

One solution could be to get the elements by their tag or their label; however, with this solution, we can't directly use the tests written with Cypress Studio.
Because they would need a re-elaboration by the devs to convert the tests in a way where elements are clicked based on the content of their label.

One of the first things we had in mind was to assign a data-cy attribute to every element on the page because Cypress studio can keep track of these elements.

So we wrote a function that whenever there is an update in the body of our webpage, assigns to each element an attribute data-cy=[num], where num is the counter of the elements of the page:

idManager v1

We inserted a new script into the 'package.json' and edited our app to make the idManager work only when we run it in test mode.

package.json script

call to idManager

At first, we were satisfied with this solution, we managed to create lots of tests and they all run perfectly, even when including them in our GitHub actions.
Another cool fact was that there were no repercussions on the responsiveness of our application since the idManager was used only if we built the app for test.

It was all fun and games until we developed a new feature, the result of our GitHub Action was FAILED: 0 tests passed.
Ok cool, what's wrong now?

Debugging, we figured out that the ids of the webpage were all different from the ones in the tests, due to the modifications we applied for the feature. So we understood that assigning the ids with a counter was not a good choice.

How to make the idManager more solid toward modifications?

After some brainstorming, we ended up with a solution:
give the data-cy a value equal to the one present in some predetermined attributes, like in the following example.

// BEFORE idManager
<input name="email" />
// AFTER idManager
<input name="email" data-cy="email" />

It's not enough, in some cases, we need to get the textContent too; to obtain something like this:

// BEFORE idManager
<span>Users</span>
// AFTER idManager
<span data-cy="users">Users</span>

After some modifications, that's how we choose the value of data-cy:

getDataCy function

We first check if the tag has one of the attributes that we want to check, if it doesn't we check its textContent (only if it's one of the tags that we are interested to check).

Now that the data-cy is based on some distinctive values we can edit their positions as we want and the tests will always execute the right way.

Here is an example of the use of Cypress Studio with a webpage using our idManager:

As you can see, the test runs successfully.
However, it is good to apply a little modification: make the assert check the text in the body instead of the div; with this little tweak, we can be sure that the text we are looking for is inside the page, even if we decide to put it in another element.

Our final test will result in this code:

Test Login

Thank you very much for being here with me, I hope you find this article helpful!

If you've liked it don't forget to leave a ❤️ and comment with your opinions 👀

...



📌 How to involve your customers in Cypress Testing?


📈 62.82 Punkte

📌 Cypress vs. Sorry-Cypress - Decoding the Drama


📈 36.66 Punkte

📌 Optus cyber-attack could involve customers dating back to 2017


📈 33.57 Punkte

📌 Testing NgRx Store with Cypress Component Testing


📈 33.19 Punkte

📌 Effortless UI Testing with CircleCI and Cypress Integration: A Guide to Testing Components and Functionality on a Website


📈 33.19 Punkte

📌 How to Use Cypress for End-to-End Testing Your React Apps


📈 29.25 Punkte

📌 Cypress.io – The State of the Art End to End Testing Tool


📈 25.76 Punkte

📌 Cypress: Was kann das Testing-Framework fürs Frontend?


📈 25.76 Punkte

📌 Cypress Testing: A Guide to Running Web Application Tests


📈 25.76 Punkte

📌 Testing-Framework: Cypress 12.6 bringt UI-Neuerungen


📈 25.76 Punkte

📌 How to Perform Component Testing Using Cypress


📈 25.76 Punkte

📌 Cypress vs. Playwright: Which Is the Best Testing Tool?


📈 25.76 Punkte

📌 A Complete Guide to Cypress Visual Regression Testing


📈 25.76 Punkte

📌 Testing The Way It Should Be (aka Intro Into Cypress)


📈 25.76 Punkte

📌 Component Testing with Cypress


📈 25.76 Punkte

📌 Cypress Testing Library: Getting Started Tutorial


📈 25.76 Punkte

📌 Do I need Unit testing if I use Cypress?


📈 25.76 Punkte

📌 Testing Defer Blocks in Angular with Cypress


📈 25.76 Punkte

📌 API Testing with Cypress - Part I


📈 25.76 Punkte

📌 Enhance Testing Workflows With HTML Allure Reports in Cypress


📈 25.76 Punkte

📌 80 Percent Of Spear Phishing Attacks Involve Brand Impersonation


📈 25.15 Punkte

📌 More Domestic Abuse Cases Involve Tech


📈 25.15 Punkte

📌 85% of Data Breaches Involve Human Interaction: Verizon DBIR


📈 25.15 Punkte

📌 Getting a New Mobile Number in China Will Soon Involve a Facial-Recognition Test


📈 25.15 Punkte

📌 More Than a Tenth of Ransomware Attacks Now Involve Data Theft


📈 25.15 Punkte

📌 Third-party data breach affecting Canadian government could involve data from 1999


📈 25.15 Punkte

📌 New BEC attacks involve US agency spoofing


📈 25.15 Punkte

📌 Centrify Research Reveals 90% of Cyberattacks on Cloud Environments Involve Compromised Privileged Credentials


📈 25.15 Punkte

📌 85% of breaches involve the human element


📈 25.15 Punkte

📌 US Escalates Apple Probe, Looks To Involve Antitrust Chief


📈 25.15 Punkte

📌 Third-Party Data Breach Affecting Canadian Government Could Involve Data From 1999


📈 25.15 Punkte

📌 macOS Infostealers That Actively Involve in Attacks Evade XProtect Detection


📈 25.15 Punkte

📌 Get involve in RoslynPad Community


📈 25.15 Punkte











matomo