Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getLocationAbsUrl() does not (always) return $location.absUrl() #3185

Closed
gkalpak opened this issue Apr 29, 2016 · 5 comments
Closed

getLocationAbsUrl() does not (always) return $location.absUrl() #3185

gkalpak opened this issue Apr 29, 2016 · 5 comments

Comments

@gkalpak
Copy link
Member

gkalpak commented Apr 29, 2016

Bug report

  • Protractor Version: 3.3.0

  • A relevant example test

    browser.get('http://angular.github.io/protractor/#/api');
    expect(browser.getLocationAbsUrl()).toBe('http://angular.github.io/protractor/#/api');
  • Output from running the test

    Expected /api to equal 'http://angular.github.io/protractor/#/api'.

As seen in protractor.ts#L864-L869 and clientsidescripts.js#L651-L658, the return value of getLocationAbsUrl() is different when angular.getTestability is available and most importantly it is not the absUrl (in the $location sense).

Basically, when angular.getTestability is not available, $location.absUrl() is returned (which is the expected behavior). But when angular.getTestability is available (i.e. since AngularJS v1.3.0-rc.0 - see angular.js#85880a6), $location.url() is returned instead (because that is what $$testability returns).

This is the case since at least Protractor v1.1.1 (see 0e9c2f4).

Returning $location.url() from a function named getLocationAbsUrl() isn't very intuitive, but this has been the case for a long time. For the next breaking release, it might be a good idea to expose two methods (on Protractor and $$testability) to retrieve both the .url() and the .absUrl(), e.g. getLocationUrl() and getLocationAbsUrl().

@juliemr
Copy link
Member

juliemr commented May 5, 2016

Yeah, this one's got an ugly history. See #3097 and #778

Is there a reason you can't use getCurrentUrl? We should really be discouraging getLocationAbsUrl.

Agree with potentially breaking for sanity at next breaking release.

@gkalpak
Copy link
Member Author

gkalpak commented May 6, 2016

No reason I can't use getCurrentUrl (except I am not sure it works on IE).

Basically, I think that (for Angular pages) getLocationUrl() (returning $location.url()) would be the most useful one (and in fact that is what getLocationAbsUrl() currently returns).

I reported this mostly because (1) the documentation is wrong and/or (2) the behavior is unexpected (i.e. the returned value doesn't match the name). I wasn't sure though how it should be best handled.

@bbaia
Copy link

bbaia commented May 9, 2016

Introduced by commit 0e9c2f4, why don't you remove the lines added in getLocationAbsUrl until it's supported in $$testability ?

@gkalpak
Copy link
Member Author

gkalpak commented May 10, 2016

@bbaia, the problem is not with fixing this (it's easy to change $$testability) - the problem is that it's a breaking change (i.e. people will have to update their currently working tests).

@sjelin
Copy link
Contributor

sjelin commented Dec 22, 2016

I say we deprecate it: add a logger.warn and some scary comments in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants