Protractor and Jasmine fail to fulfill the promise of retrieving a webpage title

I am facing an issue with my protractor/jasmine test code where it only prints out 1 and 2, then hangs and times out.

It seems like there might be a problem with the click() action on the button element or the promise on the getTitle method of the browser object, or maybe both.

Does anyone have a solution for this or a more efficient way to achieve what I'm trying to do?

Code:

it('should allow successful login', function() {   
    browser.get('http://192.168.0.100/src/');
    browser.waitForAngular();

    var titlePromise = browser.getTitle();
    titlePromise.then(function(text){
      console.log("1**************", text);
    });

    var titlePromise = browser.getTitle();
    titlePromise.then(function(text){
      console.log("2**************", text);
    });

    element.all(by.model('credentials.username')).first().sendKeys('foo');
    element.all(by.model('credentials.password')).first().sendKeys('bar');
    var loginBtn = element.all(by.cssContainingText('.btn', 'Login')).first();
    loginBtn.click();
    browser.sleep(5000);

    var titlePromise = browser.getTitle();
    titlePromise.then(function(text){
      console.log("3**************", text);
    });    
  });
}); 

Error:

Error: Timed out waiting for Protractor to synchronize with the page after 11 seconds. Please see https://github.com/angular/protractor/blob/master/docs/faq.md

Answer №1

While I may not have all the necessary information, here are some suggestions to consider:

  1. Make sure to thoroughly review each scenario that could potentially lead to a timeout as outlined in the documentation linked here. One common issue is Protractor failing to load when $timeout is being used in your Angular application.

  2. Double-check your selection of the loginBtn element to ensure accuracy. You might find it helpful to explore interactive testing options with Protractor following the instructions provided in this link. You can access this feature by navigating to the protractor directory /node_modules/protractor and running the command:

    $ node ./bin/elementexplorer.js

  3. If you encounter issues with logging in and transitioning to another page, try avoiding time-based delays and instead monitor changes dynamically:

    browser.driver.wait(function() {
      return browser.driver.getCurrentUrl().then(function(url) {
        return /logged-in-url/.test(url);
      });
    });

Answer №2

Do not forget that all interaction with the document is done using Promises. Your code should resemble the untested block provided below.

It is worth noting that browser.waitForAngular is not necessary, as "Protractor automatically applies this command before every WebDriver action."

I am unsure why you are calling getTitle so frequently, but I have included it in case it helps clarify the refactoring process.

it('should allow successful login', function() {   
    browser.get('http://192.168.0.100/src/')
    .then(function(){
        return browser.getTitle()
    })
    .then(function(text){
        console.log("1**************", text);
        return browser.getTitle();
    })
    .then(function(text) {
        console.log("2**************", text);
        return browser.getTitle()
    })
    .then(function (text) {
        console.log("3**************", text);
        element.all(by.model('credentials.username')).first().sendKeys('foo');
    })
    .then(function () {
        element.all(by.model('credentials.password')).first().sendKeys('bar');
    })
    .then(function () {
        element.all(by.cssContainingText('.btn', 'Login')).first().click();
    })
    .then(function () {
        browser.sleep(5000); // Consider using ExpectedConditions to wait for something
    })
    .then(function () {
        var titlePromise = browser.getTitle();
        return browser.getTitle()
    })
    .then(function (text) {
        console.log("3**************", text);
    });
});

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

How can I utilize customToJSON in Sails 1.0 within an Action2 function?

Currently, I am facing an issue with my user model that requires the implementation of a customToJSON method to remove the password field from the returned JSON object. Everything works fine when I include "responseType" in the "exits" with a value of "jso ...

The AngularJs project is currently experiencing issues when trying to function as a single page web application

I'm currently working on incorporating AngularJS into an existing web project that uses jQuery. Here is a snippet of my code: <div class="medya" ng-repeat="d in data" masonry-item-dir> <a href="{{d.Url}}" class="onizleme"><img src="{ ...

Is it possible to exclusively target a child div using JavaScript in CSS, without affecting the parent div?

I'm in the process of developing a calendar feature where users can select a specific "day" element to access a dropdown menu for time selection. The functionality is working fine, but I've encountered an issue. When a user selects a time from th ...

How to use image blob in Angular JS?

