Using `delay` in rxjs causes Protractor end-to-end tests to exceed the time limit

After running ng e2e on my application, I encountered the following error:

Failed: Timed out waiting for asynchronous Angular tasks to finish after 11 seconds.

Inspecting the app.component.ts, it is evident that 'app' is published 15 seconds after subscription.

My understanding is that Protractor waits for all pending asynchronous tasks in the Angular application to complete. Further details are discussed below.

import { Component } from '@angular/core';
import * as Rxjs from 'rxjs';
import * as Operators from 'rxjs/operators';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title: Rxjs.Observable<string>;

  constructor() {
    this.title = Rxjs.of('app').pipe(
      Operators.delay(15000)
    );
  }
}

The change in app.component.html is as follows:

Welcome to {{ title | async }}!

All other components remain unchanged, with only the specified modifications.

While this example is trivial, my actual code serves a functional purpose. I require the ability to have Observables that may not emit values for extended periods of time (e.g., months).

Is there a way to utilize rxjs's delay operator in a manner that prevents timeout in end-to-end tests?

Alternatively, is there a method to indicate to Protractor that it does not need to wait on a specific Observable?

Methods I have attempted:

browser.waitForAngularEnabled(false)

While this temporarily resolves the waiting issue, it complicates matters since the application is Angular-based.

ngZone.runOutsideAngular(() => {...})

This approach is ineffective as the prolonged operation is part of a view binding ({{ title | async }}), making it unsuitable for calling ngZone.runOutsideAngular.

Answer №1

Protractor aims to align itself with Angular, such as when handling $http calls to ensure the Application Under Test (AUT) is stable for testing purposes.

To prevent Protractor from performing synchronization, you can utilize

browser.ignoreSynchronisation = true
at the beginning of your tests, either within the config.js file or within the describe block.

Answer №2

Although I may be late to the party, I encountered a similar issue while using rxjs 6 with angular 8.

What worked for me was switching from delay to timer, like so:

of(true).pipe(delay(1000)); 

resulted in a protractor timeout, but changing it to

