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

browser.getLocationAbsUrl() has different behavior testing angular 1.2.26 and 1.3.0-RC.5 #1436

Closed
cthrax opened this issue Oct 13, 2014 · 9 comments

Comments

@cthrax
Copy link

cthrax commented Oct 13, 2014

Using angular 1.3 in the app under test and protractor 1.3.1 browser.getLocationAbsUrl() returns a relative url instead of the absUrl due to using angular.getTestability().getLocation() instead of $location.absUrl(). It's probably as easy as adding a getLocationAbs() to $$testability, but that goes into architectural questions I don't have context for.

So for a clear example, for URL http://domain.com/path?a=b#/hash on chrome (probably others, but not tested):

  1. Angular 1.2.26 browser.getLocationAbsUrl returns "http://domain.com/path?a=b#/hash"
  2. Angular 1.3.0-RC.5 returns "/hash"

The relevant protractor code is at:
https://github.com/angular/protractor/blob/master/lib/clientsidescripts.js#L567
As well as the relevant angular code at:
https://github.com/angular/angular.js/blob/85880a64900fa22a61feb926bf52de0965332ca5/src/ng/testability.js#L84
https://github.com/angular/angular.js/blob/1efaf3dc136f822703a9cda55afac7895a923ccb/src/ng/location.js#L348

I hope that's clear, but if you need anything else or if there's clear direction for what I can do to fix it, let me know.

Thanks!

@juliemr
Copy link
Member

juliemr commented Oct 14, 2014

This is working as intended but was accidentally omitted from the documentation at #1436.

Does this cause issues for you besides just being a breaking change?

@cthrax
Copy link
Author

cthrax commented Oct 15, 2014

At this point it won't cause me issues, but it's a little weird to ask for an absolute url (getLocationAbsUrl) and to get back a relative one. Other than that weirdness, I can see the argument for not having the absolute url exposed.

@cthrax cthrax closed this as completed Oct 15, 2014
@jlin412
Copy link

jlin412 commented Dec 3, 2014

@juliemr Can we reopen this issue? Due to #778 issue, we will need getLocationAbsUrl() to return the full abs path as a workaround. Currently in 1.4.0, I even get empty string when I am expecting something like http://localhost:8000/static/xxx/login.html

@dmitriz
Copy link

dmitriz commented Apr 7, 2015

getLocationAbsUrl() still gives only the relative path making the e2e test fail in the Tutorial:

https://code.angularjs.org/1.3.15/docs/tutorial/step_06
https://docs.angularjs.org/tutorial/step_06

@okcompute
Copy link

I'm using protractor 1.8.0, and this API got me confuse for a while. I was sure the problem was with my configuration. My belief was reinforced by the official documentation (http://angular.github.io/protractor/#/api?view=Protractor.prototype.getLocationAbsUrl). Should the the API be renamed to getLocationUrl() instead and documentation updated?! I can try to create a pull request if needed.

@adaykin
Copy link

adaykin commented Jul 28, 2015

So what is the way to get the absolute URL now in angular 1.3+? I would agree that the method should be renamed to getLocationUrl, if it's not really returning the absolute URL, otherwise it's really confusing.

@Dt-dev28
Copy link

Dt-dev28 commented Aug 6, 2015

my config : Angular 1.4.3, protractor - 2.1.0
And the latest API , ( http://angular.github.io/protractor/#/api?view=Protractor.prototype.getLocationAbsUrl ),
official Angular-phonecat tutorial app [Step-6] gives an error on e2e test in scenarios.js

 ...
it('should render phone specific links', function() {
  var query = element(by.model('query'));
  query.sendKeys('nexus');
  element.all(by.css('.phones li a')).first().click();
  browser.getLocationAbsUrl().then(function(url) {
    expect(url.split('#')[1]).toBe('/phones/nexus-s');
  });
});
 ...

error: expected undefined to be '/phones/nexus-s'

But: ( http://angular.github.io/protractor/#/api?view=webdriver.WebDriver.prototype.getCurrentUrl )
resolves it,
i guess we need to fix the API as it is not returning, what the syntax meant to do !!

@hhaamm
Copy link

hhaamm commented Nov 12, 2015

Is there a way to get absolute url? It's breaking legacy tests on protractor 1.7 and AngularJS 1.4.7

@StasShev87
Copy link

getLocationAbsUrl() gives only the relative path.
The test described in the protractor documentation fails on my angular application.

Instead I can use browser.getCurrentUrl()

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

No branches or pull requests

9 participants