What is the best way to continuously verify login and password credentials?

I am a newcomer to this industry and am facing a challenge with testing the process of entering the correct username and password using Selenium Webdriver. The current method of creating this process without a loop is extremely lengthy and monotonous. Here's an example:

let element0 = driver.findElement(By.id("login"));   
  element0.click();   
  element0.sendKeys("admin");
  await driver.sleep(1500);
  element0.clear();

I need a loop that will take the first element from the array of logins and passwords, insert them into the corresponding fields, check them, delete them, etc.

I attempted to use a for loop, but it outputted all elements of the array.

async function fillLoginPassBox() {
  let element0 = driver.findElement(By.id("login"));
  let element1 = driver.findElement(By.xpath('//*[@id="password"]'));
  let logins = ['test0', 'test1', 'admin'];
  let passwords = ['test0', 'test1', 'admin'];      

    for(let key in logins) {
      element0.sendKeys(logins[key]);
      element0.click();
      element0.clear();
      console.log(logins[key]);
    }
   // element0.click();
   // element0.sendKeys("admin");  
      await driver.sleep(1500);                                         
      element1.click();
      element1.sendKeys("admin");
      await driver.sleep(1500);
      return element1, element0;
}

Answer №1

It is not advisable to try to accomplish everything you need within a single method. Each method should focus on doing one thing, such as logging in, to ensure better readability and easier maintenance.

While it may seem efficient to handle multiple login attempts in a single script and browser, it is actually considered poor practice. It is recommended to create a single login script and execute it in parallel with different sets of login credentials.

An example of a login script:

  1. Open a browser instance
  2. Go to the login page
  3. Log in with the provided credentials
  4. Confirm successful login
  5. Log out
  6. Confirm successful logout
  7. Close the browser instance

Consider utilizing a data-driven testing approach based on the framework being used. This allows for passing attributes to the test for different scenarios. By using this method, you can run multiple tests in parallel, leading to faster test runs and fewer complications. For instance, if one login fails out of ten in a single browser, you would have to rerun all tests. However, in the parallel approach outlined above, you would only need to investigate and resolve the failed login while the others pass without needing to rerun.

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

Having trouble sending a POST request from my React frontend to the Node.js backend

My node.js portfolio page features a simple contact form that sends emails using the Sendgrid API. The details for the API request are stored in sendgridObj, which is then sent to my server at server.js via a POST request when the contact form is submitted ...

Tips for simulating or monitoring a function call from a separate file

Within my codebase, there is a function that is triggered upon submission. After the payload has been posted, I aim to execute a function located in a distinct file named showResponseMessage: Contact.js import { onValueChangeHandler, showResponseMessage, ...

Cross-platform mobile browsers typically have scrollbars in their scrollable divs

I have successfully implemented scrollable div's on a page designed for tablets running Android 3.2+, BlackBerry Playbook, and iOS5+ (except iPad 1). However, I would like to add scrollbars to improve the user experience. For iOS5, I can use the suppo ...

Storing the array with the highest length in a temporary array using Javascript

I am currently working with two arrays that can be of equal length or one may be longer than the other. My goal is to determine the longest array if they are not equal in length, and then use this length to control a loop. $.ajax({ url: "/static/Dat ...

Conversion of selenium formatting to be compatible with webdriver in Java (Export)

I'm struggling to grasp the concept of how the formatter operates in Selenium IDE. Instead of creating a new formatter from scratch, I aim to edit the current code that converts selenese into webdriver-backed Java. Typically, I would analyze the JavaS ...

Animating SVG elements with the rotation property in SVG.js

Currently, I am utilizing Javascript, Jquery, SVG, and SVG.js in my project. My goal is to rotate a circle around its origin while it's animating. The issue arises when the animation keeps restarting abruptly, causing a jittery motion. Here is the ini ...

Explore the properties within an array of objects through iteration

Here is the array I'm working with: const myArray = [{ id: 1, isSet: true }, { id: 2, isSet: false }, ...]; I only need to iterate over the isSet properties of the objects, ignoring all other properties. Initially, I attempted the following solution ...

The element type provided is not valid: it should be a string for built-in components or a class/function for composite components. However, an object was received instead. - React Native

After conducting extensive research, I have been unable to find a solution as to why this issue persists. Can anyone shed some light on what the error might be referring to? Error: Element type is invalid: expected a string (for built-in components) or a c ...

Can you share a method in javascript that extracts href= and title values, similar to PHP's preg_match_all() function?

I received an HTML string as :var code; I am looking to retrieve all the values of href and title similar to how it is done using PHP's preg_match_all(). I have achieved a similar task in PHP with the provided example but now I am curious about how I ...

Issue with Facebook like button not consistently loading on the website

Getting ready to release my new iOS app that creates customized mp3s and distributes them through a CDN-hosted webpage. Check it out at . I've integrated the XFBML code from http://developers.facebook.com/docs/reference/plugins/like/ because it' ...

Add a new component to a Vue.js instance that is already in use

Just getting started with Vue.js I'm looking to register a local component following the instructions here: https://v2.vuejs.org/v2/guide/components.html#Local-Registration The catch is that I need to register the component to an existing Vue insta ...

Enhancing User Experience with JQuery Pagination and Efficient Data Loading

I am looking to implement pagination for data retrieved from a database. The information needs to be displayed in a 4x4 table format. For the remaining data that doesn't fit in the initial view, I want to enable pagination with AJAX functionality so ...

Is there a way to extract text from tooltips using selenium even if the page does not have tooltip HTML code?

My current challenge involves scraping item details from a webpage using Selenium. Specifically, I am facing difficulties with extracting text from the item tooltip. https://i.sstatic.net/YwKWh.png When inspecting one of the items on the page using devel ...

Selecting a radio button value based on the specified sheet page using Java and Selenium Webdriver

Is there a way to use Java and Selenium Webdriver to read a value from a worksheet and then select the same value in a radio button on a webpage? Workbook workbook = Workbook.getWorkbook(new File("C:/plan.xls")); Sheet sheet = workbook.getSheet ...

Verify user identity before sending directory in Express

I'm encountering an issue with authenticating users before they access an express directory file tree. While I can successfully authenticate users on all other pages, I'm facing difficulties with authentication on "/dat/:file(*)" even though I ha ...

Using the splice method on an array is only effective when done in a specific sequence

I've encountered a small issue. I have checkboxes that correspond to different divs, and when checked, the name of the div is sent to the server. However, when unchecking the checkboxes in a specific order, the array doesn't update correctly. $ ...

Can anyone tell me the location of the PageFactory Class within Selenium?

In my .Net Core 2.2 Test project, I have successfully installed the packages Selenium.WebDriver 3.141.0, Selenium.Support 3.141.0, and Selenium.WebDriver.ChromeDriver 76.0.3809.12600. I intend to implement the Page Object Model pattern, but I am unable t ...

Sharing data between promises in Node.jsExplanation: In Node.js, passing values

Can someone assist with passing an object that I am creating step by step using promises with firebase? I would like to know if there is a more efficient way to construct the object without passing it through the promise chain. Below is the code snippet I ...

Tips for transmitting HTML as a JSON object through the res.render function in expressjs

My issue involves a JavaScript function that returns an HTML element. I want to pass this element along for users to view as actual HTML, but it ends up appearing as a string with special characters like "<" and ">". For example, "<" appears as (& ...

What is the best way to pinpoint a specific Highcharts path element?

I am currently working on drawing paths over a graph, and I am looking to dynamically change their color upon hovering over another element on the page - specifically, a list of data points displayed in a div located on the right side of my webpage. Below ...