Waltir
By: Waltir

Testing Meta Tags With Nightwatch JS

Cover Image for Testing Meta Tags With Nightwatch JS

Nightwatch.js can be used to easily test various aspects of a website, including the presence and content of meta tags. In this example, we will show how to use Nightwatch to verify the meta tags on a webpage.

Let's start by creating a test file, for example, let's call it meta_test.js and place it in the tests' folder.

Here's an example of how the meta_test.js file might look:

module.exports = {
  'Test meta tags': function (browser) {
    browser
      .url('http://example.com')
      .waitForElementVisible('head', 1000)
      .assert.attributeContains('meta[name="description"]', 'content', 'This is an example website.')
      .assert.attributeContains('meta[name="keywords"]', 'content', 'example, website, test')
      .end();
  }
};

This test will navigate to the website's home page, wait for the head element to be visible, and then check the values of the meta tag with the name attribute as description and keywords to match the expected values.

In order to run the test, you can use the following command:

nightwatch tests/meta_test.js

This will run the meta_test.js file and output the results to the console.

You can also assert for other attributes in the meta tag like charset, property, http-equiv, etc.

In conclusion, Nightwatch.js is a great tool for automating browser testing and can be used to easily test the presence and content of meta tags on a webpage. With the help of this example, you can create your own tests to suit your specific needs and ensure that your website's meta tags are correct.

More Posts

Cover Image for Blocking Ad Traffic In Nightwatch JS
Blocking Ad Traffic In Nightwatch JS
Waltir
By: Waltir

Example showing how you can block unwanted ad traffic in your Nightwatch JS tests....

Cover Image for Blocking Ad Traffic In Cypress
Blocking Ad Traffic In Cypress
Waltir
By: Waltir

Example showing how you can block unwanted ad traffic in your Cypress tests....

Cover Image for Three Ways To Resize The Browser In Nightwatch
Three Ways To Resize The Browser In Nightwatch
Waltir
By: Waltir

Outlining the three different ways to resize the browser in Nightwatch JS with examples....

Cover Image for Happy Path VS Sad Path Testing
Happy Path VS Sad Path Testing
Waltir
By: Waltir

As a test engineer it is crucial that both happy path and sad path use cases have been considered and fully tested...