0

I have an Angular 9 app. It has 2 projects in it. If I run e2e tests. it runs on the whole app. i.e. if I look for h1 tag, it takes the default app root h1 tag. I cannot make it access project 1 or project 2. How do I add / write an e2e test , to test the nav menu in project 1 for example?

This is my folder structure:

-- whole-angular
  -- e2e
  -- projects
    --project-a
      --e2e (I have manually put this here as not sure if I need to, where to put it)
        --src
          --nav.bar.e2e-spec.ts
          --nav-bar.po.ts
        --protractor.conf.js
        --tsconfig.e2e.json
      --src
          -- app (and then all the usually project/app files)
    --project-b
  --src

am thinking I need to set something inside the global e2e config file? Maybe the angular.json file. Or even the e2e config inside the actual project?

nav-bar.po-ts

import { browser, by, element, ElementFinder, promise } from 'protractor';

export class NavBar {
    navigateToBio():promise.Promise<any> {
        return browser.get('/bio');
    }

    getBioPage():promise.Promise<any>  {
        return element(by.css('h1')).getText();
    }
}

nav-bar.e2e-spec.ts

import { NavBar } from './nav-bar.po';
import { browser, protractor, element, by } from 'protractor';

describe('Nav bar', () => {  
    let navBar: NavBar = new NavBar();

    beforeEach(() => {
        navBar.navigateToLead();
    });
   
    it('should display the bio page', () => {
        navBar.navigateToBio();
        expect(navBar.getBioPage()).toEqual("bio page");
    });

  });

Error:

In the console it says:

(passes the default e2e test there) workspace-project App √ should display welcome message

(fails my one) Nav bar × should display the lead page - Expected 'Welcome to whole-angular!' to equal 'bio page'.

Any more info you need let me know :-)

Pepper
  • 709
  • 1
  • 7
  • 15
  • There could be multiple approches: - Either you can add "f" infront of describe block to run ONLY this describe block and all it's "it" cases no other describe will be run. - Secondly you can add the path_of_file.spec.ts under "spec:[]" in protractor.conf.js file to run only particular spec file. – khizer May 15 '20 at 17:51
  • @khizer Hi Thanks. I have added 'path_of_file.spec.ts under "spec:[]' so nice to know I am along the right lines :-) Thing is though when running the test, it runs it on the whole app - as in I am checking the h1 tag of the bio page of project-a. It fails the test. As it looks at the h1 tag of 'whole-angular' app. How do i get to to go to project-a and look at that h1. I'll add more code to my question :-) – Pepper May 18 '20 at 08:13

0 Answers0