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();
}
}