Comments

1 comment

  • Avatar
    Prateek Kumar Baheti

    Currently there is no way to disable screenshots on Failure in Twist. The screenshots are not taken only if tests are running on a headless environment.

    Though there is a  way to take custom screenshots in Twist. It be done by wiring "CustomScreenshotListener". This is an interface that Twist exposes with a method

         public void captureScreenshot(File directory, String screenshotFileName) 

    You can write a class that implements this interface and captures a screenshot with the fileName and in the directory name provided as arguments. This screenshot can be taken via webdriver in your case.

     package com.foo;

      public class MyScreenshotListener implements CustomScreenshotListener {    

         @Autowired

          private WebDriver browser;  //Autowire if needed

          public void captureScreenshot(File directory, String fileName) {

              // Take screenshot here

               }

          }

     

     

    To register this screenshotListener you need to add beans in the applicationContext-suite.xml in the Twist project like below.

       

    <bean id="myScreenshotListener" class="com.foo.MyScreenshotListener">

    </bean>

       

    <bean id="screenshotListener" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">

            <property name="targetClass" value="com.thoughtworks.twist.core.execution.report.CustomScreenshotListenerFactory"/>

            <property name="targetMethod" value="addCustomScreenshotListener"/>

            <property name="arguments">

                 <list>

                     <ref bean="myScreenshotListener"/>

                  </list>

              </property>

     </bean>

    This will add the custom screenshots to the generated reports. Though not documented, this is an easy way to hook custom screenshots into Twist.

     

    0
    Comment actions Permalink

Please sign in to leave a comment.