"The new Protractor 2.0 version does not seem to be incorporating a wait time for sending keys, leading to

After upgrading to protractor 2.0, I encountered some issues in my project.

An expect() statement fails because the given text is '', it appears that the expect is being executed before sendKeys() is completed.

elem.clear().sendKeys('Message');
expect(elem.getAttribute('value')).toBe('Message');

The error message I receive is:

Expected '' to be 'Message'.

This was working fine prior to updating to protractor 2.0, and I am aware of a change related to then() and promises:

To facilitate the update and reduce confusion, the element().then function has been removed unless there is an action result. This change may lead to compatibility issues. Essentially, an ElementFinder is no longer a promise until an action is performed on it.

In other tests within my project, this works as expected. I suspect that the issue may arise from having the expect statement inside a loop. Below is the full code snippet:

describe('message', function() {
    it('Should fill out visible message fields', function(){
          getDisplayedElements(element.all(by.model('message')))
         .then(function(displayedMessageInputs){
              _.each(displayedMessageInputs, function(elem){
                  elem.clear().sendKeys('Message');
                  expect(elem.getAttribute('value')).toBe('Message');
              });
         });
    });
});

Although using then() functions resolves the issue, I find it less desirable!

elem.clear().sendKeys('Message')
.then(function(){
    return elem.getAttribute('value');
})
.then(function(inputValue){
    expect(inputValue).toBe('Message');
});

Answer №1

The most effective way to handle this situation is by utilizing Promises. They allow for a structured approach to managing asynchronous callback behavior. When dealing with the sendKeys asynchronous callback, it is crucial that the Promise resolves before proceeding. It appears that the function actually returns a Promise, making it practical to leverage its built-in capabilities. To streamline the process and avoid using multiple thens, simply anticipate:

elem.clear().sendKeys('Message')
.then(function(){
    expect(elem.getAttribute('value')).toBe('Message');
});

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

Browsing Identical Groups of Multiple Selection Drop Downs Using Javascript

Is there a way to loop through multiple form elements iteratively in order to identify the selected items from a select multiple input? I am looking for a solution that allows me to determine which selection box is being operated on and then extract all t ...

During post-processing, the elimination of lens flares can sometimes lead to an error known as "copyTexImage2D: framebuffer is

After looking at the lens flares example here: , I'm encountering an issue with post-processing this particular scene. The blocks display correctly, but the light sources and lens flares are missing. Additionally, I am receiving several warnings in t ...

Show image in ReactJS using flask send_file method

Using Flask's send_file function, I send an image to the client in the following way: @app.route('/get-cut-image',methods=["GET"]) def get_cut_img(): response = make_response(send_file(file_path,mimetype='image/png')) respon ...

What is the best way to create dynamic .env files that can easily adapt to different environments instead of

Having multiple .env files (one for Vue and one for Laravel) with 'localhost' hard coded in them is causing accessibility issues from other computers on my network. It would be beneficial to have this set up dynamically, except for production. F ...

How to incorporate text into the white circle object using three.js

View the current state of my project on this JS Fiddle. I am looking to incorporate rotating text, whether in 3D or 2D. The text should rotate in sync with the white circle. I am open to any method that achieves the desired outcome. Below is the provided c ...

File resolution issue with TypeScript

While I am aware that using TypeScript outFile is generally advised against, I currently have no choice but to utilize it until a more suitable solution like AMD can be implemented. It seems like there may be a "module splitting issue" in my project. In t ...

Controller not receiving URL parameter from $location service

I'm attempting to send an ID through a URL parameter to a page called "more.html". The URL parameter will look like this: http://example.com/more.html?id=200 To retrieve the ID from the URL, I utilized the $location service in my controller on the m ...

Show or conceal a child component within a React application

In my React render function, I am working with the following code: <div> <InnerBox> <div>Box 1</div> <HiddenBox /> </InnerBox> <InnerBox> <div>Box 2</div> & ...

Developing unique custom methods in Django REST API for generic views

As an intern, I am currently working on a project that involves developing a DRF API to interact with a mobile app built by my colleague using the Ionic framework. Our task is to create new users, and here is the method in my view: class NewUser(generics. ...

Changes in styling applied via ajax are only supported by Webkit when resizing the browser window

Can you help point me in the right direction? It's been bothering me for quite some time now. In my content editor (using javascript + jquery), I have the ability to change fonts on the fly. Whenever a font is changed in the editor, an ajax request is ...

What is the technical process behind conducting A/B testing at Optimizely?

I'm currently experimenting with Google Analytics and Content Experiments for A/B testing on my website, but I'm encountering some challenges in making it seamless. To utilize the Google API properly, a few steps need to be taken. Firstly, I nee ...

"The transparency of the three-js canvas texture is compromised when using the WebGL renderer, unlike the Canvasrenderer which maintains

I am attempting to display a CircleGeometry over a cube from the camera view. The cube has a solid color, while the circle contains just an arc on a canvas with no background color. When using CanvasRenderer, the transparency of the canvas is retained an ...

Issue with Express.js and EJS application: The edit form fails to display the current category of the post

I've been developing a blogging application using Express, EJS, and MongoDB. You can check out the GitHub repository by clicking on the link. Within my application, I have separate collections for Posts and Post Categories. One issue I'm encoun ...

How can we create the best system by merging Scala-Play and AngularJS for our architecture?

After working in both a pure Scala-Play application and a pure AngularJS application, I have been impressed by both. Now I am curious about the benefits of combining these two frameworks. While they are complementary in some ways, there is also overlap in ...

Node.js server allows for accessing AJAX requests seamlessly

I need to send a parsed AST of JavaScript code to a server for processing, and then receive a list of completions back. However, when I log the AST to the client console before sending it, the structure appears like this: [ { "id":0, "type":"Program", "ch ...

Dealing with recursion issues. What are effective solutions?

Having a small issue with my recursion. I've created a function that checks for matching directions of clicked boxes. const checkMatchingDirections = (board, r, c) => { const top = board[r - 1] !== undefined && { row: r - 1, column: c }; ...

Error: The variable "$this" has not been defined in the AJAX function

Recently, I've been delving into the world of javascript and ajax. I'm trying to create a dynamic select option list similar to this: https://i.sstatic.net/qELIf.png However, when attempting to compile using Google Chrome Developer tools (F12), ...

Invoke a Node.js script from a Spring Boot application to pass a Java object to the script. The script will modify the object and then return it back to the originating class

class Services { Address address = new Address(....); /* Invoke NodeJs script and pass address object In the js script modify address object var address = getAddress() Modify address object Return address obj ...

Start up a server-side JavaScript instance utilizing Express

My journey into web programming has led me to learning JavaScript, Node.js, and Express.js. My ultimate goal is to execute a server-side JavaScript function (specifically a function that searches for something in a MySQL database) when a button is pressed ...

Is there a way for React to detect when a property on an object within an array passed as props undergoes a change in its value?

My goal is to minimize extra work by updating a property within an object in an array of objects called onMouseEnter when hovering over an ApartmentCard that displays information about a specific apartment. The challenge lies in synchronizing the Map that ...