Working with API endpoints that require authentication for image retrieval. Utilizing a service called authenticatedHttp as an abstraction over $http to manage authentication tokens successfully. Successfully receiving response, converting blob to object ...

The 'else' statement within a for loop modifies the value within an array

Hey there, I have encountered a peculiar issue with the else clause in my conditional statement. It seems to be rewriting the value in the array even when it has already found a match. Any thoughts on why this could be happening? Check out the code snippet ...

transfer to a different outlet when needing to circle back earlier

I'm currently working on implementing validation in a form, and one of the needed validations involves retrieving a value from an input field and checking its existence on the server or in a JSON file. However, there seems to be a problem where even ...

Error: The Stripe webhook payload must be submitted as either a string or a Buffer

I'm currently working on setting up a subscription system using Stripe. I have mostly followed the code from their documentation, but I keep encountering the following error: Webhook signature verification failed. Webhook payload must be provided as a ...

Encountering issues when attempting to insert information into PostgreSql utilizing AngularJs paired with a C# WebService backend

As a beginner in angularjs, I have set up the HTML file and linked it to the RegistrationController.js. Additionally, I have created the Registration.cs file for managing data retrieval and storage from a database. Despite not encountering any errors, I am ...

The protractor tool is unable to recognize an Angular component when it is displayed on the page

I have implemented end-to-end (e2e) testing on my project, but I am facing issues that are causing my tests to fail. Below is a snippet of my app.po.ts file: import { browser, by, element } from 'protractor'; export class AppPage { public b ...

React - Error: Unable to access the 'props' property because it is undefined

I am working on implementing a click event to delete an item from my list, but I keep encountering the error message "TypeError: Cannot read property 'props' of undefined" whenever I click on it. Although I am striving to follow ES6 standards as ...

Utilizing Angular JS to Manage Controller Events

I am currently working on an application that requires saving a large amount of data in cascade, similar to a typical master-detail view. Within this view, there is a "Save All" Button which saves each row in an iteration. This process triggers jQuery cus ...

The function canvas.toDataURL() is not recognized - error originating from a node-webGL wrapper

I am currently working on converting client-side volume rendering code in the browser to server-side rendering using pure JavaScript. On the server side, I am utilizing node-webgl. My objective is to send the server's canvas content to the client so ...

Polymer event / callback for appending new child nodes

My current project involves creating a custom element, let's call it <parent-element>, that performs specific actions based on the presence of its childNodes. When I define the element like this: <parent-element> <div> </div&g ...

JavaScript asynchronous problem

When developing a simple Javascript function to validate user input for City and State, it encounters an issue with asynchronous behavior. The function checks if the user has entered values in the specified input fields and then proceeds to geocode the l ...

Combine a string and integer in JavaScript without using quotation marks between them

Is there a way to concatenate a string and an integer in JavaScript without getting the ": Here is the code snippet: "<agm-map latitude=" + response.latitude + " longitude=" + response.longitude + "></agm-map>"; What it currently results in: ...

Combine PHP, jQuery, and AJAX to retrieve multiple values simultaneously

I have been using jQuery AJAX for my projects. When I make an AJAX call to a PHP page, it normally returns a single value to the success function of AJAX. However, I am now looking to retrieve multiple data individually. How can I achieve this? This is th ...

The AJAX request encountered an error due to an Unexpected End of JSON Input

My AJAX code is encountering an error message. parsererror (index):75 SyntaxError: Unexpected end of JSON input at parse (<anonymous>) at Nb (jquery.min.js:4) at A (jquery.min.js:4) at XMLHttpRequest.<anonymous> (jquery.min.js: ...

Injecting data into a Q promise

I'm facing some issues related to what seems like JavaScript closures. In my Express + Mongoose web application, I am utilizing the Q library for Promises. I have a question regarding passing request data to the promise chain in order to successfully ...

Using an Ajax call within an event handler function

After spending a full day attempting to execute an AJAX call within an event handler function, I've tried various combinations of when(), then(), and done(), as well as setting async: false. However, I keep encountering undefined errors despite my eff ...

Struggling to make the controller karma test pass

I am currently working on developing a "To Do list" using angular js. My goal is to allow users to click on a checkbox to mark tasks as completed after they have been finished. While the functionality works fine in the index.html file, I am struggling to p ...