Image of Assertions in Testim

Assertions in Testim: A Complete Guide to Smart Testing

Table of Contents

Assertions are validation steps used in automated tests to verify that a web application behaves as expected. They ensure that elements, texts, attributes, or conditions meet the required criteria during test execution.

Testim provides various assertion methods to validate expected behaviors in automated tests. You can add assertions in Testim using its UI-based test editor or by writing custom JavaScript code.

CSS Property Assertion

  • Go to the step where you need to perform validations.
  • Click on Testim Predefined Steps → Click Validations → Click Validate CSS Property.
  • In the dialog box, enter the Property Name as background-color and the Expected Value as, for example, #abcd.

Text Assertion using Testim Predefined Actions

  • Go to the step where you need to perform validations.
  • Click on Testim Predefined Steps → Click Actions → Click Add Extract Value Step.
  • Now, click on the Extract Value block and set a variable name.
  • Next, go to Predefined Steps → Click Validations → Click Validate Element Text, then pass the previously set variable name in the Text Validation block.

Good to Read:- Testim Tutorial: AI-Based Record and Playback Testing

Text Assertion Using Javascript Code

  • Go to the step where you need to perform validations.
  • Click on Testim Predefined Steps → Click Actions → Click Add Extract Value Step.
  • Now, click on the Extract Value block and set a variable name.
  • Next, go to Predefined Steps → Click Validations → Click Add Custom Validation.
  • In the dialog box, enter the name of the step. This will open the JavaScript Editor.
  • Write the JavaScript code for the assertion in this editor.

Example Code

if(previousVariableName == expectedName) {

console.log(‘Test passed’);

return true;

}

else {

console.log (‘Test Failed’);

return false;

}

Element Visible / Not Visible Assertion

  • Go to the previous step and click on Predefined Steps.
  • Select Validate Element Visible (to check if the element is visible) or Validate Element Not Visible (to check if the element is not visible).

Related Blogs