TestNG执行测试次序:depends依赖关系,首字母,优先级

一:dependsOnMethonds依赖关系

@Test(dependsOnMethonds={“上个@Test方法”})

public class testDepend {
	private WebDriver driver;
  @Test
  public void openSougou() {
	     driver.get("https://www.sogou.com/");
		 
		
  }
  
  @Test(dependsOnMethods= {"openSougou"})
  public void switchFrame() throws InterruptedException {
	     driver.findElement(By.xpath("//*[@id=\"loginBtn\"]")).click();
		 driver.switchTo().frame(driver.findElement(By.xpath(("/html/body/div[1]/iframe"))));
		 driver.switchTo().frame("ptlogin_iframe");
		 Thread.sleep(1000);
  }
  
  @Test(dependsOnMethods= {"switchFrame"})
  public void run() throws InterruptedException {
	     driver.findElement(By.xpath("//*[@id=\"switcher_plogin\"]")).click();
		 driver.findElement(By.xpath("//*[@id=\"u\"]")).clear();
		 driver.findElement(By.xpath("//*[@id=\"u\"]")).sendKeys("123");
		 driver.findElement(By.xpath("//*[@id=\"p\"]")).clear();
		 driver.findElement(By.xpath("//*[@id=\"p\"]")).sendKeys("123");
		 Thread.sleep(1000);
  }
  
  @BeforeClass
  public void beforeClass() {
	  System.setProperty("webdriver.chrome.driver", ".\\tools\\chromedriver.exe");
	  driver=new ChromeDriver();
	  driver.manage().window().maximize();
  }

  @AfterClass
  public void afterClass() {
	  driver.quit();
  }

}

TestNG中一个类中有多个测试方法的时候,多个测试方法的执行顺序或者依赖关系的问题。

二:@Test方法首字母大小升序

如果不用dependsOnMethods,testNG会自动根据@Test方法名称的首字母升序来执行测试方法。

三:priority优先级设置

或者可以设置测试方法的优先级:

@Test(priority=执行顺序序号)

public void 方法1(){

    xxxxxx;

}

 

@Test(priority=1)

public void 方法2(){

    yyyyyyy;

}

&~&~&~&  当想要某段方法暂时不执行,可修改test代码块:  @Test(enabled=false)   也可注释掉//

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值