Rayrun
← Back to Discord Forum

How to print custom message to html report?

vipinphogatposted in #help-playwright
Open in Discord
vipinphogat

I am creating a no code low code framework using playwright with Nodejs. I want to print custom messages in the report based on the outcome of the assertions.

Is there a way i can store the result of the assertion and evaluate the same to generate the custom message. Below is an example: const outcome = expect(username).toHaveText(‘admin’) If(outcome == true){ Print a passed message to report }else{ Print a failed message to report }

This thread is trying to answer question "How to print custom message to html report based on the outcome of assertions?"

8 replies
vipinphogat

How to print custom message to html report?

shaddarion
shaddarion

in case you need to print message only on failure you can use this - expect(2 > 1, 'Calcdulation is incorrect').toBe(true);

vipinphogat

Actually i want to print different message for pass and fail condition …. Is there a way i can do it based on outcome of expect?

tphillips8117

I don't mean to hijack this thread, but I am also wanting to know this. Sometimes just printing an informational message to the test log is useful, how do we see this in the report? Do our console.log messages from test scripts appear in any rest reports? How do we see those messages?

there is a way for printing messages to HTML report using test.step(), you can try that. it takes the message as first argument and async functions as second.

vipinphogat

Test.step() will always print the detail in the report ….irrespective of the outcome of the assertion. I want to print the message based on assertion outcome. @tphillips8117 - you can see the console logs at the bottom of the report in stdout under attachments section

@vipinphogat: Yeah. I missed the assertion outcome part! Sorry!

Yeah. I missed the assertion outcome part! Sorry!

vipinphogat

Guys… thank you for reading out the question and taking out the time to reply. As a workaround I implemented allure report and in playwright config file i marked detail option as false. As a result, pw api calls are not printing in the report and only the test.step() caption is getting printed. This is not exactly what i wanted but for now i think this is the best option i can proceed with… let me know if you have any suggestions for me

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].