Tips for creating a script that waits for a specific amount of time before moving on to the next execution block in Protractor

Need to automate a test case that involves filling out a form with 5 date pickers and 30 fields. Once the form is filled, a jar needs to be invoked to retrieve the data from the DB and process it independently.

Note: The jar does not send any value back to the script, but it should update the process status on the UI after 1 minute.

Tried using wait in the beforeEach() block, but it caused unnecessary delays in the script by introducing waits before each step. In one of the forum threads, some users recommended using the done function of Jasmine 2, but I am not sure how to implement it.

Sample code:

describe("Test functionality of xyz", ()=>{
    // few it blocks
    it();
    it();

    // login to the UI 
    it("Login to application", ()=>{
        utility.signIn(inputTestdata.Common.LoginPage.Username, inputTestdata.Common.LoginPage.Password);
    });

    // filling the form 
    it("Fill the form", ()=>{
        utility.fill_form(dataSet);
    }); // want Protractor to wait for exactly 1 minute before executing the next it block

    it("Process the data", ()=>{
        utility.runSimulator();
    }); // want to wait here for 2 minutes  

    it("Verify the result", ()=>{
        // verifying the result 
    });

    // more it blocks 
});

Expected behavior: The jar invocation it block should only run after the form filling it block has been processed. Then, there should be a specified delay before proceeding to the verification result step.

However, in reality, Protractor calls the form filling it block and immediately moves on to the jar it block.

Answer №1

If you're looking to avoid waiting after each 'it' statement, you'll need to incorporate the wait within the 'it' block itself.

One option is to utilize the sleep function or the wait function based on your specific scenario.

Alternatively, you can create nested describe blocks specifically for the test case where waiting is necessary and include the wait in the afterEach method.

Answer №2

To pause the program's execution, utilize "browser.sleep(time in milliseconds)".

describe("Testing functionality of abc", ()=>{
// a few it blocks
it();
it();

//login to the system 
it("Log in to the platform", ()=>{
    utility.signIn(inputTestdata.Common.LoginPage.Username, 
    inputTestdata.Common.LoginPage.Password);
});

// completing a form
it("Complete the form", ()=>{
    utility.fill_form(dataSet);
    browser.sleep(2000);// specify how long you want to wait at this stage.
}); // ensuring Protractor waits for 1 minute before proceeding with the next it block

it("Process the information", ()=>{
    utility.runSimulator();
    browser.sleep(2000); // specifying how long to wait at this stage.
}); // waiting here for 2 minutes  

it("Check the outcome", ()=>{
    //checking the result 
});

//additional it blocks 
});

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

A guide on retrieving data from Firestore using TypeScript

I've been diving into a chat project using Angular, and Firestore has given me a bit of trouble. Trying to get the hang of typescript while working with it. Within app.module.ts, kicking things off with: import { provideFirebaseApp, getApp, initi ...

Issue encountered when attempting to import a module within the ionic framework

I encountered an issue in my project (built with the ionic-framework 3) where I included the following line to import the dialogflow module: const dialogflow = require('dialogflow'); However, when compiling, it resulted in the error message: ...

Transforming a JSON object into XML format

Currently, I am encountering an issue while attempting to convert my JSON object to XML using the xml-js library's json2xml function. When trying to implement this functionality, I keep getting an error message that states: Error: Buffer is not defin ...

Incorporate the {{ }} syntax to implement the Function

Can a function, such as toLocaleLowerCase(), be used inside {{ }}? If not, is there an alternative method for achieving this? <div *ngFor="let item of elements| keyvalue :originalOrder" class="row mt-3"> <label class=" ...

Changing the appearance of a specific child component in React by referencing its id

There is an interface in my code. export interface DefaultFormList { defaultFormItems?: DefaultFormItems[]; } and export interface DefaultFormItems { id: string; name: string; formXml: string, isDefaultFormEnable: boolean; } I am looking ...

Navigating to an external link directing to an Angular 5 application will automatically land on

