23

What I want to do is:

expect(browser.getCurrentUrl()).toEqual(protractor.baseUrl + urls.cookiesPage());

This is what I get:

 - Expected 'https://somewebsite.com/about/cookies/' to equal 'undefined/about/cookies/'.

How to pass baseUrl from config file into my test so I can assert it?

Jakub Mucha
  • 1,342
  • 1
  • 13
  • 18

1 Answers1

60

5 minutes later, I found an answer... after 2 hours of research:

expect(browser.getCurrentUrl()).toEqual(browser.baseUrl + 'some/url/right/here');

So, this was the answer:

browser.baseUrl
Oliver Spryn
  • 16,871
  • 33
  • 101
  • 195
Jakub Mucha
  • 1,342
  • 1
  • 13
  • 18
  • On my side this assertion throws an error: *Argument of type 'string' is not assignable to parameter of type 'Expected>'*, not on your side ? – ThCollignon Aug 29 '18 at 10:01
  • the only note I can add is that browser.baseUrl returns a different value if you are debugging in vscode. When debugging you don't get a slash on the end, when running 'ng e2e' you do get one. I had to modify my tests accordingly. – samneric Dec 26 '18 at 22:57
  • How do you set value for baseurl in config.js ? I did like this but get a compile error . exports.config = { //directConnect: true, framework: 'jasmine', baseUrl='https://juliemr.github.io/protractor-demo', – Sameera De Silva Dec 13 '19 at 08:27
  • I can pass it like this but I prefer to mention it in my config,js anyway to achieve it ? Thank you . protractor defaultconfig.js --baseUrl https://juliemr.github.io/protractor-demo – Sameera De Silva Dec 13 '19 at 08:37