Reputation: 136
I'm trying to check if the current url of the page after click on submit button is changed to the right url. I tried to do it in many ways that i found on web, but nothing is worked. Sometimes the problem is that it can't be possible to doing equality for "url object" and "string", sometimes something else. One thing is surely, the error when i launch the test. Can you help me? Thank you.
Here my stepdefinition.js
expect(browser.getCurrentUrl()).to.equal("https://myurl.com/eng/homepage.html");
Here my error:
E/launcher - expected { Object (flow_, stack_, ...) } to equal 'https://myurl.com/eng/homepage.html'
[15:34:28] E/launcher - AssertionError: expected { Object (flow_, stack_, ...) } to equal 'https://myurl.com/eng/homepage.html'
Upvotes: 0
Views: 2579
Reputation: 186
browser.getCurrentUrl() returns a promise. You'll need to resolve it using .then() as shown below :
Option 1) Only use chai
// protractor conf.js
onPrepare: function() {
var chai = require('chai'),
chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
global.expect = chai.expect;
// make `expect`as global, so you can use it anywhere is your code
}
browser.getCurrentUrl().then(function(currentUrl){
expect(currentUrl).to.equal("https://myurl.com/eng/homepage.html");
})
Option 2) Use chai
and chai-as-promised
together:
// protractor conf.js
onPrepare: function() {
var chai = require('chai'),
chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
global.expect = chai.expect;
// make `expect`as global, so you can use it anywhere is your code
}
expect(browser.getCurrentUrl()).to.eventually
.equal("https://myurl.com/eng/homepage.html");
Upvotes: 3
Reputation: 707
Try doing:
expect(browser.getCurrentUrl()).toEqual("https://myurl.com/eng/homepage.html");
Upvotes: 0