简体   繁体   English

我从命令行运行testng,但未执行任何测试

[英]I'm running testng from command line but no tests get executed

If I run my testng.xml from Eclipse IDE, everything works well; 如果我从Eclipse IDE运行testng.xml,那么一切都会很好; but if aI try to run them from command line then i see following 但是如果我尝试从命令行运行它们,那么我会看到以下内容 在此处输入图片说明

Folder structure: 资料夹结构: 在此处输入图片说明

My Class is following, whose test are run fine when I run from eclipse IDE: 我的课程如下,当我从Eclipse IDE运行时,其测试运行良好:

package package1;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class Example1 {

    public static WebDriver driver;

    @BeforeTest
    public void launchBrowser() {
        System.setProperty("webdriver.chrome.driver", "C:\\Eclipse\\Selenium\\chromedriver.exe");
        driver = new ChromeDriver();
    }

    @Test(priority = 1)
    public void verifygoogleTitle() {
        driver.get("http://www.google.com");
        Assert.assertEquals("Google", driver.getTitle());
    }

    @Test(priority = 2)
    public void verifyyahooTitle() {
        driver.get("https://in.yahoo.com");
        Assert.assertEquals("Yahoo", driver.getTitle());
    }

    @Test(priority = 3)
    public void verifybankofindiaTitle() {
        driver.get("http://www.bankofindia.co.in/english/home.aspx");
        Assert.assertEquals("Bank Of India - Home", driver.getTitle());
    }

    @AfterClass
    public void closeBrowser() {
        driver.close();
    }

}

My testng.xml is following: 我的testng.xml如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
  <test name="Test">
    <classes>
      <class name="package1.Example1"/>

    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

[UPDATE] Extended Logs : [更新]扩展日志:

在此处输入图片说明

I had similar problem. 我有类似的问题。 testng.xml was running fine if I run it from Eclipse but when I run the same from command prompt ; 如果我是从Eclipse运行的,但是testng.xml运行良好,但是从命令提示符运行的时候; it gave the result as 0 tests run, there was no errors. 进行0次测试后得出结果,没有错误。

My issue was in my classpath setting. 我的问题是在我的类路径设置中。 I had kept all my TestNG jar files in a separate folder (to organize better) in eclipse project's lib directory while the rest of my jar files were directly in the lib directory. 我已经将所有TestNG jar文件保存在eclipse项目的lib目录中的一个单独的文件夹中(以便更好地组织),而其余的jar文件则直接位于lib目录中。 When I added the lib as well to my classpath it worked fine. 当我将lib也添加到我的类路径中时,它运行良好。

set classpath = D:\\workspace\\SeleniumTrials\\bin;D:\\workspace\\SeleniumTrials\\lib\\TestNG*;D:\\workspace\\SeleniumTrials\\lib* java org.testng.TestNG testng.xml 设置类路径= D:\\ workspace \\ SeleniumTrials \\ bin; D:\\ workspace \\ SeleniumTrials \\ lib \\ TestNG *; D:\\ workspace \\ SeleniumTrials \\ lib * java org.testng.TestNG testng.xml

Let me address your question here with a few points: 让我在这里简单说明您的问题:

  1. If at all we are using maven, there is no need to install (add TestNG libraries) TestNG seperately (manually) either by Install New Software or Eclipse Market Place . 如果我们完全使用maven,则不需要通过Install New SoftwareEclipse Market Place单独(手动)安装(添加TestNG库)TestNG。 Instead we can simply specify the TestNG dependency in the pom.xml as follows: 相反,我们可以简单地在pom.xml指定TestNG依赖项,如下所示:

 <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>6.8</version> <scope>test</scope> </dependency> 

Advantages: maven-surefire-plugin does all the downloading & configuration for us. 优点: maven-surefire-plugin为我们完成了所有下载和配置。

  1. Now, we have got 4 optional ways to execute the Testcase as follows: 现在,我们有4种可选的方法来执行Testcase,如下所示:

A. Run As TestNG Test (Eclipse, through .java file) A. Run As TestNG Test (Eclipse,通过.java文件)

B. Run As TestNG Suite (Eclipse, through testng.xml) B.以Run As TestNG Suite (Eclipse,通过testng.xml)

C. Run As maven test (Eclipse, through pom.xml) C. Run As maven test (Eclipse,通过pom.xml)

D. Command-line option. D.命令行选项。

For command line execution: a. 对于命令行执行: We have to specify in pom.xml where to find the testng.xml . 我们必须在pom.xml中指定在哪里找到testng.xml For example: 例如:

 <suiteXmlFiles> <suiteXmlFile>${suiteXmlFile}</suiteXmlFile> </suiteXmlFiles> 

To achieve this, 为达到这个,

b. We have to move the testng.xml to src/main/resources 我们必须将testng.xml移到src/main/resources

c. C。 Through command-line change directory to project folder. 通过命令行将目录更改为项目文件夹。

d. d。 Flush out previous dependencies. 清除以前的依赖项。

e. Install the necessary dependencies. 安装必要的依赖项。

f. F。 Install build & execute testcase. 安装构建并执行测试用例。

Let me know if this answers your question. 让我知道这是否回答了您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM