The browser successfully navigates in the e2e test, but the URL cannot be matched

Currently diving into the world of e2e testing with Protractor in our Angular application. My current focus is on testing the routing within a specific page. The goal here is to create and trigger a page object that will click on the top row of test data with an id of 7. This action should then activate a routing event that will take me to the intended page.

forwarding.e2e-spec.ts

      let detailsPage: ForwardingDetailsPo;
      beforeAll(async () => {
        page = new ForwardingPagePo();
        await page.navigateTo();
        detailsPage = new ForwardingDetailsPo();
        table = await page.getForwardingTablePo();
        await table.getTable().getRow('7').click();
      });
      afterEach(async () => {
        await detailsPage.navigateTo('7');
      });
      it('should navigate to details', async (done) => {
        browser.getCurrentUrl().then(url => {
          expect(url).toContain('administration/forwardings/7');
          done();
          }
        );
      });

    }); 

Following this, I aim to verify if the URL has indeed changed. Despite appearing successful on the automatically opened browser where tests are conducted, the actual test fails:

Expected 'http://localhost:4200/administration/forwardings' to contain 'administration/forwardings/7'.

I have confirmed that the row I am attempting to click is indeed .isPresent().

As you can see, I have included several awaits in the code to ensure that the test does not proceed before the routing process is complete. However, this approach does not seem to be entirely effective.

Any suggestions or insights?

______EDIT_______

The issue was not related to the click operation itself. Please refer to my answer for further details.

Answer №1

Based on my observation, it seems that you are moving to 7 after verifying the URL, rather than before. This is because the afterEach function runs after each individual it block.

Answer №2

After discovering the solutions, I wanted to share them here with everyone. The issue I encountered was related to timing. I had some other tests that required BeforeEach functions to be properly set up. In one of those tests, I mistakenly routed back to my main page again. Because beforeAll runs before the beforeEach calls, the routing worked as intended at first, but I soon realized that I was actually routing away almost immediately.

Today, I learned the importance of avoiding the use of beforeAll in certain inner tests unless absolutely necessary.

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

conducting tests for protractor across multiple browser environments

Seeking advice for running Protractor E2E tests on multiple remote hosts with various browsers such as Ubuntu - Firefox, Chrome, Windows - IE, Chrome, Firefox, Mac - Firefox, Chrome, Mobile - Android, Mobile - iOS etc. Please provide a sample configuration ...

How to Generate a Collection of Textfields in Angular 4

My challenge involves working with an array object that receives input from a textfield. I am looking to create a clean design where only one textfield is initially displayed, along with a '+' button next to it. When the user enters information i ...

Utilize Angular Service Worker to prefetch API data efficiently (dataGroups)

I am working on an Angular website that needs to function offline. In order to achieve this, I need some data from the API, which can be considered Stale data. To handle this scenario, my approach is to first attempt to retrieve the data from the API, and ...

New feature in Next.js 13: Utilizing a string within className

Looking for a way to dynamically generate radio buttons in Next.js using a list of strings? Utilizing Tailwind CSS classes, you can modify the appearance of these buttons when checked by leveraging the peer/identifier classname. But how do you include th ...

Not all of the Error constructors are displayed by TypeScript

My issue is straightforward: I am attempting to utilize the Error constructor that requires a message and an options object. Despite setting my tsconfig.json file to have "target": "es2020", the Intellisense in VS Code only displays one ...

Is it recommended to include the generated .js files in git when working with TypeScript code?

What is the best practice for handling generated .js files when writing a node.js application with TypeScript? Is it preferable to exclude generated .js files from version control by adding them to .gitignore and only committing the .ts files, or is it ac ...

Displaying dynamic key-value pairs in each row of an Angular mat-table

I need help displaying a key-value pair data in JSON format dynamically within a table using Angular mat-table. The keys will vary, so there is no set list of keys that will be included in the JSON. This is an example of the data: var data = { "cars" : 2 ...

Creating a personalized state object containing unresolved promises in React Native utilizing axios inside a custom React Hook

I'm currently in the process of creating a custom state within a custom Hook for React Native (non-Expo environment). The state I am working on looks like this: interface ResponseState { api1: { error: boolean; errorMsg?: string; ...

Setting ngModel to the month input control

I am trying to use ngModel to link a date object that contains the current month value and display the month and year on the input month calendar. However, even though the object is successfully bound to the control, the month/year does not appear. Any tip ...

Introducing the 'node' type in tsconfig leads to errors in type definitions

I've encountered an issue with my NodeJS project where I have a type declaration file to add properties to the Request object: @types/express/index.d.ts: import { User } from "../../src/entity/user.entity"; declare global { namespace Exp ...

Incorporate changing keys and fluctuating values into a JavaScript object

I am trying to create a function in TypeScript that will return an object like this: marked = { '2024-08-21': { dots:[food, recycling] }, '2024-08-22': { dots:[food, recycling] } } Here i ...

How to integrate ngx-bootstrap Static Modal into a personalized Angular 4 component

I have been trying to utilize the static modal feature from ngx-bootstrap in my Angular 4 project. When I directly include the modal on a web page, it works perfectly fine. However, when I try to include it in a component's templateUrl, it causes the ...

Why does the Material button style take time to apply when my Angular application first loads instead of being immediate?

Inside the Angular application I'm working on, there is a toolbar component that consists of three different links. The first link directs to the main app page, while the other two lead to distinct components within the app. Each link is styled with c ...

Getting a string output from a Typescript promise

Here is some Typescript code that I thought would be simple. public showDialog(theNickname: string): string { var req = { method: 'POST', url: '/Q/GetUserDetails', data: { nickname ...

In React-Typescript, the second index of the todos array is constantly being updated while the rest of the array remains unchanged

I am struggling to get my Todo-List working with typescript-react. The code I have doesn't seem to be functioning properly. Here is a snippet of my App.tsx: import { useState } from "react"; import "./App.css"; export default fun ...

Designing a versatile Angular component for inputting data (Mailing Address)

Currently, I am in the process of developing an Angular 11 application that requires input for three distinct mailing addresses. Initially, I thought I had a clear understanding of what needed to be done, only to encounter warnings about elements with non- ...

Issues have arisen with Angular 7.2.15 and three.js 0.105.2 following the upgrade of three.js

After updating Angular from V-7.2.5 to V-7.2.15 and Three.js from V-0.101.2 to V-0.105.2, I encountered a myriad of errors that I'm struggling to resolve: THREE.Box3's method .getSize() is throwing "error TS2554: Expected 1 arguments, but got 0. ...

Sending Data from Angular to PHP Server

Trying to send data from Angular to a PHP file and print it, but all I get is NULL :( I've gone through similar topics but still can't figure out what's going wrong or how this is supposed to work. Here's a simplified version of the s ...

Using Typescript to assign a custom object to any object is a powerful feature

I am attempting to organize table data by utilizing the code found at https://github.com/chuvikovd/multi-column-sort. However, I am unsure of how to pass a custom object to the SortArray[T] object. The structure of my custom object is as follows: const ob ...

Angular bootstrap search is encountering an issue with locating a supporting object. It seems to be struggling to find a differ for the object of type 'object'

I recently delved into learning autoComplete Search. While I successfully retrieved the object from the backend server, displaying them in HTML resulted in the following error. NgbTypeaheadWindow.html:5 ERROR Error: Cannot find a differ supporting object ...