Diego
Diego

Reputation: 610

Protractor browser.get() doesn't get the proper url

So I've been trying to use protractor in my Angular 4.4.6 project to test a template drive form.

I followed the protractor set up instructions from their website.

package.json

  "dependencies": {
    "@angular/common": "^4.4.6",
    "@angular/compiler": "^4.4.6",
    "@angular/core": "^4.4.6",
    "@angular/forms": "^4.4.6",
    "@angular/http": "^4.4.6",
    "@angular/platform-browser": "^4.4.6",
    "@angular/platform-browser-dynamic": "^4.4.6",
    "@angular/router": "^4.4.6",   
    "@types/selenium-webdriver": "^3.0.8",
    "core-js": "2.5.1",
    "json-typescript-mapper": "^1.1.3",
    "rxjs": "^5.5.0",
    "typings": "^2.1.1",
    "zone.js": "^0.8.18"
  },
  "devDependencies": {
    "protractor": "^5.0.0"
  }

protractor.conf.js

require('ts-node/register');

const helpers = require('./helpers');

exports.config = {
  baseUrl: 'http://localhost:3000/',

  specs: [
    helpers.root('src/**/**.e2e.ts'),
    helpers.root('src/**/*.e2e.ts')
  ],

  framework: 'jasmine',

  allScriptsTimeout: 11000,

  jasmineNodeOpts: {
    showTiming: true,
    showColors: true,
    isVerbose: false,
    includeStackTrace: false,
    defaultTimeoutInterval: 40000
  },

  directConnect: true,
  capabilities: {
    browserName: 'chrome',
    chromeOptions: {
      args: [ "--headless", "--disable-gpu", "--window-size=800x600", "--no-sandbox" ]
    }
  },

  onPrepare: function() {
    browser.ignoreSynchronization = true;
    require("zone.js/dist/zone-node");
    require('ts-node').register({
      project: 'tsconfig.e2e.json'
    });
  }

   SELENIUM_PROMISE_MANAGER: false
};

I have tried numerous ways on trying to get the url of my page.

Here's a sample code.

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

describe('General Info Component End to End', () => {
  beforeEach(() => {

    browser.waitForAngular();
    browser.get('asdfasdf, 3000);
  });

  it('should return page title', () => {
    element.all(by.css('#effective-date')).sendKeys('01/01/2018');

    expect(element.all(by.css('#effective-date')).getAttribute('value')).toContain('01/01/2018');

  });
});

This passes, which it shouldn't.

Upvotes: 1

Views: 1768

Answers (1)

Gois
Gois

Reputation: 98

To get the current page URL u need to use browser.getCurrentUrl(), also seems to have a missing single quote on your browser.get function call

Upvotes: 1

Related Questions