of(true).pipe(switchMap(() => timer(1000))

resolved the issue. I'm not sure why, but now I don't have to explicitly instruct protractor to not wait for angular, especially when making multiple http requests. This approach achieves the same result, disregarding the passed value.

browser.waitForAngularEnabled(false)

is unnecessary in this case. This is more of a workaround as I would have preferred to stick with delay without having to rewrite all my e2e tests for this behavior.

Answer №3

I encountered a similar issue while working with the rxjs timer. My Protractor tests kept throwing "ScriptTimeoutError: script timeout" exceptions consistently. To resolve this issue, I found success by utilizing the native Selenium WebDriver API on the pages that included the timer. Here's an example:

Instead of:

await element(by.id('question-12' )).click();

I opted for using the Selenium WebDriver:

import {By} from "selenium-webdriver";
//...
await browser.driver.findElement(By.id('question-12' )).click();

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

Modify the System.config() in Angular 2 following the segregation of JavaScript and TypeScript files

My project follows the folder structure of quick-start ToH, which can be found at https://angular.io/docs/ts/latest/tutorial/toh-pt1.html In order to separate the .ts and .js files, I included the following line in the tsconfig.json file: "outDir": "dist" ...

What is the reason behind receiving the error message "Unable to resolve all parameters for ApplicationModule"?

I am experiencing an issue with my Angular app as it is not working properly in CodeSandbox. The error message I receive is: Can't resolve all parameters for ApplicationModule evaluate main.ts:11:25 8 | enableProdMode(); 9 | } 1 ...

Leverage custom attributes for user input in Ionic 2

Trying to incorporate custom attributes into inputs and divs has been a challenge for me. At first, when I hardcoded the data like this: <input type="hidden" class="test" value="0" custom-data='12345' /> everything worked perfectly. Howev ...

Accessing properties using bracket notation in Typescript is a powerful feature that

I wish to retrieve a typed object using bracket notation like this: interface IFoo { bar: string[]; } var obj: IFoo = { bar: ["a", "b"] } var name = "bar"; obj[name]. // type information lost after dot As per the specification 4.10, it seems to be t ...

Transferring information to a navigated module using Angular2

I am currently facing a scenario where I have a component being loaded via routing, and my goal is to pass data from the parent component into this child component. How exactly can I achieve this task effectively? Parent Component Class export class Home ...

Vue Basic Components 'T' has not been declared

After updating to Vue 3.4.30, I encountered an issue while trying to use Generic components. When attempting to use T as a type for a property, I received an error message. Any guidance or suggestions on how to resolve this would be greatly appreciated. I ...

Developing a firestore query using typescript on a conditional basis

I've encountered an issue while attempting to create a Firestore query conditionally. It seems like there's a TypeScript error popping up, but I can't seem to figure out what's causing it. Here's the snippet of my code: const fetch ...

The error message "Undefined error in Angular 8 when waiting for API call to finish" appears when

if(this.datashare.selectedtableId!=null) { console.log( "inside if condition"); let resp= this.http.get(this.global.apiUrl+"columns/"+this.datashare.selectedtableId); resp.subscribe((data)=>this.users=data); conso ...

Encountering a Typescript error while attempting to convert a JavaScript file to Typescript within an Express

After deciding to transition my express.js code to typescript, I have encountered an issue with my user model. Below is a simplified version of the code: //user.model.ts import { Schema, Types } from 'mongoose'; export interface User { na ...

What is the most effective way to retrieve data from a URL and process it using reactjs?

Looking to consume JSON data from a URL, here is an example of the JSON structure: { "results": [ ... ], "info": { ... } } I aim to display the fetched data as a component property. What is the most efficient way to achie ...

Is there a way to utilize multiple HTML templates with the same TypeScript file?

Is it possible to use different HTML templates for the same TypeScript file, based on an expression in the constructor? I am looking for something like this: <div class="container-fluid"> <app-teste1 *ngIf="teste == '1'> & ...

Improving Performance with Reusing Selectors in Ngxs

Working with Angular using the container/presentation pattern and Ngxs presents a challenge for me. The issue I am facing is that I have one container component nested within another container component, both calling the same @Select: @Select(State.example ...

IE11 triggers DatePicker to display as NaN when changing the year

When attempting to manually adjust the year value in the input field rather than utilizing the popup, the datepicker switches the value to "NaN/NaN/NaN". This issue appears to be specific to IE11 as it works correctly in Chrome. ...

Using Vue and TypeScript to define components

Whenever I attempt to install vue-class-component, vue-class-component, or vue-property-decorator, I encounter the following error message: npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! While resolving: <a ...

How to Apply a CSS Class to the Body Tag in Angular 2.x

How can I add [class.fixed]="isFixed" to the body tag when Angular 2.x is bootstrapped inside the body (outside my-app)? <html> <head> </head> <body [class.fixed]="isFixed"> <my-app>Loading...</my-app> </body> & ...

How to Generate a JPG File from a Leaflet Map in Angular 4 using Typescript

I am developing a custom application using Angular4 that involves integrating leaflet maps. One of the requirements is to export the current view of a map as a JPG image, capturing only the map with markers and polylines - similar to taking a screenshot. ...

Angular 14: Deleting an item from a FormArray triggers unintended form submission due to Angular animation

After beginning to create animations for my app, I observed that deleting an element from a FormArray triggers a form submission. Custom form controls were developed using ControlValueAccessor, and certain FormGroups are passed through @Inputs. The animati ...

Running terminal commands in typescript

Can Typescript be used to run commands similar to JavaScript using the Shelljs Library? ...

Determine the full location information with the help of Google Maps SDK without the need

My current challenge involves dealing with a list of unformatted and incorrectly written addresses. I am seeking a way to iterate through these flawed strings and generate more organized and accurate addresses using one of the many Google Maps SDKs availa ...

Request with missing authentication header in Swagger OpenAPI 3.0

When generating the swagger.json using tsoa for TypeScript, I encountered an issue. Even after adding an access token to the authorize menu in Swagger and making a request to one of my endpoints, the x-access-token header is missing from the request. What ...