2015-09-27 21 views
-1

什么是错误的设置环境的代码无法运行该代码成立之后TestNG的不运行

亲切指导它

package tc1; 

import java.util.concurrent.TimeUnit; 

import org.openqa.selenium.By; 

import org.openqa.selenium.WebDriver; 

import org.openqa.selenium.chrome.ChromeDriver; 

import org.openqa.selenium.firefox.FirefoxDriver; 

import org.testng.annotations.AfterClass; 

import org.testng.annotations.BeforeClass; 

import org.testng.annotations.Test; 

public class TC001 { 

    WebDriver driver; 

    @BeforeClass 

    public void launchBrowser(){  

     FirefoxDriver driver = new FirefoxDriver(); 

     driver.manage().timeouts().implicitlyWait(50000, TimeUnit.SECONDS); 
    } 

    @Test 

    public void login(){ 

     driver.get("http://www.meritnation.com/testprep"); 

     driver.findElement(By.className("login-link")).click(); 
     //Thread.sleep(50000); 

    } 

    @AfterClass 

    public void browserClose(){ 

     driver.quit(); 
    } 
} 

有显示零游程和零故障运行TestNG的输入代码here

[TestNG的]运行: C:\用户\用户\应用程序数据\本地\ TEMP \ TestNG的-蚀 - 1256807320 \ TestNG的-customsuite.xml

===============================================默认的测试

测试运行:0,失败:0,跳过:0

============================ ===================默认套房

总测试运行:0,失败:0,跳过:0

[TestNG的]时间采取[FailedReporter通过= 0失败= 0跳过= 0]:3 ms

[TestNG]时间采取 [email protected]:1毫秒

[TestNG的]采取[email protected]时间:

[TestNG的]时间采取的56毫秒

[email protected]:26 毫秒

[TestNG的]时间采取 [email protected]:9毫秒

[TestNG的]采取 org.testng时间.reporters.SuiteHTMLReporter @ 6bf2d08e:66 ms

+0

你是如何引发的考验吗? –

回答

0

简短的回答是,我认为你需要改变@Before@BeforeClass

而且我不知道什么进口使用(我只是一味地没有按Ctrl + Shift +在eclipse O),或者是什么网站你要,但我想我会在给你一个工人阶级给一个镜头,所以我希望这有助于:

import java.util.concurrent.TimeUnit; 

import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.firefox.FirefoxDriver; 
import org.testng.annotations.AfterClass; 
import org.testng.annotations.BeforeClass; 
import org.testng.annotations.Test; 

public class TC001 { 

     // WebDriver driver; 
     public static WebDriver driver = new FirefoxDriver(); 

      @BeforeClass 
      public void launchBrowser() { 



       driver.navigate().to("https://www.google.com"); 
      // FirefoxDriver driver = new FirefoxDriver(); 

      // driver.manage().timeouts().implicitlyWait(50000, TimeUnit.SECONDS); 
      } 

      @Test 
      public void login() { 

       driver.findElement(By.className("login-link")).click(); 

       //Thread.sleep(50000); 
      } 
      @AfterClass 
      public void browserClose() { 

       driver.quit(); 
      } 


} 

更新: 当我跑到你的代码是失败,失败1。由于您见状,0运行,我会问

  1. 你能尝试在Eclipse“清洁工程”(或任何你的IDE 是)。

  2. 尝试关闭重新启动IDE

    • 确保您已安装TestNG的在你的IDE,如果你能真正 得到它的运行,那么我们进入到下一个问题。

    你正在与司机做一些不寻常的事情。你声明2个不同的东西作为你的“驱动程序”。
    - 尝试做public static WebDriver driver = new FirefoxDriver();像我有我的回答,

    • @beforeclass方法取出FirefoxDriver线,

    • @beforeclass.

还可以使用driver.navigate
+0

还有一件事,我删除了超时,因为我不想等那么久,因为它失败。随意取消注释。 – jason12459

+0

我仍然面临同样的问题。测试运行:0,失败:0,跳过:0 – shruti

+0

与JUnit不同,TestNG被设计为在'@ Before/AfterClass'方法中使用非'static'属性。 – juherr

0

驱动程序已经宣布两次。 @BeforeClass方法正在创建一个本地的FirefoxDriver实例,它不能在@Test方法中访问。在创建FirefoxDriver()的实例的情况下,在@BeforeClass中删除'FirefoxDriver'。换句话说,用@BeforeClass方法替换FirefoxDriver driver = new FirefoxDriver();driver = new FirefoxDriver();

所以,它看起来有点像这样:

public class TC001 { 

WebDriver driver; 

@BeforeClass 

public void launchBrowser(){  

    driver = new FirefoxDriver(); 

    driver.manage().timeouts().implicitlyWait(50000, TimeUnit.SECONDS); 
} 

//剩下的代码,因为它是