Skip to content

Commit

Permalink
Fixed nightwatchjs#1034 - page urls evaluated at navigate, not init
Browse files Browse the repository at this point in the history
  • Loading branch information
senocular authored and beatfactor committed Jul 30, 2016
1 parent b5e5cc7 commit 4891ae6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/page-object/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function Page(options, commandLoader, api, client) {
this.api = api;
this.client = client;
this.name = options.name;
this.url = this.getUrl(options.url);
this.url = options.url;

PageUtils
.createProps(this, options.props || {})
Expand Down Expand Up @@ -45,15 +45,15 @@ Page.prototype = {
/**
* This command is an alias to url and also a convenience method because when called without any arguments
* it performs a call to .url() with passing the value of `url` property on the page object.
* Uses `url` protocol command.
* Uses `url` protocol command.
*
* @method navigate
* @param {Object} [url=this.url] Url to navigate to.
* @param {function} [callback] Optional callback function to be called when the command finishes.
* @returns {*}
*/
navigate: function(url, callback) {
var goToUrl = url || this.url;
var goToUrl = this.getUrl(url || this.url);
if (goToUrl === null) {
throw new Error('Invalid URL: You must either add a url property to "' +
this.name + '" or provide a url as an argument');
Expand Down
31 changes: 31 additions & 0 deletions test/src/page-object/testPageObjectCommands.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,37 @@ module.exports = {
assert.equal(typeof page.section.propTest.props, 'object', 'props function should be called and set page.props equals its returned object');
assert.ok(page.section.propTest.props.defaults.propTest, 'props function should be called with page context');
assert.equal(page.section.propTest.props.defaults.propTest, '#propTest Value' );
},

testPageObjectWithUrlChanged : function(done) {
var page = this.client.api.page.simplePageObj();
var urlsArr = [];
page.api.url = function(url) {
urlsArr.push(url);
};

page.navigate();

page.api.perform(function() {
page.url = function() {
return 'http://nightwatchjs.org'
}
});

page.api.perform(function() {
page.navigate();
});

page.api.perform(function() {
try {
assert.deepEqual(urlsArr, ['http://localhost.com', 'http://nightwatchjs.org']);
done();
} catch (err) {
done(err);
}
});

this.client.start();
}
}
};

0 comments on commit 4891ae6

Please sign in to comment.