2014-07-23 97 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测试运行,则可以看到差异。

相关问题