Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protractor check for location path

Is it possible to check the location path? I'm new to AngularJS and I'm learning with a book that describes ngScenario. This package is deprecated and I'm trying to update the described test to protractor.

E.g.

expect(browser().location().path()).toEqual('/books'); 

becomes:

expect(browser.getCurrentUrl()).toEqual('http://localhost:8080/#/books');

But I'd like to avoid http://localhost:8080/.

like image 824
Thomas Sablik Avatar asked Dec 25 '22 11:12

Thomas Sablik


1 Answers

Just use the power of jasmine matchers:

expect(browser.getCurrentUrl()).toMatch(/\/#\/books$/);  // /#/books at the end of url
expect(browser.getCurrentUrl()).toEndWith("/#/books");
expect(browser.getCurrentUrl()).toContain("/#/books");

where toEndWith() is coming from an awesome jasmine-matchers library.

Or, if you want an exact match, get the base URL:

expect(browser.getCurrentUrl()).toEqual(browser.baseUrl + "/#/books");
like image 87
alecxe Avatar answered Jan 05 '23 07:01

alecxe