I am struggling to comprehend why a link from an external source to my Angular app keeps redirecting to the default route page when accessed from a browser. The scenario involves a user entering an email address, triggering an API that sends an email cont ...

Properly incorporating a git+https dependency

I'm facing an issue while trying to utilize a git+https dependency from Github to create a TypeScript library. I've minimized it to a single file for illustration purposes, but it still doesn't work. Interestingly, using a file dependency fu ...

"Encountering an issue with mounting components in React Unit Testing with Jest and Typescript

Having developed a simple app with components, here is the code: import GraphicCanvas from './Graphing/GraphCanvas'; import { drawCircle } from './Graphing/DrawCircle'; function App() { return ( <div className="App"&g ...

Currently attempting to troubleshoot a factory operation that is experiencing difficulties with injection

As a newcomer to Angular and testing in general, I am attempting to create a simple test to check if the object is defined before proceeding with further testing. An error message that I encounter is: Error: [$injector:unpr] Unknown provider: $statePar ...

What is the best way to download a file with a specific name using Angular and TypeScript?

Greetings! Below is a snippet of code from my Angular component: this.messageHistoryService.getMessageHistoriesCSV1(msgHistoryRequest).subscribe( (data) => { console.log(data.messageHistoryBytes); let file = new Blob( [data.messageHistoryBytes ...

TypeScript - Converting into individual compiled files

Currently, I am working on a project that consists of lengthy source files. While this is advantageous for imports, it poses challenges in terms of maintenance. For instance: /main/core.ts export type Foo { ... } export interface Bar { ... } export cla ...

What is the best way to create a linear flow when chaining promises?

I am facing an issue with my flow, where I am utilizing promises to handle the process. Here is the scenario: The User clicks a button to retrieve their current position using Ionic geolocation, which returns the latitude and longitude. Next, I aim to dec ...

Can the return type of a function be utilized as one of its argument types?

When attempting the following code: function chain<A, B extends (input: A, loop: (input: A) => C) => any, C extends ReturnType<B>> (input: A, handler: B): C { const loop = (input: A): C => handler(input, loop); return loop(input) ...

Using RxJs in an Angular 2 application to enable row selection in a table by detecting mouse movements

Check out this example of an Angular 2 application with row selection in a table: https://plnkr.co/edit/HdQnWqbg9HloWb4eYGHz. The row selection functionality is implemented using mouse event handlers (mousedown, mousemove, mouseup). Below is the template ...

The behavior of the dynamically generated object array differs from that of a fixed test object array

I'm facing an issue while trying to convert JSON data into an Excel sheet using the 'xlsx' library. Everything works perfectly when I use test data: //outputs excel file correctly with data var excelData = [{ test: 'test', test2: ...

"Encountering an issue where attempting to set a property on an undefined variable, despite it being

I've been working on a timer app/component, but I'm running into an issue. The error message reads: Cannot set property startAt of undefined. I've defined it in my dashboard component, so I'm not sure where the problem lies. Any suggest ...

By specifying the union type being used, the TypeScript compiler is informed

Imagine I have the following type: type TMyType = { a: string; b: number; c: number; d?: SpecialTypeA | SpecialTypeB | SpecialTypeC; } How can I specify in typescript that I am aware of the type of d in my (React) child components? I am hoping f ...

Currently in the process of executing 'yarn build' to complete the integration of the salesforce plugin, encountering a few error messages along the way

I've been referencing the Github repository at this link for my project. Following the instructions in the readme file, I proceeded with running a series of commands which resulted in some issues. The commands executed were: yarn install sfdx plugi ...

A script object must only permit one property at a time

I am unfamiliar with TypeScript and I have an object named obj with 3 properties: a, b, c. However, it is important to note that b and c cannot exist together in the same object. So, my object will either be: obj = { a: 'xxx', b: 'x ...

Arranging a list of objects with a designated starting value to remain at the forefront

Consider the array and variable shown below: array = ['complete','in_progress','planned']; value = 'planned'; The goal is to always sort the array starting with the 'value' variable, resulting in: array ...