JAVA自定义注解在自动化测试中的使用

发表于:2015-5-28 09:59

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:张飞_    来源:51Testing软件测试网采编

  6.再来初始化一下实现注解类:
  package com.test.annotation;
  import org.openqa.selenium.WebDriver;
  public class InitialAnnotation {
  private WebDriver driver;
  public InitialAnnotation(WebDriver driver) {
  this.driver = driver;
  }
  public void initialAnnotation(){
  LoadAllPage lap = new LoadAllPage();
  lap.setDriver(driver);
  lap.loadAllPage();
  AutoPage ap = new AutoPage();
  ap.setPageAnnotation();
  }
  }
  7.接下来就是使用了:在一个Page中加上这个@LoadPage注解:
  package com.test.page;
  import org.openqa.selenium.WebDriver;
  import com.test.annotation.LoadPage;
  import com.test.base.Page;
  @LoadPage("firstPage")
  public class FirstPage extends Page{
  public FirstPage(WebDriver driver) {
  super(driver);
  }
  public void linkToMobileList(){
  driver.navigate().to("http://www.baidu.com");
  }
  }
  8.为了使@Page注解在case中能用到,所以得在TestBase的@BeforeClass中添加如下代码:
  if(InitialManger.allInstance.isEmpty()){
  InitialAnnotation init = new InitialAnnotation(driver);
  init.initialAnnotation();
  }
  AutoPage ap = new AutoPage();
  ap.setTestAnnotation(this);
  9.在CASE中这样用即可:
package com.test.testcases;
import java.util.Map;
import org.testng.annotations.Test;
import com.test.annotation.Page;
import com.test.base.TestBase;
import com.test.page.FirstPage;
public class Test2 extends TestBase{
@Page(name="firstPage")
private FirstPage firstPage;
@Test(dataProvider="providerMethod")
public void testLogin(Map<String, String> param){
firstPage.linkToMobileList();
}
}
33/3<123
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号