【问题标题】:How to Generate an executable solution for a MAVEN TESTNG Selenium-Webdriver framework如何为 MAVEN TESTNG Selenium-Webdriver 框架生成可执行解决方案
【发布时间】:2019-10-17 08:37:55
【问题描述】:

我正在使用 testNG 和 Selenium 对我的应用程序进行多项功能测试。 执行 mvn install 后,项目成功构建并生成包含所有类和 .jar 文件的目标文件,但此解决方案不可执行,因为我的框架不包含 main 方法,因为它是一个 TESTNG FRAMEWORK。

该文件如何可执行才能将其部署到较低的环境或使用任务调度程序运行解决方案!

这是针对使用 maven testng 和 selenium webdriver(PageObjectModel) 的 Web 应用程序的测试自动化框架

C:\Users\myuser\Documents\test\myapp\target>java -jar myapp-1.0-SNAPSHOT.jar

没有主清单属性,在 myapp-1.0-SNAPSHOT.jar 中

这是我尝试从生成的目标文件执行 jar 时得到的。

【问题讨论】:

  • 你可以使用maven执行目标来运行你的测试
  • 是的,我可以,但为了部署到较低的环境,在这种情况下,我需要一个可执行的解决方案目标文件

标签: maven selenium teamcity pom.xml


【解决方案1】:

我建议重新考虑您的方法,而不是运行可执行的 .jar,您应该 run testng.jar like:

java org.testng.TestNG /path/to/your/testng.xml

您可以创建一个具有public static void main() 声明的助手类,例如:

package com.example;

import org.testng.TestNG;

public class TestRunner {

    public static void main(String[] args) {
        TestNG testNG = new TestNG();
        testNG.setTestClasses(new Class[]{TestClass.class}); // replace TestClass with your actual class where your test methods live
        testNG.run();
    }
}

然后将下一个条目添加到您的 pom.xml 文件中

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.1.2</version>
            <configuration>
                <archive>
                    <index>true</index>
                    <manifest>
                        <addClasspath>true</addClasspath>
                    </manifest>
                    <manifestEntries>
                       <Main-Class>com.example.TestRunner</Main-Class>
                    </manifestEntries>
                </archive>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>test-jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

打包应用后,您将看到myapp-1.0-SNAPSHOT-tests.jar,它将是一个可执行文件。

更多信息:

【讨论】:

  • 感谢您的帮助,但不是主要方法找到测试但由于某种原因跳过它们================== ============================ 测试自动化脚本质量检查总测试运行:77,失败:0,跳过:77 配置失败:16,跳过:370 ===============================================
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-12-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-15
相关资源
最近更新 更多