How to customize Cucumberjson report

Hi Team,

Cucumber json report have a result key which is having pass and fail status of test cases. If the test case fails, report shows the error message with its description like 'No element found using locator: By(xpath, //div[contains(text(), ‘Test’)]) ’

How can i add some meaning ful text which can appear along with the technical error message.

Expected something like : 'No element found using locator: By(xpath, //div[contains(text(), ‘Test’)]) '. Element ‘test’ is not present on login screen which makes the test case failed.

Please help me and let me know how i can customize it.

Thanks,
Rahul Sharma

Hi there and welcome to the community,

When Cucumber runs, it will report any exception occurring during the test and mark the test as failed. The reported error message will be the exception message. In your case, the test is failing because the element your are looking for could not be located. I guess the code looks something like this:

var div = element(by.xpath('//div[contains(text(), "Test")]'));

As Protractor fails to locate the element, it generates an exception with the text No element found using locator: By(xpath, //div[contains(text(), ‘Test’)]). As far as I know, there is no easy way to customize this message.

There are some attempts to customize this message in jasmine with jasmine-custom-message. And you can also check that element is present before making assertions on it, and throw a more meaningful error as described here.

You can also use another matcher which may yield more meaningful error messages:

var div = element(by.cssContainingText('div', 'Test'))