When utilizing $resource, Protractor experiences a timeout while trying to synchronize with the page

Currently, I am testing Protractor with a small AngularJS application.

Here is the test scenario:

describe('Testing Protractor', function() {
  var draftList;

  it('should count the number of drafts', function() {
    browser.get('#/');
    draftList = element.all(by.repeater('newsletter in drafts'));
    expect(draftList.count()).toEqual(2);
  });
});

Controller:

angular.module('myApp.controllers', []).
  controller('DraftsCtrl', ['$scope', 'Draft', function($scope, Draft) {
    $scope.drafts = Draft.query();
}])

Draft service:

angular.module('myApp.services', ['ngResource']).
  factory('Draft', ['$resource',
    function($resource) {
      return $resource('api/drafts/:id')
    }])

When executing this test using Protractor, an error occurs:

Error: Timed out waiting for Protractor to synchronize with the page after 11 seconds

However, changing this line in the controller from:

$scope.drafts = Draft.query();

to:

$scope.drafts = [];

The test fails as expected, but importantly, it no longer times out.

With query() active, data returned by the API displays correctly when viewing the app manually in a browser and through Protractor's browser window.

Why does Protractor struggle to synchronize with the page when the service communicates with the API?

The AngularJS version being used is v1.2.0-rc3, and Protractor is at v0.12.0.

Answer №1

This particular issue has been identified and acknowledged, however there is a temporary solution available. By setting

ptor.ignoreSynchronization = true
, you can work around it.

Here's an example:

describe('Testing Protractor', function() {
  var draftList;
  var ptor;

  beforeEach(function() {
    ptor = protractor.getInstance();
    ptor.ignoreSynchronization = true;
  });

  it('should count the number of drafts', function() {
    ptor.get('#/');
    draftList = element.all(by.repeater('newsletter in drafts'));
    expect(draftList.count()).toEqual(2);
  });
});

Answer №2

Setting browser.ignoreSync to true; solved my issue.

Answer №3

Using Protractor version 3.3.0 has been a bit tricky in my testing scenario. To make it work, I needed to delay the ignore synchronization until after setting up everything.

So, in my beforeEach function, I execute the following action:

var searchBox = element(by.css('#inpt_search'));
searchBox.sendKeys('test');

After that, I have to wait for the mock backend to populate the view. I'm not a fan of using sleep calls, so if you have a better alternative, please share in the comments section. I couldn't get expectedConditions.presenceOf to work due to a bug, as it's related to the same issue. So, I use browser.sleep(500) to handle the waiting period. After this, I set

browser.ignoreSynchronization = true
in the test to unblock any blocked elements and see the browser content.

describe('standard search', function (){
    beforeEach(function (){
        openApp();
        var searchBox = element(by.css('#inpt_search'));
        searchBox.sendKeys('test');
        browser.sleep(500);
    });
    it('should work or something similar', function () {
        browser.ignoreSynchronization = true;
        var fileItems = element.all(by.repeater('item in list'));
        expect(fileItems.count()).toEqual(50);
    });
});

Answer №4

Opt for

browser.waitForAngularEnabled(*boolean*)
over using browser.ignoreSynchronization. By setting
browser.waitForAngularEnabled(false)
, you effectively turn on browser.ignoreSynchronization; conversely, setting
browser.waitForAngularEnabled(true)
will switch off browser.ignoreSynchronization.

You can also incorporate this step into your test suites' configuration file:

onPrepare: function () {
    'use strict';
    browser.waitForAngularEnabled(false);
}

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

Sort firebase information by chronological order based on timestamp

I'm currently working on sorting track IDs from firebase based on their timestamp (createdAt). The function is functioning correctly, but the ordering doesn't seem to work as expected. I'm not sure where the issue lies. Any assistance or sug ...

Unraveling the Mystery of jQuery AJAX Response: Where Have I Gone Astray?

