Issue encountered when attempting to chain promises with async/await functionality

Here is my current code snippet:

await enterName();
await enterCity();
await submit();

async enterName() {
element.sendKeys('name');
}
async submit() {
element.submit();
waitForAngular();
}

The problem I am facing is that when calling the submit function asynchronously, it fails to make any network calls. I attempted using controlFlow, but it only seems to work if I fetch the URL right before submitting.

protractor.promise.controlFlow.execute( driver.get(url));
        await submit();
----------> this solves the issue!

However, my requirement is to first open the URL, fill out the form, and then initiate the asynchronous submit call. Is there anyone who can assist with this?

Answer №1

It is important to remember to await all functions that return promises, even those from protractor:

class y {
    element = element(".test");
    async fillOutForm() {
        await this.element.sendKeys('name');
    }

    async saveData() {
        return Promise.resolve();
    }

    async waitForPageLoad() {
        return Promise.resolve();
    }
    async finalizeSubmission() {
        await this.element.submit();
        await this.waitForPageLoad();  // Making sure this is also asynchronous.
    }

    async performTest() {
        await this.fillOutForm();
        await this.saveData();
        await this.finalizeSubmission();
    }
}

Answer №2

  1. To effectively use `async/await`, it is imperative to turn off Control Flow.
  2. A function must be declared as `async` if it contains a promise that needs to be handled using `await`.

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 transform HTML into a PDF using Angular 2?

Is there a way to convert a dynamically generated HTML table into a PDF and also have the ability to print it using Angular 2 and Typescript? ...

Tips for merging individual Koa-Routers using Typescript

My approach to organizing routers in my project involved categorizing them based on their purpose. Here's how they are structured: routers/homeRouter.ts import * as Router from 'koa-router'; const router: Router = new Router(); router ...

Is there a way to utilize an Event Emitter to invoke a function that produces a result, and pause until the answer is provided before continuing?

Looking for a way to emit an event from a child component that triggers a function in the parent component, but with a need to wait for a response before continuing. Child @Output() callParentFunction = new EventEmitter<any>(); ... this.callParen ...

Guide on how to show the index value of an array on the console in Angular 2

Is there a way to show the array index value in the console window upon clicking the button inside the carousel component? The console seems to be displaying the index value twice and then redirecting back to the first array index value. Can we make it so ...

An error occurs when attempting to access a property that does not exist on type 'never'. Why is this considered an error rather than a warning?

I am experiencing an issue with the following code snippet: let count: number | undefined | null = 10; count = null; let result: string | undefined | null = count?.toFixed(2); console.log(`Result: ${result}`); The error message I received is as follows: ...

How should testable functions be exported in Typescript through an effective class design?

In my software, I have developed a couple of stateless classes that handle business logic and return computed values. These classes naturally depend on other classes in the system. As I consider the best design approach, I have been contemplating two opti ...

Having Trouble with React, TypeScript, and MUI Tabs? Dealing with Overload Errors?

Currently, I'm in the process of building a component using MUI Tabs. Here's a snippet of my code: <Box> <Tabs value={value} onChange={handleChange} variant='fullWidth'> {RoomTabs.map((tab, index) => ( ...

React form submissions are not saving the state

I currently have dynamic components rendered from the server side, including a submit button component. The issue I am facing is that when I submit the form, the state reverts to its initial values instead of retaining the updated values set by child compo ...

Ways to fetch data based on a specific relationship criterion

In my data structure, there is a Product entity and an Image entity with a OneToMany relationship. This means that One Product can have many Images attached to it. When an image needs to be removed, instead of deleting the data from the table, I have chos ...

Retrieve a prepared response from a TypeORM query

I need to retrieve all the courses assigned to a user with a simple query: There are 2 Tables: students & courses return await this.studentsRepository .createQueryBuilder('s') .leftJoinAndSelect('courses', 'c' ...

Utilizing a string variable as a property name for dynamic typing

I am looking to dynamically create a type with a property name based on specified parameters. Although I can successfully create the object, I am facing challenges when trying to create the actual type. This dynamic type creation is essential for compositi ...

The performance of linting has significantly decreased following the upgrade of nx/angular, particularly for the plugin import/no-deprecated

The upgrade process of the project involved moving from version 11.2.11 to version 12.2.10 through the nx upgrade process (nx migrate) Following this upgrade, the code linting process now takes around 4 minutes, compared to the previous 30 seconds: time ...

Steps for setting up single sign on in an Angular 2 application

Currently, I am working on a web application that has been developed using angular2. One of the requirements for this application is to incorporate a single sign-on feature, where users do not have to manually input their login credentials. Instead, the ap ...

An issue has occurred: changes.forEach does not function as expected

Encountered an issue while attempting to retrieve data from Firestore using Angular/Ionic. PizzaProvider.ts getAllPizzas() { return this._afs.collection<Pizzas>('pizzas', ref => ref); } pizzas-list.ts pizzas: Observable<any[]& ...

Utilizing Optional Generics in TypeScript

I have created a wrapper for making API calls to a Strapi server. export const api = { post: async<T extends unknown, K>(url: string, body: Partial<T>, jwt?: string): Promise<K> => { try { const result = await ...

Retrieve a particular item using the NGXS selector and incorporate it into the template

I am retrieving stored configuration settings from an API. Each setting includes an 'ID' and several properties like 'numberOfUsers', etc. I am utilizing NGXS for managing the state. My goal is to specifically fetch the 'numberOf ...

Why is the return type for the always true conditional not passing the type check in this scenario?

Upon examination, type B = { foo: string; bar: number; }; function get<F extends B, K extends keyof B>(f: F, k: K): F[K] { return f[k]; } It seems like a similar concept is expressed in a different way in the following code snippet: functi ...

Incorporating ng2-bootstrap into an Angular2 project with SystemJS starter template

I am attempting to integrate the ng2-bootstrap modal functionality into a component of my project that is built using the angular2-starter. Below is my systemjs.conf.js configuration: /* * This config is only used during development and build phase onl ...

utilize undefined files are assigned (Typescript, Express, Multer)

I am facing an issue while trying to save image uploads to a folder named "/images". The problem lies in the fact that req.files is appearing as undefined for some reason. Below is the relevant code snippet. Feel free to ask any questions, any assistance w ...

Return the subclass from the constructor function

class X{ constructor(input: string) { // do things } f() {console.log("X")} } class Y extends X{ constructor(input: string) { // do things } f() {console.log("Y")} } class Z extends X{ con ...