Should locator names be utilized in templates for the purpose of simplifying E2E tests?

When conducting deep nested tests, I often struggle to locate the items I need.

Would it be unwise to use something like

<h1 name="test-main-title">About Us</h1>

and simply utilize

element(by.name('test-main-title'));?

Afterwards, in the production build, I can eliminate name="test-*" from my HTML files. I am curious if this is a bad approach before proceeding.

Answer №1

One approach is to customize an application or a specific build for testing or staging purposes in order to simplify the testing process. While this idea is commonly used, it comes with its own set of advantages and disadvantages. Personally, I prefer not to alter existing attribute values but rather focus on creating meaningful ids and data-oriented classes or other attributes.

Using ids offers several benefits - they are more stable, unique, data-driven (meaning they reflect the purpose of the element), and provide a quicker way to locate elements.

For further insights and ideas, check out these related threads:

  • Test automation html element selectors. Element ID or DataAttribute
  • Is adding IDs to everything standard practice when using Selenium?

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

Is there a way to customize the color of the icons on material-table for the actions of onRowAdd, onRowUpdate, and onRowDelete

I recently experimented with the material-table library to perform basic CRUD operations. Utilizing onRowAdd, onRowUpdate, and onRowDelete, I was able to incorporate icons for each function. However, I am interested in changing the color of these icons. Ca ...

Retrieve the variance between two arrays and store the additions in AddedList and the removals in RemovedList using typescript

I am still getting the hang of Typescript and I am trying to figure out the best solution for my issue. I have two arrays, A and B, and I need to identify the difference between them in relation to array A. The goal is to separate the elements that were ad ...

Capture an image from the webcam without any manual intervention and store it in the system's directories

Looking to automate the process of capturing a picture from a webcam once access is granted, and then saving it without any user intervention. I've managed to capture the image but struggling with: A) Automating the capture process B) Saving the ca ...

Dealing with asynchronous tasks in JavaScript

I am currently delving into the world of Node development and struggling to grasp the asynchronous nature of JavaScript and Node.js. My project involves creating a microservices backend web server using Express in the gateway service, which then translates ...

Repurpose the identical popup window

I am searching for a solution to use the same pop-up window whenever it is called. Currently, I need to submit a form into a pop-up window and it works well, except in Chrome iOS where each form submission opens a new tab/window instead of reusing the prev ...

The identifier for the $.find control is not defined

My goal is to dynamically generate a control and then modify another control without using post/get queries. For example, I have a button and a label, and I want to change the label's text using AJAX/JavaScript. Here is the code I am using: f ...

Loop through an object with only one array using JavaScript

I have a specific object structure that I am trying to iterate through in order to find a particular value within the array. For example, I want to check if the user name is equal to user2. While I was able to accomplish this with two separate objects (cre ...

html retrieve newly updated page from the provided link

I am facing an issue where I set a cookie on one page and try to unset it on the next page that I reach via a link. However, the cookie only gets unset when I refresh the second page by pressing F5. To test this scenario, I have added a link and some cook ...

Using jQuery to validate the existence of a link

Within my pagination div, I have links to the previous page and next page. The link to the previous page is structured as follows: <span id="previous"><a href="www.site.com/page/1" >Previous</a>. However, on the first page, there will be ...

Error: Unable to access the 'sid' property because it is undefined

I've been facing an issue where sending an SMS through Twilio's API Explorer works fine, but fails under my node installation. Despite a complete uninstall and reinstall, the problem persists. Error 7 Oct 21:28:37 - [nodemon] starting `node scr ...

Executing code on the server-side (back-end) using Javascript: A step-by-step guide

Imagine wanting to execute JavaScript on the server side instead of exposing the code to the client. For example: Starting with the JS native window Object from the browser. Performing all JavaScript processing in the backend by passing the window Object ...

"Automatically redirecting after 5 seconds following the submission of an ajax form using

When submitting a form, I use the following code: $(this).parents("form").ajaxForm(options); I'm wondering how can I set a timeout for this process. Specifically, I would like to redirect the page after 5 seconds of form submission. ...

What methods does the firebug use to uncover the distinct CSS pathway for Selenium?

When working on automating scripts with Selenium, I encountered a situation where I needed to locate a specific web element using a css selector. I relied on Firebug to provide me with the unique css path for that element. Surprisingly, there were instance ...

Steps for generating a pop-up window for choosing a file from a local folder?

I'm looking to develop a popup window that displays all the files within a specific directory, for example, a /functions directory. The goal is to be able to select a file in that directory, click "ok", and store its information in variables without a ...

Removing HTML elements using Nightwatch and Node.js - Step-by-step guide

It appears that in the Nightwatch framework, there is no presence of a 'document' or 'window' object. Instead, there is a 'browser' object which serves a similar purpose. I attempted to utilize methods such as .getElementById ...

Which is better to use: sql==true or sql===true?

Hey there, could you please take a look at this and thanks in advance! I'm currently working on developing a system for upgrading buildings in my game. I have set up a universal upgrade div that applies to all buildings. When the player clicks on a bu ...

Make sure to choose the radio button that corresponds to the desired title value, as this will be automatically added to the input text

Visit this link for a live example. <div class='liveExample'> <input type="radio" name="gender" value="Mr." checked>Mr. <input type="radio" name="gender" value="Mrs.">Mrs. <p>First name: <input data-bind=&ap ...

Tips for showcasing individual product information on your e-commerce site using React-js and React-Router-dom

As I work on developing an e-commerce platform, my goal is to create a functionality where users can view detailed information about a specific product by clicking on it. To achieve this, I am using React.js along with react-router-dom. Can anyone guide me ...

Retrieve the response text from a jQuery.get() call and return it

Attempting to achieve the following: var msg = $.get("my_script.php"); Expecting msg to be assigned to the text returned by my_script.php, which should be the responseText of the jqXHR object. However, it seems that msg is consistently set to "[object XM ...

The following authentication error occurred: JWEDecryptionFailed - the decryption process has encountered a failure

[...nextauth]/route.js file import { User } from "@/lib/models"; import { connectToDb } from "@/lib/utils"; import NextAuth from "next-auth"; import GitHubProvider from "next-auth/providers/github"; export const aut ...