Protractor: Stuck on the current piece of Code

Why is the "else" code inside the "IsPresent()" function not getting executed in Protractor with Jasmine framework? The "IF" code works fine, but when I provide a value from an Excel file, the execution stops at the "IF" block. Any suggestions on why it's stuck and not moving forward would be appreciated.

Note: Recursion is used to read values from the Excel file and print the output based on the index.

Here is the code snippet:

import { browser, protractor, element, by, By, ElementArrayFinder, ElementFinder } from "protractor";
import { Workbook } from "exceljs";
import { exists } from "fs";


describe('Search PID', () => {
    var Excel = require('exceljs');
    var wrkbook = new Excel.Workbook();
    wrkbook.xlsx.readFile("Path to the excel file");

    beforeAll(() => {
        browser.ignoreSynchronization = true;
        browser.get('My App URL');

    });

    function PIDMatching(value, index) {
        // Function logic here...
    }

    fit('Navigation', () => {
        // Test case logic here...
});

Answer №1

Implement async / await for better promise handling

Utilizing async / await can help streamline your code by avoiding nested promises and long chained then statements. By refactoring the given code to use async / await, it will improve readability and maintainability.

An important reason to switch to async / await is Protractor's transition away from control flow support. To disable the control flow feature in Protractor, ensure that SELENIUM_PROMISE_MANAGER: false is set in your Protractor configuration file.

// It's recommended to maintain consistency in importing 'By' in your code.
// Avoid mixing "by" with "By".

export async function loop(i: number): Promise<void> {

  if (i >= 1) {
    // Consider using a CSS selector instead of complex xpath for locating web elements.
    await element(by.css('body > app-root > app-side-menu > mat-sidenav-container > mat-sidenav > mat-nav-list > div > div > div.col-md-2 > button')).click();

    // Avoid xpath usage and follow the style guide provided at http://www.protractortest.org/#/style-guide
    const count = await element.all(by.xpath('//*[contains(@id,"mat-dialog")]/app-error-dialog/div/div[1]/div/span')).count();
    console.log(`count Value is: ${count}`);

    if (count <= 0) {
      const PID = await element(by.css('text[transform="translate(800.8947256481425,612.9323227754049)rotate(0)"]')).getText();
      console.log("PID is: " + PID);
    } else {
      await element(by.xpath('//*[contains(@id,"mat-dialog")]/app-error-dialog/div/div[1]/div/span')).click();
      await loop(i - 1);
    }

    // Further clarity on recursion logic needed for this section.
    await element(By.css('body > app-root > app-side-menu > mat-sidenav-container > mat-sidenav-content > app-process-view-container > div > app-process-pane > div > mat-card > nav > div > ul > li:nth-child(5) > a > div')).click();

    // Recursion execution with more insights required for understanding.
    await loop(i - 1);

    // Recursive call based on undefined variable 'rows'.
    await loop(rows);
  }
}

Revising the question with detailed explanation on the recursive actions performed during testing would greatly help in providing precise assistance. Please provide additional information on what actions are being taken and the expected outcomes for better understanding.

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

The service has terminated unexpectedly because of signal: Ended prematurely: 9

I'm encountering the error 'Service exited due to signal: Killed: 9' and am unable to launch my app. I've come across information suggesting that this may be caused by memory leaks or a lengthy startup time for the app. In all honesty, ...

Can an Angular application be developed without the use of the app-root tag in the index.html file?

I'm a newcomer to Angular and I'm trying to wrap my head around how it functions. For example, if I have a component named "login", how can I make Angular render it directly? When I try to replace the app-root tag with app-login in index.html, n ...

Mastering the proper usage of the import statement - a guide to seamless integration

I'm excited to experiment with the npm package called camera-capture, which allows me to capture videos from my webcam. As someone who is new to both npm and typescript, I'm a bit unsure about how to properly test it. Here's what I've ...

Steps to align the outline of VS Code with the current location in the editor

When working in a language known for its large and complex files, it can be frustrating to navigate through the code. I often find myself scrolling up and down multiple times just to locate the current function name. This is why I am looking for a way to e ...

Retrieving the key from an object using an indexed signature in Typescript

I have a TypeScript module where I am importing a specific type and function: type Attributes = { [key: string]: number; }; function Fn<KeysOfAttributes extends string>(opts: { attributes: Attributes }): any { // ... } Unfortunately, I am unab ...

How to fetch a file from a Spring Boot server using Angular 4

I'm currently developing a Spring Boot server with an Angular 4 front-end. I've created a service that allows users to download a .zip file from the front-end using HttpClient. Below is my code: Angular service: getZip(fileName: string) : Obser ...

What is the initial component that Angular will activate or run?

Uncertainty surrounds the correctness of my question. Within my application, there exist numerous routing components and feature modules. I am eager to discern whether the appcomponent.ts file or the routing logincomponent.ts file will be executed first. ...

Encountering the error message "Error: 'preserveValueImports' is an unknown compiler option" while setting up a SvelteKit project

https://i.stack.imgur.com/fnidk.png Every time I set up a new sveltekit project using TypeScript, I keep encountering the error "Unknown compiler option 'preserveValueImports'.ts" in the tsconfig.json file. The error shows up above the line wher ...

Mastering the art of utilizing Function's construct signatures within TypeScript

Currently delving into the TypeScript documentation, specifically exploring More on Functions. However, I find myself perplexed by the code snippet provided below. Can someone offer guidance on how to implement this in practical development scenarios? An ...

The risk of a race condition could arise when working with nested switchMaps in ngr

I am currently working on an Angular 9 application that heavily relies on observables. In a specific component, I have the following requirements: Retrieve all companies to access certain information. Fetch all responses and link additional company detai ...

Make sure accordion items stay open even when another one is clicked

I have implemented an accordion component that currently opens and closes on click. However, I am facing an issue where clicking on one item closes another item that was previously open, which is not the behavior I desire. I'm unsure of the best appro ...

What is the best way to organize a collection of objects by a specific characteristic in Typescript?

Imagine you have an array of objects with the following structure: type Obj = { id: number, created: Date, title: string } How can you effectively sort this array based on a specific property without encountering any issues in the type system? For ...

Mapping intricate entities to intricate DTOs using NestJS and TypeORM

Currently, I am using the class-transformer's plainToClass(entity, DTO) function to transform entities into DTO objects. In addition, I have implemented the transform.interceptor pattern as outlined in this source. I make use of @Expose() on propert ...

Modify the selection in one dropdown menu based on the selection in another dropdown menu using Angular 8

When I have two dropdowns, I aim to update the second dropdown with a matching JSON object based on the value selected in the first dropdown. JSON this.dropdownValues = { "mysql 8": { "flavor": [ "medium", ...

There is no matching overload for this call in Angular. Error code: TS2769

Having trouble identifying the issue in this TypeScript code snippet. Error reported on line 5, ".subscribe((response: { Token: string }) => {". login() { this.httpClient .post('http://localhost:4000/signin', this.loginForm.value) ...

A pronounced distinction exists between ionInput and ionChange functionality

Q. Can you explain the difference between (ionInput) and (ionChange) events in Ionic framework? When would it be more appropriate to use one over the other? I have experimented with both event handlers below and found that they produce the same expected r ...

Building an interactive menu in Angular: A step-by-step guide

I am working with an Interface that looks like this: export interface INavData { name?: string; url?: string | any[]; icon?: string; } To populate this Interface, I use the following data structure: export const navItems: INavData[] = [ { ...

TS2339: The 'map' property is not available on the 'Object' type

I'm currently working with the following code snippet: import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Observable } from 'rxjs/Observable'; import 'rxjs/add/op ...

Deactivating a form field depending on a selected radio button in Angular 2

If I have two radio buttons, with a click function called localClick for the first button to give value 1 and the second button to give value 2. <div class="ui-g-12"><p-radioButton name="group1" value="Local" (click)=localClick(1) label="Local"&g ...

The variable being declared at the class level inside a function within the same class is not recognized

Seeking guidance on the code snippet I'm currently studying. I am implementing a TypeScript 1.8.10 compiler along with EM5: module myAmazingModule{ 'use strict'; export interface INavigateService { links: string[], ...