【问题标题】:Maven testNg project building success but not running in command promptMaven testNg 项目构建成功但未在命令提示符下运行
【发布时间】:2018-07-16 10:37:58
【问题描述】:

请帮我运行这个简单的例子。我想通过命令提示符打开浏览器完全构建成功但不在cmd(命令行)中运行

   public class Hello {
WebDriver driver;

@Test
public void a() {
    System.setProperty("webdriver.chrome.driver",
            "C:\\Users\\PoojaPatange\\Downloads\\workfolder\\chromedrive\\chromedriver.exe");
    driver = new ChromeDriver();
    driver.manage().window().maximize();
    driver.get("https://ar-ae.citrusstv.com");
}
}

pom.xml 文件:

<dependencies>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.11.0</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.testng/testng -->
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.9.13.6</version>

    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
    <dependency>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.7.0</version>
    </dependency>

    <dependency>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.20.1</version>
    </dependency>

enter image description here

请帮我运行这个简单的例子。我想通过命令提示符打开浏览器:

图片:

【问题讨论】:

  • 什么没有运行,你正在尝试使用哪个命令。

标签: java maven testng


【解决方案1】:

尝试在命令行中运行以下命令来运行您的测试:

0。在 maven 项目中运行所有测试类

  mvn test 

1.运行单个测试:

mvn -Dtest=TestClassName#testCaseName test

2。 runningalltests(在课堂上):

mvn -Dtest=TestClassName test

3. (如果使用 testNg)通过测试套件运行

mvn -Dsurefire.suiteXmlFiles=src/test/java/com/testsuites/testsuitAll.xml test

同时添加你的 pom:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19.1</version>
        </plugin>
    </plugins>
</build>

评论中问题的补充:

这里是如何通过 testng xml 文件调用一个或多个类:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite">
    <test name="Run">
        <classes>
            <class name="path.to.your.class.AND_ITS_NAME"/>
        </classes>
    </test>
</suite>

希望这会有所帮助,

【讨论】:

  • 谢谢大家的工作,真棒,你能帮我解释一下如何在jenkins中运行项目
  • 如果我想从 testng thyen 的多个类文件中只选择一个类,我该如何使用这个 mvn -Dsurefire.suiteXmlFiles=src/test/java/com/testsuites/testsuitAll.xml 测试跨度>
  • 我会写下答案,会扩展它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-03-02
  • 1970-01-01
  • 2019-04-19
  • 1970-01-01
  • 1970-01-01
  • 2019-05-29
  • 2010-10-12
相关资源
最近更新 更多