Adding Asserts During and After Test Recording

An assert is a boolean expression used to help debug and test a condition as part of the code execution. If the condition is met (true), the program continues to run as normal. However, if the condition is not met (false), an assertion failure is triggered, and the test will halt or an error message will be displayed. Using assert primarily aims to catch bugs or unexpected conditions during the development phase.

With Sofy, when you use an assert and the condition is not met during testing, you can either stop your test execution or create a warning but continue to execute your test. This selection is made when you are specifying the assert rules.

Adding Asserts while Recording a Test Case

  1. Log in to your Sofy account.
  2. Click Device Lab from the left navigation bar.
    Sofy home page with a callout over the Device Lab option in the left navigation bar.
  3. Acquire and launch a device.
  4. Start recording a test case.
  5. To add an assert, click the Assert icon in the action bar to the right of the device.
    Device Lab with a callout over the Add Assert option in the action menu.
  6. Click on a component or element on your app. This will open the Add Assert window.
  7. Configure the following assert settings:
    1. Verify: Choose from the following asserts:
      1. Component: Check if a certain component is present or absent, enabled or disabled, checked or unchecked, and so on.
      2. Text: Verify that certain text is present, or if a field contains text.
      3. Numeric: Verify whether a numeric condition or expression evaluates as expected.
    2. Then: Specify what you want the system to do if the assert fails. Choose from the following:
      1. Fail Test: If the visual match is not made on the specified step, the test will automatically end with a “Failed” status.
      2. Warn and Continue: If the visual match is not made on the specified step, a warning will be added to the step but the test will continue.

Adding an Assert to an Existing Text Case

You can add either a Component Assert or Visual Assert to an existing test case. A Component Assert can be used for validating text, content, numeric values, component existence, or element properties. A Visual Assert can be used when selecting a region of this screen to validate images or elements that are not well-defined, or to ensure that your visuals are consistent.

Note: We do not recommend using a Visual Assert for the following scenarios:

  • For automated tests recorded and run on devices that have largely different screen sizes. For example, the test was recorded on a mobile device and played on a tablet.
  • The custom bounds are drawn around an area that might contain noise. For example, if your app has a white background and the element you’ve selected has a lot of white space, the system might mark those white spaces as redundant, resulting in a false positive or incorrect match.

To add an assert to an existing test case:

  1. Log in to your Sofy account.
  2. Go to Automation from the left navigation bar.
    Sofy home page with a callout over the Automation left navigation bar option.
  3. Select a test case.
  4. Find and select the step you want to add a Visual Match override to, then select Edit from the popup.
    Automated test steps with a callout over the Edit option in the popup menu next to a step.
  5. Select the Add Assert tab.
    Add Assert window with a callout over the Add Assert tab.
  6. Choose what kind of assert you want to add:
    1. Component Assert: Used for validating text, content, numeric values, component existence, or element properties.
      1. Click on an element or component on the screen to the left.
      2. Configure the following assert settings:
        1. Verify:
          1. Component: Check if a certain component is present or absent, enabled or disabled, checked or unchecked, and so on.
          2. Text: Verify that certain text is present, or if a field contains text.
          3. Numeric: Verify whether a numeric condition or expression evaluates as expected.
        2. Then: Specify what you want the system to do if the assert fails. Choose from the following:
          1. Fail Test: If the visual match is not made on the specified step, the test will automatically end with a “Failed” status.
          2. Warn and Continue: If the visual match is not made on the specified step, a warning will be added to the step but the test will continue.
    2. Visual Assert: Used when selecting a region of this screen to validate images or elements that are not well-defined, or to ensure that your visuals are consistent.
      1. Click on an element or component on the screen to the left.
      2. Check the Create Custom Bound box.
      3. In the screen to the left, click and drag your mouse over the desired area to create a green custom-bound box. The box coordinates will appear in the Custom Bounds field.
      4. If you need to redo the custom bound box, click and drag your mouse again to remove the original box and create a new one.
      5. Under If Assert condition fails, select one of the following options:
        1. Fail Test: If the visual match is not made on the specified step, the test will automatically end with a “Failed” status.
        2. Warn and Continue: If the visual match is not made on the specified step, a warning will be added to the step but the test will continue.
  7. Click Save when you’re done.
  8. Select Save Test in the top right-hand corner to save your changes.

Assert Functions

The following tables describe how various assert functions are used in Sofy.

Component

Component Assert

UI/Element Component

Description

Component is present

Any Element

The component is present in the current view.

Component is not present

Any Element

The component is not present in the current view.

Component is enabled

Button, TextBox

The component is enabled for data entry or selection.

Component is disabled

Button, TextBox

The component is enabled for data entry or selection.

Component is checked

Checkbox

The component is checked.

Component is unchecked

Checkbox

The component is unchecked.

Text

Text Assert

UI/Element Component

Description

Text has content and should be equal

Button, Labels, TextBox

Text of the component matches with the string that is provided.

Text has content and should not be equal

Button, Labels, TextBox

Text of the component does not match with string that is provided.

Text has content and should contain

Button, Labels, TextBox

Text of the component contains the string that is provided.

Text has content and should not contain

Button, Labels, TextBox

Text of the component does not contain the string that is provided.

Numeric

Numeric Assert

UI/Element Component

Description

Numeric is equal to

Number

The component has a numeric value that is equal to the defined number.

Numeric is greater than

Number

The component has a numeric value that is greater than the defined number.

Numeric is greater than or equal to

Number

The component has a numeric value greater than and/or equal to the defined number.

Numeric is less than

Number

The component has a numeric value that is less than the defined number.

Numeric is less than or equal to

Number

The component has a numeric value lesser than (and/or equal to) the defined number.

Numeric is in-between

Number

The component has a numeric value lying between two defined numbers.


How did we do?