2014-05-21 41 views
1
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("[email protected]"); 
     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/"); 
    } 

遺產繼承中硒的webdriver用TestNG

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

當我嘗試先調用父類的方法。子類方法首先調用。如何調用父類方法最初

+0

在testng.xml文件包括這個<套件名稱=「測試套件」平行=「假」保留階=「真」> \t <測試名稱= 「迴歸測試套件」> \t \t \t \t \t <類名= 「登錄」/> \t \t \t <類名= 「AddtoCart」/> \t \t \t – SanjayDVG

回答

0

使用TestNG嘗試使用:

@Test(priority=1) (assign the position to execute)