Close

CAPABILITY GENERATOR

LambdaTestAutomation Testing ● View Assertion Errors On LambdaTest

View Assertion Errors On LambdaTest


While handling GET requests in your Selenium scripts, many times the assertion might fail. To view these assertion errors as exceptions and handle them better, you can now use the Lambda Exceptions feature.

What Are Lambda Exceptions?


Lambda Exception is the feature of LambdaTest, by which you can easily manage and handle your GET request errors, like AssertionError. By using this feature, the error gets displayed as an exception in the Exception tab of your test.

For example:

How To Use Lambda Exception?


While performing assertions on GET requests, if the assertion fails, an AssertionError exception is thrown. Refer the below Java syntax to catch this error and push it to LambdaTest using Lambda Exceptions.

In the above syntax, when the AssertionError is caught in the catch{} block, the exception message is added in the form of an array of Strings. This message is then pushed to LambdaTest using the Lambda Exceptions feature, as shown via the JavascriptExecutor command.

Lambda Exception Demo


For demo purpose, we will create a script to:

  • visit www.lambdatest.com
  • fetch the title
  • assert the title with expected value

View Exception on LambdaTest Using Lambda Exception


Below is the complete code for this script, using TestNG framework in Java.

Upon executing the above test as a TestNG script, you will notice that the test will fail. It is because we have provided an incorrect value in the ExpectedTitle variable, for demo purposes. So when you open the test view of this test and navigate to the Exception tab, you will find a message displaying this error, as shown below:

View StackTrace on LambdaTest Using Lambda Exception


You can even view the complete StackTrace on the LambdaTest platform, using the Lambda Exceptions feature. For this, you need to convert the StackTrace to String and print it in the form of an array of Strings. Below is the complete script to print the StackTrace, using the TestNG framework in Java:

Upon executing the above test as a TestNG script, it will provide you the same result as the view exception section, because we have provided an incorrect value in the ExpectedTitle variable, for demo purposes. So when you open the test view of this test and navigate to the Exception tab, you will find the complete StackTrace, as shown below:

Below is the complete StackTrace printed on the LambdaTest platform, generated from above script.


That’s it! You can now easily handle and manage exceptions using the Lambda Exceptions feature. If you still have any doubt, please feel free to reach out to us via 24/7 chat support or by mailing to us on [email protected]. Happy testing! ?