Using Nightwatch to Test Comments and Doctype

I am an IT instructor and started using Nightwatch to test students' homework to see if it meets meeting specifications.

I can check all the "normal" elements / attributes without problems. My problem is with some materials that you probably didn’t usually test in a production environment.

I want to verify that they are using the correct type of HTML5, which lies outside the root, of course, and I believe that Nightwatch starts with an HTML node.

I also tell them how to use comments to make their own lives easier and the lives of their fellow developers. Therefore, I would like to check that they leave comments. Some parts of the commentary are necessary and consistent, but other parts change, for example, their name in the commentary. Here is an example comment ...

The Name of the Page
Sample Page for the Widgets
Author: your name
Date: the date

Again, I probably would not test the comments and doctype in the real world, but I wonder if this is possible using Nightwatch?

I tried the containsText () and text.to.contain () methods already without success.

Any thoughts and recommendations would be appreciated.

In addition, I am not opposed to using another testing tool or any other middleware that can help if you know about it. I did not find any in my search and did not find a solution to my difficulty.

+4
1

, Nightwatch . ( ), -. - , - Selenium WebDriver. , , , "" , CasperJS. PhantomJS, WebKit.

Nightwatch

Nightwatch, , , .source(), () DOM:

browser
  .url("http://www.website.com")
  .source(function (res) {
    if (/<!--/.test(res.value)) {
      console.log("Comment detected!");
    }
  })

, , DOCTYPE, .source(). XPath, /html.

, console.log , . , Nightwatch CSS...

Casper

...

Casper .getHTML(), DOM. DOCTYPE, (.assertMatch()) . :

casper.test.begin('Test website', function (test) {
    casper.start('http://www.website.com', function () {
        var html = this.getHTML();
        test.assertMatch(html, /<!DOCTYPE html>/);
        test.assertMatch(html, /<!--.*-->/);
    });

    casper.then(function () {
        // Your code...
    });

    casper.run(function() {
        test.done();
    });
});

, HTML5 . .

+3

Source: https://habr.com/ru/post/1676963/


All Articles