Skip to content

Commit

Permalink
Merge pull request segment-boneyard#902 from jekku/master
Browse files Browse the repository at this point in the history
Adds .path() to get path exclusively, instead of full url
  • Loading branch information
reinpk authored Dec 15, 2016
2 parents 0b5d778 + 710fba6 commit ad8058a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,9 @@ Returns the title of the current page.
#### .url()
Returns the url of the current page.
#### .path()
Returns the path name of the current page.
### Cookies
#### .cookies.get(name)
Expand Down
13 changes: 13 additions & 0 deletions lib/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ exports.url = function(done) {
}, done);
};

/**
* Get the path of the page.
*
* @param {Function} done
*/

exports.path = function(done) {
debug('.path() getting it');
this.evaluate_now(function() {
return document.location.pathname;
}, done);
};

/**
* Determine if a selector is visible on a page.
*
Expand Down
9 changes: 9 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,15 @@ describe('Nightmare', function () {
url.should.have.string(fixture('evaluation'));
});

it('should get the path', function*() {
var path = yield nightmare
.goto(fixture('evaluation'))
.path();
var formalUrl = fixture('evaluation') + '/';

formalUrl.should.have.string(path);
});

it('should check if the selector exists', function*() {
// existent element
var exists = yield nightmare
Expand Down

0 comments on commit ad8058a

Please sign in to comment.