Verifying that the button remains disabled after being clicked using Protractor for Angular applications

When users click the submission button, it becomes disabled until the operation is complete and they are redirected to the /dashboard page.

We want to ensure this 'disabled while pending' feature is tested in our Protractor end-to-end tests:

it('should disable button after submission', function(){
  page.usernameTextBox.sendKeys(username);
  page.passwordTextBox.sendKeys('password1');
  page.signInButton.click();
  expect(page.signInButton.getAttribute('disabled')).toContain('true');
  expect(browser.getCurrentUrl()).toContain('/dashboard');
});

The assertion on the disabled attribute fails because the next page has already loaded. This is due to Protractor waiting for the operation to be completed before running the assertion - not a race condition. Protractor synchronizes the process so the assertion waits for the operation to finish before executing.

How can we effectively test the above behavior?

Answer №1

Give this a shot: anticipate(page.signInButton.isEnabled().toBe(false));

Answer №2

While this question may seem outdated in the world of web development, I came across it in 2018 and believe others may as well. Thus, I will provide an answer to ensure accurate information.

If your button has a name assigned to it, you can use the following code with the latest version of protractor:

expect(element(by.name('loginButton')).isEnabled()).toBeFalsy();

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

Activate the Select List to Appear Only When a Search is Conducted

Currently, I have implemented the react-select API in order to provide language options for selection. <Select isMulti name="langs" options={langOptions} defaultValue={{ value: "English", label: "English", nativeNam ...

Data update using AJAX and codeigniter was unsuccessful

How can I update my data using Codeigniter and AJAX for submitting the response? Below is the View section of my code: <form id="form_update" action="<?php echo base_url() ?>admin/update_derap_info" method="POST" role="form"> <textare ...

Chat Room with Stable Div Size

I am working on developing a chat feature, but I am facing an issue where the new message does not appear on the screen after a certain number of messages. I want the messages to overflow so that users can scroll down to view them, but only a few messages ...

X/Y Client accessing via Chrome on Android device

I am looking to accurately capture the X and Y coordinates where the user taps on the screen, regardless of zoom or scroll levels. Currently, I am utilizing event.clientX and event.clientY to achieve this, which is working as intended. The code snippet loo ...

Eliminate browser.sleep() from the functions

At the moment, I am in the process of writing end-to-end tests using Protractor for file uploads. I have created methods to add files to a container and then click on the upload button to upload the files. Here are my page object file methods: addCus ...

Unable to utilize ng-Bootstrap datepicker

I recently cloned the quickstart project from the tour of heroes guide on Angular's official website, and I wanted to incorporate the ng-Bootstrap datepicker. However, I encountered some issues with its functionality. Below are the key components of m ...

Invoke JavaScript function upon page load

There is a link on my page that, when clicked, opens a login popup. However, I am struggling to make it work on page load. I have spent a lot of time trying to figure this out, but nothing seems to be working. <a id="onestepcheckout-login-link" href=" ...

Display the JSON outcome with console.logging

As I delve into the world of APIs, JSON, and JQuery, I've encountered a roadblock. How can I retrieve the following information, "name: The Old Mill Cafe," and log it to the console from my JQuery call? Below is my current code snippet: $(document). ...

Error: Custom Service is behaving unpredictably

My latest project involves creating a customized service. While the service function is returning data as expected, I encounter an issue when calling it in the controller - it returns 'undefined'. Service: var toDoListServices = angular.module( ...

Guide to extracting a specific value from a JSON object with JavaScript

When working with JavaScript and fetching data from an API, the structure of the data retrieved may look something like this: [{ "word":"gentleman", "score":42722, "tags":["syn","n"] }, { "word":"serviceman", "score":38277, "tags":[ ...

Is it possible to invoke a Java Script function from a GridView using `<% Eval("") %>` as a parameter for the function?

Is there a way to call a javascript function with a single parameter from a link click within the GridView Control? I need to pass the value of the parameter using <%Eval("myfield")%>. How can this be accomplished? <ItemTemplate> ...

Using jQuery, transform JSON into an array

After running my PHP code, I have the following result: $result = '[{"MFG_NAME":"ABC","CONCATED_MKT_SHARE":"01-MAR-14|0.59"},{"MFG_NAME":"XYZ","CONCATED_MKT_SHARE":"01-MAR-14|0.87"},{"MFG_NAME":"ABC","CONCATED_MKT_SHARE":"01-APR-14|0.25"},{"MFG_ ...

What is the method for deactivating a form input field in Angular Formly?

Is there a specific way to disable a form input field using Angular Formly? I have tried searching online and cannot find a clear answer. Even after checking Formly's 'field configuration docs', I only found one mention of the word 'dis ...

Struggling to traverse through intricate layers of nested objects in React and showcasing them without going crazy

Dealing with an API that returns data structured in deeply nested objects has been a challenging task. The goal is to extract specific data from these nested objects and then display them within a React project. Despite numerous attempts, finding a simple ...

Running tests in jest with or without mocks depending on the condition

Currently, I am performing tests using mocks to avoid always hitting APIs. Nevertheless, I also aim to introduce a condition that would allow me to utilize the same test for API testing purposes. However, when I include a condition, it seems to be disrega ...

What causes the $injector to be empty while utilizing UpgradeComponent?

I am currently attempting to transition from using Angular 1 to Angular 2 by bootstrapping a hybrid setup that incorporates both ng1 and ng2. You can find the code for my project here: https://plnkr.co/edit/3jrnPyVc8WN2a4crUJF?p=preview Upon running this ...

Dynamically incorporating parameters into a function without any limitations

Is there a way to dynamically pass multiple arrays as function parameters and then store their values into a single array? I already know how to accomplish the second part, as shown below: function arrayfunction(/*arrays go here*/) { var allArrays = [] ...

Changing the css value using jquery is ineffective

When clicking the 'Design Custom Cables & Order Online' button, I aim to have the step 1 accordion content collapse and instantly expand the step 2 content. However, upon applying jQuery, the step 2 content does not expand immediately and the ste ...

AngularJS provides a way to create isolated scope for individual items within a list

I am using ng-repeat to populate a list of items. <ul> <li ng-repeat="item in items" ng-class="setClass" ng-click="assignClass()">{{item.name}}</li> </ul> In my controller, I have the following code: $scope.assignClass = func ...

What could be the reason for Angular to merge the element at index 0 of an array into a subarray instead of doing

After setting up the Array in my oninit function, I encountered an issue where one part of the array was functioning as intended while the other returned an error. this.tests = [{ status: 0, testresults: [{ name: 'test ...