您的位置:首页 > 产品设计 > UI/UE

Web UI自动化测试框架搭建之六:扩展testNG支持自动执行失败的脚本

2017-12-29 19:22 417 查看
1: 实现接口IRetryAnalyzer中的retry方法,如下:

public class MyRetryAnalyzer implements IRetryAnalyzer {

  private int curentRetryCnt = 0;

  private int maxRetryCnt = 2;

  public boolean retry(ITestResult result) {

    if (curentRetryCnt < maxRetryCnt) {

     //Add some logs here

      curentRetryCnt ++;

      return true;

    }

    return false;

  }

}

2: 覆盖IAnnotationTransformer中的方法,如下:

public class MyRetryListener implements IAnnotationTransformer {

  @Override

  public void transform(ITestAnnotation testannotation, Class testClass,

      Constructor testConstructor, Method testMethod) {

    IRetryAnalyzer retry = testannotation.getRetryAnalyzer();

    if (retry == null) {

      testannotation.setRetryAnalyzer(MyRetryAnalyzer.class);

    }

  }

}

3: 在testNG.xml中增加该listener,如下:

    <listeners>

           <listener class-name="framework.testNG.MyRetryListener"/>

     </listeners>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