package user;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
public class Login {
public WebDriver driver;
@Test
public void Signin() throws Exception {
driver.manage().window().maximize();
Thread.sleep(5000);
driver.navigate().refresh();
driver.findElement(By.xpath("//div[@id='header']/div/div/ul/li[6]/a")).click();
driver.findElement(By.id("Email")).sendKeys("test@gmail.com");
driver.findElement(By.id("password")).sendKeys("123456");
driver.findElement(By.xpath("//tr[5]/td[2]/input")).click();
Thread.sleep(5000);
}
@BeforeTest
public void BeforeTest() {
System.setProperty("webdriver.chrome.driver", "D:\\lib\\chromedriver.exe");
driver = new ChromeDriver();
driver.get("http://test.com/");
}继承
package user;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.testng.annotations.Test;
public class Addtocart extends Login {
public WebDriver driver;
@Test
public void Cart() throws Exception {
Thread.sleep(5000);
driver.findElement(By.xpath("//div[2]/div/div/a")).click();
driver.findElement(By.xpath("//a[contains(@href, '/Catalog/Featured')]")).click();
driver.findElement(By.id("//div[4]/div/a/img")).click();
driver.findElement(By.id("anchorAddToWishList")).click();*/
}
public static void main(String[] args) throws Exception{
Addtocart ac = new Addtocart();
ac.BeforeMethod();
ac.Signin();
ac.Cart();
}
}当我首先尝试调用超类方法时。子类方法首先调用。如何初始调用超类方法
发布于 2017-06-21 03:39:47
使用TestNG时,请尝试使用:
@Test(priority=1) (assign the position to execute)发布于 2020-02-14 13:26:50
您从未在您的超类中定义'BeforeMethod‘方法,只是一个观察值。
TestNG - Number 0具有最高优先级(它将首先执行),优先级基于给定的数字,即0比1具有最高优先级。1具有比2更高优先级,依此类推。
公共类TestNG_Priority_Annotations {
@Test(priority=6)
public void c_method(){
System.out.println("I'm in method C");
}
@Test(priority=9)
public void b_method(){
System.out.println("I'm in method B");
}
@Test(priority=1)
public void a_method(){
System.out.println("I'm in method A");
}
@Test(priority=0)
public void e_method(){
System.out.println("I'm in method E");
}
@Test(priority=3)
public void d_method(){
System.out.println("I'm in method D");
}}
输出将为:
我用的是方法E
我用的是方法A
我用的是方法D
我用的是方法C
我用的是方法B
https://stackoverflow.com/questions/23782423
复制相似问题