In the nightwatch documentation I can see that there are both the urlContains and urlEquals assertions that can be specified in a nightwatch.js but these do not allow xpath selectors. I have applied the global parameter to use Xpath everywhere (I will explain below) but I am looking for a way to assert (in a fuzzy way) that the URL of the current page matches a pattern.

The reason is that I test on numerous instances of the same application which are distinguished by their subdomain(s). I am attempting to make my test automation run on any of these environments (without having to change or duplicate the tests).

  • Can you write your own function that has a regular expression pattern that does the matching?
    – Yu Zhang
    Dec 21 '16 at 16:13
  • Yes but want to be 100% there isn't a more maintainable way beforehand.
    – Rebecca D.
    Dec 21 '16 at 16:14

One way that you can do this is by using:

  .url(function(result) {
    //match result.value to expression here

This is the best way I've been able to get the URL and doing any kind of matching with it.

  • @Rebecca-d were you able to find a solution?
    – Swagin9
    Apr 4 '17 at 19:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.