-1

I'm having trouble verifying that a certain string exists in a page's source in nightwatch.js

Basically, I'm trying to replicate the verifyHtmlSource command from Selenium IDE.

Does anyone know how to verify that a certain string exists in a page's source in Nightwatch?

Testerson
  • 21
  • 4

2 Answers2

1

On way would be to call .containsText on the body:

.assert.containsText('body', 'my text')
Florent B.
  • 41,537
  • 7
  • 86
  • 101
  • I need to check for something that is loaded via javascript and it doesn't appear anywhere on the page, only in the source. I know that the page's source is printed in the following example but is there a command that can be run against the result.value variabe to verify that particular string exists in it? `browser .url("http://www.google.com") .source(function (result){ // Source will be stored in result.value console.log(result.value); })` – Testerson Apr 13 '16 at 13:33
  • Your original post doesn't contain enough information to provide a better answer. So please update with a reproducible example. – Florent B. Apr 13 '16 at 13:38
1

I was able to test for a string within a page's source with the following code:

.source(function (result){ _browser.verify.equal((result.value.indexOf('STRING IN PAGE SOURCE TO MATCH AGAINST') > -1), true) })

Testerson
  • 21
  • 4