Automation testing

8. Assertions

Assertions

Assertion - is a way of verification. We can verify that data exist on the page, url is the one we expect to have, and.... pretty much anything else.

WairFor... as a way of assertion

Let's start with making sure elements existence on the page. For this purpose, we don't even need to use any extra modules. We can simply use:

  • waitForDisplayed(); - waits until selector is displayed
  • waitForExist(); - waits until selector exists
  • waitForClickable(); - waits until selector is clickable

Assert module as a way of assertion

For more complicated cases where we need to verify, let's say URL === 'https://www.google.com', we could use the chai module. Don't forget to install it if you haven't done so:

  • npm install chai

Assert URL

// require assert from chai module
const assert = require('chai').assert;
// use this one in your test
const url = browser.getUrl();
assert.equal(url, 'https://www.google.com', 'Url mismatch');
Assert text === 'expected text'

// require assert from chai module
const assert = require('chai').assert;
// use this one in your test
const actualText = $('#fakeTextId').getText();
const expectedText = 'Expected fake text';
assert.equal(actualText, expectedText, 'Our fake text did not match expected one');
Assert true

// require assert from chai module
const assert = require('chai').assert;
// use this one in your test
const loggedInUserIcon = $('#fakeIconId').isExisting();
assert.isTrue(loggedInUserIcon, 'User was not logged in');
Assert false

// require assert from chai module
const assert = require('chai').assert;
// use this one in your test
const usernameTextfield = $('#fakeUsernameTxtId').isExisting();
assert.isFalse(usernameTextfield, 'User was not logged out');
See entire list of assertions at: chais website
Previous Article
7. The Power Of XPath
Automation testing
Next Article
9. JS Automation test errors explanation
Automation testing
We help ambitious people to get into Tech with no prior experience.