How to embed screenshot in RF report

1,126 views
Skip to first unread message

bks456

unread,
Jan 8, 2017, 5:47:30 PM1/8/17
to robotframework-users
Hello experts

I am using robotframework-2.8.5.jar. Using selenium able to take screenshots upon test failures but how to embed the screenshot in the Robot framework generated report right after the keyword failure?

Appreciate your inputs.

Thanks,

Hi-Fi

unread,
Jan 9, 2017, 12:56:12 AM1/9/17
to robotframework-users
Selenium2Library should do that automatically, if the failure comes from it's own keywords. If not, you can e.g. overload the keyword used in check, and put teardown in that overloaded case which takes screenshot (which is automatically added to report) if that keyword fails.

Like: 
*** Keywords ***
Should Be Equal
    [Arguments]    ${first}    ${second}    ${msg}=None    ${values}=True
    Should Be Equal    ${first}    ${second}    ${msg}    ${values}
    [Teardown]    Should Be Equal Teardown
Should Be Equal Teardown
    Run Keyword If  '${KEYWORD STATUS}' == 'FAIL'
    ...   Capture Page Screenshot

There might be coming keyword to simplify this a bit to RF 3.x: https://github.com/robotframework/robotframework/issues/2201.

kev 456

unread,
Jan 9, 2017, 4:19:11 PM1/9/17
to Juho Saarinen, robotframework-users
I am using jython based RF, it has argument that takes listener. The listener has endTest methods, here i am overloading the method to take screenshot whenever the keyword fails but screen shot is not appending  to report. How can i do that?

How to customize if at all i have to?. I am currently using 2.8.5.



Jython RF setup:

classname="org.robotframework.RobotFramework"
rebot
--listener Listener



listener code:


public class Listener 
{
 
 
 public void endTest( String name, Map attributes ) throws IOException, ScriptException
 {
 String status = attributes.get( "PASS" ).toString();     
       
 if( !status.equals( PASS ) ) 
 {        
 
 try 
 {    
 File scrFile = ( ( TakesScreenshot )driver ).getScreenshotAs( OutputType.FILE );
 FileUtils.copyFile( scrFile, new File( outputFolder + "/" + errorFile + ".png" ) );        
 } 
 catch ( Exception ex ) 
 {
 System.out.println( "Exception while taking and saving screenshot" );
 ex.printStackTrace( System.out );
 }
 
 }
}





--
You received this message because you are subscribed to a topic in the Google Groups "robotframework-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/robotframework-users/9c_c7IJaYvA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to robotframework-users+unsub...@googlegroups.com.
To post to this group, send email to robotframework-users@googlegroups.com.
Visit this group at https://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

Hi-Fi

unread,
Jan 10, 2017, 12:23:27 AM1/10/17
to robotframework-users, juho.s...@gmail.com
I think you're making things too complicated by direcly calling webdriver at Java code.

But that way you can log the image in following way:
public static void logImage(String imagePath) {
logHTML("<a href='"+imagePath+"' target='_blank'><img src='"+imagePath+"' style='width:80%; height: auto;'/></a>");
}
public static void logHTML(Object log) {
System.out.println("*HTML* "+log);
Documentation: http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#logging-example 
To post to this group, send email to robotframe...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages