2014-07-23 90 views
1

我是selenium webdriver的新手,我剛安裝了eclipse kelpler的TestNG插件,現在當我試着用TestNG來執行我的代碼時,我能夠看到代碼出現在@BeforeTest下,但是@Test註解下的代碼沒有被執行。 下面是代碼我已經寫了:TestNG沒有在selenium webdriver的Test註釋裏面執行方法

import java.util.List; 
import java.util.Set; 

import org.junit.Test; 
import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.WebElement; 
import org.openqa.selenium.chrome.ChromeDriver; 
import org.openqa.selenium.firefox.FirefoxDriver; 
import org.openqa.selenium.support.ui.ExpectedConditions; 
import org.openqa.selenium.support.ui.Select; 
import org.openqa.selenium.support.ui.Wait; 
import org.openqa.selenium.support.ui.WebDriverWait; 
import org.testng.annotations.AfterTest; 
import org.testng.annotations.BeforeTest; 

public class Survey_Fill { 

WebDriver driver; 

    @BeforeTest 
    public void start(){ 
     driver= new FirefoxDriver(); 

     org.openqa.selenium.Dimension d = new org.openqa.selenium.Dimension(1360, 1200); 
     driver.manage().window().setSize(d); 
    } 

    @Test 
    public void test(){ 
     System.out.println("hello"); 

    } 

} 

這裏是TestNG的結果給出的輸出:

[TestNG] Running: 
    C:\Users\User\AppData\Local\Temp\testng-eclipse--1183478272\testng-customsuite.xml 


=============================================== 
    Default test 
    Tests run: 0, Failures: 0, Skips: 0 
=============================================== 


=============================================== 
Default suite 
Total tests run: 0, Failures: 0, Skips: 0 
=============================================== 

[TestNG] Time taken by [email protected]: 35 ms 
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 0 ms 
[TestNG] Time taken by [email protected]: 164 ms 
[TestNG] Time taken by [email protected]: 257 ms 
[TestNG] Time taken by [email protected]: 0 ms 
[TestNG] Time taken by [email protected]: 13 ms 

請讓我知道,我已經在這裏做了錯誤。 謝謝。

回答

3

如果你正在運行使用TestNG的

你的測試刪除import org.junit.Test

使用TestNG的註釋,

import org.testng.annotations.Test; 

爲什麼它不工作,

bcoz,測試( )方法是從Junit派生的,並且start()方法使用的是TestNG註釋,因爲您將Test作爲TestNG測試運行,Junit test()不會執行。

如果您將測試作爲Junit測試運行,則可以看到差異。

相關問題