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

What is the best way to use JavaScript to emphasize the searched text in a textbox?

My application uses JavaScript and I am looking to both highlight the search element and keep the cursor in the textbox positioned at the search item. Can anyone suggest a way to accomplish this using JavaScript? ...

Issue with Jasmine Unit Test for Function not within Class

I encountered a challenge while attempting to test a static function located outside of the "export class LogoManager" in the logo-manager.component.ts file. export class LogoManagerComponent implements OnInit { ... } function dataURLtoFile(dataurl, filen ...

Where am I going wrong in my attempts to use a callback function?

I am currently attempting to implement a callback function for this particular JavaScript function. function Filtering_GetSite(siteElement) { $.ajax({ type: "POST", url: "samle.asmx/f1", data: "", contentType: "application/json; charset= ...

Tips on sending an array to material-ui dataSource props

Currently utilizing material-ui for a component. I am facing an issue with the autocomplete component in material-ui where I intend to display a list of icon names along with the icons. When only passing MenuItem to dataSource, it results in an empty input ...

Is it possible to retrieve the complete file path in a form?

My goal is to retrieve a file using an input element of type "file". This element is located within a partial view, and I need to send it to the controller or request it there using "Request.Form["inputFile"];". However, this method only provides me with t ...

What could be causing the discrepancy in the first and second socket request in my Node.js code?

Below is my echo server code snippet var net = require('net') var server = net.createServer(function(socket) { socket.write('Echo server\r\n'); socket.on(&ap ...

How can complex POST parameters be structured in a RESTful API?

For my current project, I am working on developing an application utilizing node.js along with express. This application involves a feature that allows users to subscribe to lists of items. Each subscription includes specific options such as minimum scores ...

"Encountering issues with AngularJS when attempting to send data through $http.post

I am currently working on an angular app where I need to post elements into a database. To achieve this, I have set up a modal that allows me to select courses which will then be posted using the $http.post method. Below is the function responsible for pos ...

Choose an element from within a variable that holds HTML code

I have a specific div element that I need to select and transfer to a new HTML file in order to convert it into a PDF. The issue I'm facing is related to using AJAX in my code, which includes various tabs as part of a management system. Just to prov ...

Interdependent function calls between two functions

When faced with the task of recursively checking two objects with sorted keys, I came up with a solution involving two functions. buildObj - this function retrieves all unique keys from the objects, sorts them, and then calls buildObjKey for each key bui ...

Redirecting CORS in Cordova: A Comprehensive Guide

My Cordova/Phonegap app is encountering an issue while trying to retrieve certain files using AJAX. The specific error message that I receive states: XMLHttpRequest cannot load https://docs.google.com/uc?export=open&id=.... Redirect from 'https ...

Organize an array based on its ratio

I am attempting to organize an array based on the win and lose ratio of each player. This is how my code currently looks: const array = [{playerName: 'toto', win: 2, lose: 2}, {playerName: 'titi', win: 0, lose: 0}, {playerName: &apo ...

Is there a possibility of Node.js being blocked during the processing of large file uploads?

Is it possible for Node.js to become blocked during the processing of large file uploads? Due to Node.js having only one thread, is there a risk that other requests will be blocked while handling large file uploads? If this is the case, what is the best ...

A guide to efficiently managing updates and inserts with bulkCreate in node.js

Currently, I am utilizing node.js to facilitate the uploading of an excel file into a database. Furthermore, in my service, I am employing bulkCreate to efficiently upload the data into the mysql db. In order to provide more context, I will outline the str ...

What is the best way to utilize the `Headers` iterator within a web browser?

Currently, I am attempting to utilize the Headers iterator as per the guidelines outlined in the Iterator documentation. let done = false while ( ! done ) { let result = headers.entries() if ( result.value ) { console.log(`yaay`) } ...

JavaScript's ability to show and hide div elements functions properly in Internet Explorer, but is encountering issues in Firefox and Chrome

I have a total of 20 spans with unique IDs, all set to hidden in my stylesheet. To toggle the visibility of these spans upon clicking on sections of an image map, I created this script: function showDiv(pass) { var divs = document.getElementsByTagName ...

Utilizing KnockoutJS to Apply CSS Binding Based on Dropdown Selection

Check out the live example here: http://jsfiddle.net/0gmbbv5w/ In my application, I have an object retrieved from the database that I bind to a <select> var NoticeType = function (noticeType) { this.NoticeTypeId = ko.observable(noticeType.Notic ...

The TinyMCE editor's input box lost focus while on a popup dialog

Whenever I attempt to access the TinyMCE editor in a dialog box popup and click on "Insert link", the "Insert link" dialog box pops up but I can't type anything into the text field. I suspect that the issue may stem from having a dialog box open with ...

Tips for determining if a key is present in local storage:

I need to set a key value, but only if it doesn't already exist. In my component1.ts file, I am assigning the key and value in the constructor. However, I want to include a condition that this action should only be taken if the key is not already pre ...

Guide to creating a parallax scrolling effect with a background image

My frustration levels have hit an all-time high after spending days attempting to troubleshoot why parallax scrolling isn't functioning for a single image on a website I'm developing. To give you some context, here's the code I've been ...