Warning: Obsolete Warning: Unresolved promise rejections are no longer supported. - Exploring Javascript Promises with Selenium

I recently encountered an issue while setting up test cases with Selenium in Javascript for a basic login page test. I am currently working on implementing proper error handling by rejecting within a Promise. Here is the code snippet in question:

//Test Case 1: Valid Email / Valid Password
async function tc1() {
    announceTC();
    //Creating a promise to handle the asynchronous test case execution
    let promise = new Promise(async function (resolve, reject) {
        //Setting up the webdriver (Chrome) and navigating to the test page
        const driver = createDriver();

        //Entering a valid email and password
        await validEmail(driver, reject);
        await validPassword(driver);

        //Simulating a click on the login button
        await clickLoginButton(driver);

        //Verifying a successful login
        await testSuccessfulLogin(driver, resolve, reject);

        //Closing the driver instance
        await driver.quit();

        //Triggering callback functions
        promise
            .then(value => console.log(value),
                value => console.log(value))
            .catch(value => console.log(value))
            .finally(() => tc2());
    });
};

While working on the validEmail function, I came across an issue where I need to reject if an error occurs. Here is how I handled it:

//Locate and input valid email on the login page
async function validEmail(driver, reject) {
    try{
        //Locating the email input box
        let emailBox = await driver.wait(until.elementLocated(By.xpath("//*[@id='email']/iput")), 5000);
        await emailBox.click();

        //Inputting the email address
        driver.findElement(By.xpath("//*[@id='email']/input")).sendKeys("<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a0d2c5c4c1c3d4c5c4e0c7cdc1c9cc8ec3cfcd">[email protected]</a>");
    } catch(error) {
        console.log(error);
        reject(tcErrorMsg());
    }
}

From my understanding, this error arises when there's no catch statement in the promise to address a rejected case.

Oddly enough, my testSuccessfulLogin function utilizing resolve works fine with .then, but encountering an unhandled rejection error when using reject in a similar manner has left me puzzled.

Answer №1

The code snippet below needs to be relocated outside of the asynchronous function.

 //Execute the callback functions
        promise
            .then(result => console.log(result),
                result => console.log(result))
            .catch(error => console.log(error))
            .finally(() => finalize());

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

Tips for implementing the .nex() property from jQuery in CSS styling

When I add the class "playing", then I will apply custom CSS to the next li tag. Please review my code and see if you understand. Please take a look at my code. <ul> <li class="playing">li (sibling)</li> <li id="head">li ...

Executing a POST request with AJAX in jQuery to communicate across different domains and fetching XML data as

Is it possible to send an AJAX request using the POST method and receive XML as a response text? If so, please provide me with the steps to achieve this. For example: url : "http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate" data ...

Exploring the angular js repeater component's context menu options

In one of my current projects, the client has specifically requested a right-click menu feature. However, the challenge lies in ensuring that the function triggered by the menu options has access to relevant information from the model. For instance, you ...

Error: The `Field` component encountered a failed prop type validation due to an invalid prop `component` after upgrading to MUI version

Encountered an error when migrating to Material ui v4 Failed prop type: Invalid prop component supplied to Field. in Field (created by TextField) This error points to the redux form field component export const TextField = props => ( <Field ...

Observing the evolution of Vue with Observable notifications

I'm currently working on creating a method to verify a user's login status using firebase's firebase.auth().onAuthStateChanged(). My intention is to make this functionality accessible throughout my app as a global variable. Presently, I am ...

AngularJS is unable to find the controller specified

Whenever I attempt to launch my application, I encounter this particular error. An issue arises where 'CampaignsSettingsController' is not recognized as a function and is instead undefined. The controller in question is outlined below: // Exec ...

Displaying data from a SQL database using PHP in a JavaScript environment

Currently, I am facing an issue with JavaScript while working on an event booking application. The front end utilizes JavaScript to collect data, which is then inserted into the database using PHP. However, I am encountering a problem where I am unable to ...

Using a static value in the comparator is necessary for Array.find to function properly in Typescript

Looking to retrieve an item from an array: const device = this.selectedDevtype.devices.find(item => console.log(this.deviceID); return item.device_id === this.deviceID; }); console.log(device); When this.deviceID is logged, it shows "4", but t ...

Inspecting log files using WebDriver to identify potential error exceptions

My current requirement is as follows: - When my @Test method runs, I need to check the log files. - If there are any exceptions in the log files, the test case should fail. Otherwise, it should pass. Currently, I have implemented the follo ...

Place an element that exceeds 100% in size at the center

How can I center an image that is larger than its parent element? I have set the min-width and min-height to 100% so that the picture will always fill up the parent element. The issue arises when the image does not match the proportions of the parent elem ...

What is the best way to handle resolving a promise nested within another promise and retrieving the result within a controller?

I have a situation where I need to modify the result of a promise returned by a function in one service and make this altered value accessible to my controllers from another service. angular.module('test').service("service1", function($q) { ...

Using Python Selenium to create multiple loops within a single range statement

Can someone assist me with creating multiple loops in one statement like this: for a,b,c in range(1,501): ........code **TypeError: cannot unpack non-iterable int object** ...

Difficulties arising from Bootstrap menu causing interference with dropdowns

I am facing a problem with the two navigation menus on my website. Both menus are of the same type and are built using Bootstrap. The first navigation menu uses the “navbar-inverse” class, while the second one uses the “navbar-default” class with s ...

Steps for adding an item to the datasource in a Kendo UI Combobox manually

I am facing an issue with a combobox that is being populated using a JSON string received from a servlet. $(document).ready(function() { //Combobox Init (From Servlet) var comboBoxDataSource = new kendo.data.DataSource({ transport : { ...

Node.js can be used to easily set the values of HTML elements

After successfully setting up a node.js connection to my mysql database and being able to retrieve and input data using connection.query(), I now want to display the database information on my HTML elements. Is there an equivalent of getElementById for t ...

Implementing Checkbox Functionality within a Dropdown Menu using AngularJS or JavaScript

I am interested in finding a multi-select checkbox solution similar to the one demonstrated here: Instead of using jQuery, I would prefer options in AngularJS or pure JavaScript. Does such a solution already exist in these frameworks, or is there guidance ...

Encountering a problem when trying to assign a value to a file/image input field using Vue Formulate

Having trouble setting the initial value for the image input field? The documentation suggests providing an array of objects with URLs (link to docs). I've followed the same format for other fields like 'text' and 'email', which w ...

An error is thrown when trying to retrieve Objects: Uncaught TypeError - Object function ParsePromise()

By obtaining a Document object with its id, the following code proceeds to locate corresponding sections based on the object. The document identifies a Parse object and document.toJSON converts this into a Javascript object. Furthermore, sections represent ...

Do you think it's essential to utilize express for node in developing moderate-sized applications?

What is the best approach for handling cookies and authentication in a project with approximately 30 or 40 routes? Is it feasible to manage cookies and authentication without using Express? What percentage of developers prefer using Express over bare bon ...

Dim the background for all elements except for one

Seeking a way to create a dimmed-background effect by adjusting the opacity of all elements on the page except for one specific element. I've experimented with using the :not() selector as well as jQuery selectors to exclude certain elements, but have ...