Hi,
I have scenario like I have to trigger email in specific format like reason for failure, Priority etc…, whenever test fail in robot framework. Please help in getting solution
Thanks,
Sudheer
Hi,
I have scenario like I have to trigger email in specific format like reason for failure, Priority etc…, whenever test fail in robot framework. Please help in getting solution
Thanks,
Sudheer
Hi Sudheer,
There are so many possible ways to solve this problem, but none are really “builtin”
How are you running your tests?
The fact that you want email notification on failure indicates that they are probably being run by some automated process?
Does that process have the ability to send email notifications? because this is the usual way to handle this type of notification.
Dave.
@damies13 We are running our test script locally using Visual studio code. None are really ‘built in’ means do we need to write python code to trigger mail for the failure test case/step? Please share the ways we can achieve this.
Thanks,
Sudheer
Hi Sudheer,
As I mentioned before, most of the time this would be handled by the process that launched the test, meaning your CI/CD engine or build server. But if you are triggering the tests manually then yes you would need ti implement something.
Some examples of what you could do (there are many other options these are just a few):
Robot framework is very flexible and can do almost anything if you set your mind to it, it’s also got really great documentation.
Dave.
sendinblue.com has an API which allows you to send emails. You can also create and save templates in SendInBlue and call those templates from the API with variable data.
Using this I trigger emails on failure from robot framework using a POST request.
A simple example RF Code:
*** Settings ***
Library OperatingSystem
Library RequestsLibrary
Library Collections
*** Variable ***
${string1} apples
${string2} oranges
*** Test Cases ***
ApplesAreOranges
IF '${string1}'=='${string2}'
log to console Apples are oranges and dogs are cats and monkeys eat bananas.
ELSE
create session email https://api.sendinblue.com
${headers}= create dictionary content-type=application/json accept=application/json api-key=reallylongapikeyhere
${json}= get file failed.json
${response} post on session email /v3/smtp/email headers=${headers} data=${json}
log to console ${response}
fail
END
…and example json file which it is reading the body content from:
{
"sender":{
"name":"Testy McTesterson",
"email":"noreply@somedomain.com"
},
"to":[
{
"email":"youremailaddress@yourdomain.com",
"name":"Your Name"
}
],
"subject":"ROBOT FRAMEWORK JOB FAILED",
"htmlContent":"It's broke yo."
}
The script generates a failure since apples do not equal to oranges, then generates the email as such:
I think this is the right way.
I’m doing it like so:
ResultVisitor
Of course, you can handle listener, that will send information about failed test right after test fails, but for me is better to just parse output, and do other things with it, not just send email
Hi @tomaspekarovic,
Just FYI when robot exits you can catch the Return codes at the os level, if it’s 0 all the tests passed witch might be useful if you only want to notify when there is a failure.
Also catching the stdout Command line output might be useful as the email body if you just want a quick summary, might save you from processing the XML if that’s sufficient information and you just attach the xml and html files.
Hope that’s helpful,
Dave.
Hi.
I know but I want to store all as jira tasks, every time. I just create task with suitename and date and other information. Create subtasks with timing, and if everything is ok, I just close all the taska/subtasks.
If not, failed results are assigned to specific person.
This way, i can look for all the runs in history with their specific states and even find out if it found a bug or not.
Ofc notification are sent only if there is any problem.
Also log.html is attached, but the parsed tasks gives me more freedom and statistics about runs.
If someone does not need this information it is maybe better to just get statuscode and send notification of it is error.
Hi,
I’m collecting Test status in teardown using rum keyword if test failed and if test fails it will trigger a mail with error. To trigger mail I have written python code but I want to also attach log reports generated by robot framework in the mail itself. Can we collect log reports during execution runtime?
Report files will be written as a last step of the robot run so, either in any teardown be it test or suite, the files wont be in proper shape…
Can we collect log reports during execution runtime?
Yes, via Listener interface you can collect the status but not the actual files.