TestNG配置失败

时间:2014-08-09 03:31:07

标签: selenium configuration testng

我正在尝试从命令行运行一个简单的TestNG测试,它会因配置失败而出错。相同的TestNG测试将从Eclipse IDE正确运行。从命令行它不起作用。这是此TestNG框架的严重限制,使其在持续集成主题中不可用。如果您打算使用TestNG,请确保在承诺将其用作测试框架之前,可以从命令行运行它。必须从Eclipse IDE运行它是一个严重的限制。

TestSuite_Bollosk
Total tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 1

命令行语法是:

java -cp "C:\correctclpath1\*;C:\correctclpath2\*" org.testng.TestNG "C:\anotherpath\TS_simpletest.xml"

测试看起来像这样:

package pkgTSBollosk;

import java.io.IOException;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class TC_Bollosk 
{
WebDriver driver;
@Parameters({"param1","param2"})
@Test
public void bollosktestmethod(String param1, String param2) throws InterruptedException 
{
    assert(true);
    System.out.println("test output for bollosk test:");
}
@BeforeTest
  public void beforeTest() throws IOException {
      driver = new FirefoxDriver(); 
      driver.manage().timeouts().implicitlyWait(2,TimeUnit.SECONDS);
          }
  @AfterMethod
  public void afterTest() {
      driver.quit();
      driver = null; 
  }
}

TS_simpletest.xml文件如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<suite name="Bollosk Test Suit" parallel="false">
 <test name="Bolluks test name">
  <parameter name="Param1" value="not - used"></parameter>
  <parameter name="Param2" value="not - used"></parameter>
    <classes>
      <class name="pkgTSBollosk.TC_Bollosk">
      <methods>
      <include name = "bollosktestmethod"></include>
      </methods>
      </class>
    </classes>
  </test> 
</suite>

4 个答案:

答案 0 :(得分:2)

用Assert.assertTrue代替断言并导入org.testNG.assert解决了这个问题。新手的陷阱.....我收回了我之前关于严重限制的陈述。

答案 1 :(得分:1)

public class test1 {
    public WebDriver d;
    @Parameters({"browsername","url"})
    @BeforeMethod
    public void browserselections(String broname,String URL) {

        System.out.println(broname);
        System.out.println(URL);

        if (broname.equalsIgnoreCase("ff")) {

            d = new FirefoxDriver();

        } else if (broname.equalsIgnoreCase("chrome")) {
            System.setProperty("webdriver.chrome.driver", "F:\\All jars\\chromedriver.exe");
         d = new ChromeDriver();

        }

        d.manage().window().maximize();
        d.get(URL);
    }

    @Test

    public void tc1() {

        d.findElement(By.id("lst-ib")).sendKeys("testing");
    }

}

below is my xml code

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" configfailurepolicy="skip">
    <test name="Test1">
    <parameter name="browsername" value="ff"/>
    <parameter name="URL" value="https://www.google.com"/>
        <classes>
            <class name="testng.test1" />
        </classes>
    </test>

    <test name="Test2">
    <parameter name="browsername" value="chrome"></parameter>
        <classes>
            <class name="testng.test1" />
        </classes>
    </test>
</suite> <!-- Suite -->enter code here

答案 2 :(得分:1)

我遇到了同样的问题,我注意到我的所有jar文件都在不同的子文件夹中。将所有这些文件移到一个库文件夹中,然后使用相同的命令执行。

java -cp“%projectLocation%/ Library / *”;“%projectLocation%/ target / classes /”org.testng.TestNG testng.xml

答案 3 :(得分:1)

尝试TestNG配置策略。添加参数configfailurepolicy =&#34;继续&#34;如果你想继续配置失败,那么configfailurepolicy =&#34; skip&#34;。示例

  <suite name="Bollosk Test Suit" configfailurepolicy="continue">