Is it possible to globally delay the execution of WebElement.sendKeys() in Protractor's onPrepare function?

While running protractor on a sluggish machine, I am in need of slowing down each key press and action performed. The action part has been successfully implemented, but how can I achieve the same for key presses?

I have come up with a local solution which is as follows:

function delay(el, value, newDelay) {
    for (var i = 0; i < value.length; i++) {
        browser.sleep(newDelay || browser.params.delay);
        el.sendKeys(value[i]);
    }
}

In my onPrepare function, I managed to slow down each action using the following code:

browser.driver.controlFlow().execute = function () {
    var args = arguments;

    if (arguments[1] === "WebElement.sendKeys()")
        debugger;

    origFn.call(browser.driver.controlFlow(), function () {
        return protractor.promise.delayed(100);
    });

    return origFn.apply(browser.driver.controlFlow(), args);
};

However, I am unsure about how to slow down the sendKeys function. I believe I need to make some modifications where I placed the debugger, but what exactly needs to be done?

Answer №1

After much trial and error, I finally came across a solution that worked for me. It involved sending the entire string first, and if that failed, sending the keys individually and checking again. The code snippet below illustrates this approach:

el.getAttribute('value').then(function (insertedValue) {
    if (insertedValue !== value) {
        el.clear().then(function () {
            el.sendKeys(protractor.Key.END);
            for (var i = 0; i < value.length; i++) {
                browser.sleep(100);
                el.sendKeys(value[i]);
                el.sendKeys(protractor.Key.END);
            }
            if (tryNo < 1) {
                el.getAttribute('value').then(function (insertedValue) {
                    if (insertedValue !== value) {
                        // Handle the situation where the inserted value is still not as expected
                    }
                });
            }
        });
    }
});

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

Add a fading transition feature to images that are loaded at a later time

I used a clever technique to create a blur effect by loading a small, lightweight image first. Once the main background image is loaded, it swaps out the 'data-src' with the actual image. However, I am facing an issue with the abrupt transition, ...

Navigate to the initial visible element on the specified webpage via the page hash link

In my handlebars HTML template, I have a partial view that includes different pieces of content for desktop and mobile. I use different CSS classes to hide and show these elements accordingly. <div class='hideOnMobile showOnDesktop'> < ...

The effectiveness of a promise chain is consistent, even when the return statement is subject to conditions

After reorganizing this sequence, I am perplexed at how it continues to function regardless of a conditional return statement in one of the .then sections: function addList(name) { let listObj = {}; listObj.name = name; return nameExists(name) //returns a ...

The Axios GET method retrieves a response in the form of a string that represents an object

I have developed a function that triggers an axios Request. I am working with typescript and I am avoiding the use of any for defining return data types of both the function and the axios request itself. The issue arises when the returned object contains ...

The IIS URL rewrite is causing issues with the rewriting of CSS and JS files

Struggling with my URL rewrites - every time I set up a rewrite for a page, it ends up affecting the CSS and JS files linked within the webpage, resulting in them not displaying properly. In an attempt to fix this issue, I tried using fully qualified path ...

What are the proper methods for accurately testing vuex state and mutations?

Can someone guide me on how to properly test mutations and state? I have a modal window component that is rendered when the showModal property in the state is true. There is an event triggering a mutation that changes this property. How can I verify that a ...

Exploring Angular14: A guide to efficiently looping through the controls of strictly typed FormGroups

Currently, I am working on upgrading my formGroups to be strictly typed in Angular v14. Within my FormGroup, there is a specific block of logic that iterates through all the controls and performs an action (this part is not crucial as I am facing issues be ...

Attempting to transfer a newly created element from one location to another within the document after it has finished

I'm currently updating the design of my website. The currency selector app by Shopify is placed at the bottom, which has caused confusion for my international customers. To resolve this issue, I want to move it to a specific div class called .CSPositi ...

Mockgoose encountered an error during shutdown: ENOTCONN

It's making me lose my mind. I'm currently executing some unit tests with the following configuration import mongoose from "mongoose"; import mockgoose from "mockgoose"; import chai from "chai"; import chaiAsPromised from "chai-as-promised"; i ...

Using Selenium to locate and interact with multiple elements by combining WebDriverWait with a for loop

Encountering issues with Selenium while attempting to locate elements and using WebDriverWait: WebDriverWait(browser, 5).until( EC.presence_of_element_located((By.XPATH, "//*[contains(text(), 'Hello')]"))) ...

Patiently anticipating the completion of a jQuery animation

I am currently working on some jQuery code that handles toggling containers and buttons. The specific snippet of code I am focused on is the following: var id = $(this).data('id'); if ($('#container').is(':visible')) { $( ...

Remove the class upon clicking

I recently created a toggle-menu for my website that includes some cool effects on the hamburger menu icon. The issue I am facing is that I added a JavaScript function to add a "close" class when clicking on the menu icon, transforming it into an "X". Whil ...

Refresh Browser with Angular UI State Parameters

I'm seeking assistance on an issue I've encountered while using angularjs 1.5.5 and angular-ui-router 0.4.2. Specifically, when refreshing the browser, I face a problem that seems to be implementation-specific. Below is a sample code snippet of ...

I'm experiencing an issue where Angular Directives are not rendering properly when fetched from a JSON

I've been working on creating a front end that pulls content from a WordPress CMS. I've successfully used the WP REST API plugin to retrieve JSON data from my WordPress site and display the HTML content using 'ng-bind-html'. However, I ...

The NextJs router encountered an unknown key passed through the urlObject during the push operation

I have a Next.js/React application where I am utilizing the Next Router to include some queries in my URL. However, when using the following function, the Chrome Dev Console displays numerous warnings: const putTargetsToQueryParams = (targets: IFragrance ...

What are some ways to defer the loading of JavaScript files until after AngularJS has finished populating directives?

Currently, I am facing an issue with animation libraries that are being loaded at the end of the page. They do not seem to bind properly to the HTML content generated by directives. Is there a method to ensure that the scripts are loaded after the view ha ...

The error message "Uncaught TypeError: Cannot read property '0' of undefined" is triggered when using toDataURL

Recently diving into the world of JavaScript and facing a perplexing error. I must be overlooking some fundamental concept... apologies in advance. Here is the issue at hand. In my HTML file, this snippet of code is present: <div> <script type= ...

What are the steps to successfully install OpenCV (javascript edition) on Internet Explorer 11?

I'm currently experiencing issues with getting the OpenCV javascript version to function properly on IE11 for contour detection. While my code runs smoothly on all other up-to-date browsers, I am encountering errors such as: TypeError: Object doesn&a ...

Looking for guidance on restructuring a JSON object?

As I prepare to restructure a vast amount of JSON Object data for an upcoming summer class assignment, I am faced with the challenge of converting it into a more suitable format. Unfortunately, the current state of the data does not align with my requireme ...

Troubleshooting: Unable to create records in MongoDB using MEAN Stack

I am currently in the process of developing a MEAN stack application. My main objective at this point is to create a record in MongoDB from a form, but I seem to be encountering some issues. The data binding between the view and the controller appears to b ...