ptor.getCurrentUrl() is not working correct
Hello,
I've just started looking at protractor for our angularjs apps and looks very promising.
I want to use ptor.getCurrentUrl() to get url after login to make sure that I actually got logged in. My code looks something like this:
var util = require('util');
describe('Sign In Page', function() {
var ptor;
beforeEach(function() {
ptor = protractor.getInstance();
ptor.get('#/login/');
ptor.waitForAngular();
});
it ('Login', function(){
ptor.findElement(protractor.By.css('input[name=email]')).sendKeys("***");
ptor.findElement(protractor.By.css('input[name=password]')).sendKeys("***");
ptor.waitForAngular();
var currentUrl = ptor.getCurrentUrl();
console.log(currentUrl);
}, 20000);
it('afterAll', function(){
});
});
I'm using
var currentUrl = ptor.getCurrentUrl();
console.log(currentUrl);
to see what exactly gets stored and in console I see following result:
APankov$ node_modules/.bin/protractor conf.js
Using the selenium server at http://localhost:4444/wd/hub
{ then: [Function: then],
cancel: [Function: cancel],
isPending: [Function: isPending] }
What am doing wrong in this case?
Thank you
Hello! ptor.getCurrentUrl() is returning a promise that will resolve to the value of the current URL, not the URL itself. Check out https://code.google.com/p/selenium/wiki/WebDriverJs#Understanding_the_API for an introduction to promises in WebDriver. Specific documentation for getCurrentUrl() is available in the webdriver code at https://code.google.com/p/selenium/source/browse/javascript/webdriver/webdriver.js#621
Closing as there seem to be no further questions. Please reopen if something comes up!
Hey @juliemr, I've changed my code a little bit:
var util = require('util');
var Faker = require('../node_modules/Faker');
describe('Check Url after SignUp', function (){
var ptor;
beforeEach(function() {
ptor = protractor.getInstance();
ptor.get('#/');
var randomFirsName = Faker.Name.firstName();
var randomLastName = Faker.Name.lastName();
var randomEmail = "test+" + randomFirsName +"@2domen.com";
var signUpPassword ="qatest1";
ptor.findElement(protractor.By.css('input[name=first_name]')).sendKeys(randomFirsName);
ptor.findElement(protractor.By.css('input[name=last_name]')).sendKeys(randomLastName);
ptor.findElement(protractor.By.css('input[name=email]')).sendKeys(randomEmail);
ptor.findElement(protractor.By.css('input[name=password]')).sendKeys(signUpPassword);
ptor.findElement(protractor.By.css('button.green.large')).click();
ptor.waitForAngular();
}, 10000);
it('Check Current URL', function() {
ptor.getCurrentUrl().
then(function(url) {
expect(url).toBe('https://application.com/#/home');
});
}, 10000);
});
application.com is my BaseUrl in conf.js. But I'm getting error that URL doesn't match. Basically it takes base URL not a URL after i signup when user gets signed up
What's wrong with the code?
Thank you
I don't understand your last sentence, sorry. What is the URL that you are getting? On Sep 12, 2013 5:55 PM, "Andrew" [email protected] wrote:
Hey @juliemr https://github.com/juliemr, I've changed my code a little bit:
var util = require('util');
var Faker = require('../node_modules/Faker');
describe('Check Url after SignUp', function (){ var ptor;
beforeEach(function() { ptor = protractor.getInstance(); ptor.get('#/'); var randomFirsName = Faker.Name.firstName(); var randomLastName = Faker.Name.lastName(); var randomEmail = "test+" + randomFirsName +"@2domen.com"; var signUpPassword ="qatest1"; ptor.findElement(protractor.By.css('input[name=first_name]')).sendKeys(randomFirsName); ptor.findElement(protractor.By.css('input[name=last_name]')).sendKeys(randomLastName); ptor.findElement(protractor.By.css('input[name=email]')).sendKeys(randomEmail); ptor.findElement(protractor.By.css('input[name=password]')).sendKeys(signUpPassword); ptor.findElement(protractor.By.css('button.green.large')).click(); ptor.waitForAngular(); }, 10000);
it('Check Current URL', function() { ptor.getCurrentUrl(). then(function(url) { expect(url).toBe('https://application.com/#/home'); }); }, 10000);
});
application.com is my BaseUrl in conf.js. But I'm getting error that URL doesn't match. Basically it takes base URL not a URL after i signup when user gets signed up
What's wrong with the code?
Thank you
— Reply to this email directly or view it on GitHubhttps://github.com/angular/protractor/issues/57#issuecomment-24366633 .
I apologize, I should be more specific.
I have baseURL in conf.js file, which is a basic sign up page. Which looks like https://myapp-qa.domen.com/#/ I'm passing my gmail name + generated by Faker name to create unique users. After user signs up he should be redirected to the main page of the app and url should look like https://myapp-qa.domen.com/#/home. This URL is hardcoded for now.
Basically what happens protractor doesn't wait until home page gets loaded, grabs baseURL and then my test fails.
I hope it's more clear now.
Thank you.
A
On Sep 12, 2013, at 8:59 PM, Julie Ralph [email protected] wrote:
I don't understand your last sentence, sorry. What is the URL that you are getting? On Sep 12, 2013 5:55 PM, "Andrew" [email protected] wrote:
Hey @juliemr https://github.com/juliemr, I've changed my code a little bit:
var util = require('util');
var Faker = require('../node_modules/Faker');
describe('Check Url after SignUp', function (){ var ptor;
beforeEach(function() { ptor = protractor.getInstance(); ptor.get('#/'); var randomFirsName = Faker.Name.firstName(); var randomLastName = Faker.Name.lastName(); var randomEmail = "test+" + randomFirsName +"@2domen.com"; var signUpPassword ="qatest1"; ptor.findElement(protractor.By.css('input[name=first_name]')).sendKeys(randomFirsName); ptor.findElement(protractor.By.css('input[name=last_name]')).sendKeys(randomLastName); ptor.findElement(protractor.By.css('input[name=email]')).sendKeys(randomEmail); ptor.findElement(protractor.By.css('input[name=password]')).sendKeys(signUpPassword); ptor.findElement(protractor.By.css('button.green.large')).click(); ptor.waitForAngular(); }, 10000);
it('Check Current URL', function() { ptor.getCurrentUrl(). then(function(url) { expect(url).toBe('https://application.com/#/home'); }); }, 10000);
});
application.com is my BaseUrl in conf.js. But I'm getting error that URL doesn't match. Basically it takes base URL not a URL after i signup when user gets signed up
What's wrong with the code?
Thank you
— Reply to this email directly or view it on GitHubhttps://github.com/angular/protractor/issues/57#issuecomment-24366633 .
— Reply to this email directly or view it on GitHub.
@juliemr, it looks like I'm having same issue as described here https://github.com/angular/protractor/issues/88
Hi , I have fixed the issue using the following function to wait for the URL to change function waitForUrlToChangeTo(newUrl) { var currentUrl;
return browser.getCurrentUrl().then(function storeCurrentUrl(url) {
currentUrl = url;
}
).then(function () {
return browser.wait(function () {
return browser.getCurrentUrl().then(function (url) {
return (url !== newUrl);
});
});
}
);
}
I've got a problem with IE10/IE11 that both returned URL without hash, whereas webkit returned with hash. Switched to a more cross-browser hack:
browser.executeScript('return window.location.hash;').then(function(v){
console.log(v);
});
On ie11 browser.getCurrentUrl() does not return the current url, but the previous url.
The hack from @tot-ra works.
To be honest, all the APIs from protractor suck. The best way looks like to run always javascript code inside the browser. So may problems I am getting with protractor...
@ctamas you don't understand the way protractor and js selenium api manages promises.
and getCurrentUrl() always worked, while in ie11 don't.
I guess the way js selenium API or protractor manage promises has problems in synchronization, or it is a way that is not a good one to manage promises.
@ctamas the point is that it is not clear when to resolve promises with then and when not, and selenium api communicates like there is no need to resolve promises with then, while there is this need as we are demonstrating in this thread.
I think the confusion comes from this sentence
The promise manager maintains a queue of scheduled tasks, executing each once the one before it in the queue is finished.
and from the fact that someone - not only me apparently - expects a different behavior from getCurrentUrl()
My fault I did not get the semantic of getCurrentUrl()
i am using the statement browser.get(URL); but the url is not launched, rather just the browser window is opened by the previous statement browser.manage().window().setSize(1600, 1000); which was defined in onprepare method on conf.js file
is there any solution to this?