$.ajax({ type: 'POST', url: 'place/add', data: { lat: 45.6789, lng: -123.4567, name: "New Place", address: "123 Main St", phone: "555-1234", review: "Great place!", cat ...

Is it possible to swap the src of the Next.Js Image Component dynamically and incorporate animations in the

Is there a way to change the src of an image in Nextjs by using state and add animations like fadein and fadeout? I currently have it set up to change the image source when hovering over it. const [logoSrc, setLogoSrc] = useState("/logo.png"); <Image ...

Issue with this.setState() not updating value despite not being related to asynchronous updates

Just a quick note, this specific question does not involve any asynchronous update problem (at least, as far as I can tell). I currently have a class component with the following code snippet (simplified for clarity on the main issue): constructor(props ...

The radio button element could not be located using the attribute "checked="Checked""

While working with Geb, I encountered an issue using the code div.find("input","checked":contains("checked")). This is the snippet of code I attempted to use in order to locate the checked radio button on a webpage. However, I received an error when using ...

avoid selecting a d3 table

I'm currently learning about creating tables in D3 and I have a question regarding when to use ".select()": For example, when constructing circles: var circles = svg.selectAll("circle") .data(dataSet) .enter() .append("circle") .att ...

Verifying the absence of query parameters in AngularJS forms

I have been working on a project that involves passing query parameters to the backend for searching purposes. These parameters are passed using the AngularJS $http.get method. Some of these parameters are not mandatory for the search, so I would like th ...

Unable to retrieve button value with material-ui package

My task requires me to retrieve the value of a button, as it contains an ID essential for further steps. Initially, I used a standard button with Bootstrap styling and everything functioned correctly. <button value={row.vacationRequestID} c ...

Arranging data in Ember: sorting an array based on several properties in different directions

Is it possible to sort a collection of Ember Models by multiple properties, where each property can be sorted in different directions? For example, sorting by property a in ascending order and by property b in descending order? Update I attempted to use ...

Issue with pagination not updating when a checkbox is clicked

My goal is to create a filter function, but I am encountering issues with pagination when filtering. Specifically, when I click on the "Mobile Phone" checkbox, it only displays one record on the first page, two records on the second page, and so forth. Add ...

Learn how to increase spacing in React applications

I'm currently utilizing the Grid component from @material-ui to present my data. Within this Grid, I have several nested grids, each representing a different section. I've implemented the container spacing attribute of the Grid and set it to the ...

How to Store Values from a ReadStream in an Array

I'm currently attempting to use a stream and the async/await keywords with the fast-csv library in order to read a CSV file synchronously. Unfortunately, the function I've written doesn't seem to be producing the expected output. My assumpt ...

Italian calendar conversion for the react-multi-date-picker library

I recently integrated the react-multi-date-picker into my project, utilizing the multiple mode feature. However, I encountered an issue when trying to display the Italian calendar based on the language setting. Despite using locale="it", the calendar was n ...

What is the best way to place content in a single div without it being divided into several separate boxes

Here is my code snippet: <div class="col-md-9"> <div id="statbox"> {% for obj in product_type %} {% for obj1 in vastu %} <script type="text/javascript"&g ...

Navigating through the fetch API request when using express js

I'm looking to use the fetch API to send requests and have those requests handled by Express JS. In my setup, I've put together server.js (Express JS), index.html (home page), and signin.html (sign-in page). index.html <!DOCTYPE html> < ...

Learn how to seamlessly transition from a basic HTML Angular page to one with a ui.router template located within a folder using Angular ui.router

On my standard Angular page (index.html) without any ui.router functionality, I need to redirect the flow to a page inside a folder that uses angular-ui.route template after triggering an Angular call by clicking on a link. To better illustrate this scena ...

Guide on creating a menu that remains open continuously through mouse hovering until the user chooses an option from the menu

I have a unique scenario where I am working with two images. When the mouse hovers over each image, two corresponding menu bars appear. However, the issue is that when the mouse moves away from the images, the menu disappears. Any suggestions on how to im ...

There was an error in locating the JavaScript file within the Node.js Express Handlebars application

My website is not displaying the .js file, css file, or image from the public folder. Here are the errors showing up in the console: GET http://localhost:8080/assets/images/burger.jpg 404 (Not Found) GET http://localhost:8080/burgers.js net::ERR_ABORTED ...

Tips for retrieving values from numerous checkboxes sharing the same class using jQuery

Currently, I am struggling with getting the values of all checkboxes that are checked using jquery. My goal is to store these values in an array, but I am encountering difficulties. Can anyone provide me with guidance on how to achieve this? Below is what ...

What is the best way to instruct the protractor to pause until the webpage has completely loaded

My application is taking some time to load the login page, causing Protractor to attempt entering the username before the page fully loads. To resolve this issue, I need to instruct Protractor to wait until the login page is completely loaded. Can you ass ...