How can I know the base url used in a running test in protractor?

Viewed 2058

I'm trying to do navigation test in protractor and don't see any consitency with the baseUrl in the config and the url used in the test.

protractor.conf.js

exports.config = {
  baseUrl: 'http://localhost:4200/'
}

navbar.e2e-spec.ts

import { NavbarPage } from './navbar.po';
import * as protractor from './../protractor.conf.js';
describe('navbar', () => {
  let navbar: NavbarPage;
  const baseUrl = protractor.config.baseUrl; 

  beforeEach(() => {
    navbar = new NavbarPage();
    browser.get('/');
  });
  it(`should see showcase nav item, be able to (click) it,
  and expect to be navigated to showcase page`, () => {
    const anchorShowcase = navbar.anchorShowcase;
    expect(anchorShowcase.isDisplayed()).toBe(true);
    anchorShowcase.click();
    browser.waitForAngular();
    expect(browser.getCurrentUrl()).toBe(baseUrl + '/showcase');
  });
});

Although when I run the e2e test it uses a different port:

** NG Live Development Server is listening on localhost:49154, open your browser on http://localhost:49154/ **

Why is the test url set to port 49154. This apparently seems to be the default if you start a new angular-cli project: https://github.com/angular/angular-cli

How can I get control over the baseUrl / Or is http://localhost:49154/ safe to use for all my angular cli projects?

3 Answers

Aniruddha Das's solution doesn't work anymore as this option isn't there from Angular CLI 6.x version, you can try following -

ng e2e --dev-server-target=

please see following reference

Related