Selenium Webdriver:如何在终端(在MAC中)中运行testNG.xml文件?

我已经在MAC系统中创建了一个Maven-testNG项目。我已经创建了一个testSuite,现在我想使用 Terminal 运行testNG.xml文件。有什么方法可以运行此xml文件吗?

Selenium Webdriver:如何在终端(在MAC中)中运行testNG.xml文件?

testNG.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" verbose="2">
    <test name="Test">
        <classes>
            <class name="com.Live.testcase.TC0001_Signup" />
            <class name="com.Live.testcase.TC0002_SoleProprietorship" />
            <class name="com.Live.testcase.TC0003_Login" />
            <class name="com.Live.testcase.TC0004_ForgotPassword" />
            <class name="com.Live.testcase.TC0005_LLC" />
        </classes>
    </test> <!-- Test -->
</suite> <!-- Suite -->

Pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.learnautomation</groupId>
    <artifactId>com.learnautomation.selenium</artifactId>
    <version>0.0.1-snAPSHOT</version>

    <properties>
        <suitXmlFile>src/main/resources/testng.xml</suitXmlFile>
        <skipTests> false </skipTests>
    </properties>

    <build>
        <plugins>
            <plugin>

                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <compilerVersion>1.8</compilerVersion>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M3</version>
                <configuration>
                    <testFailureIgnore>true</testFailureIgnore>

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


                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>

        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.141.59</version>
        </dependency>


        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-server -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-server</artifactId>
            <version>3.14.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.13</version>
        </dependency>


        <!-- https://mvnrepository.com/artifact/jexcelapi/jxl -->
        <dependency>
            <groupId>jexcelapi</groupId>
            <artifactId>jxl</artifactId>
            <version>2.4.2</version>
        </dependency>


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


        <!-- https://mvnrepository.com/artifact/com.aventstack/extentreports -->
        <dependency>
            <groupId>com.aventstack</groupId>
            <artifactId>extentreports</artifactId>
            <version>3.1.5</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.10-FINAL</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/log4j/log4j -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

    </dependencies>

</project>

注意:我在互联网上看到了很多选择。主要是关于通过命令行(Windows计算机)运行代码,而一些不是maven项目的建议意味着简单的项目,请转至库部分并运行命令。

qwer21212009 回答:Selenium Webdriver:如何在终端(在MAC中)中运行testNG.xml文件?

是的,您可以从终端运行testng.xml文件。您应该在计算机中安装maven。遵循以下命令会有所帮助。

$ brew install maven

之后,您只需使用mvn命令即可​​在项目中执行Maven目标。如果您已相应配置Pom.xml文件,则以下命令将执行您的testng.xml文件

$ cd path/to/your/project
$ mvn test
,

正如我所说,我的testng文件位于build文件夹中,因此我必须在<suiteXmlFile>build/${suiteFile}</suiteXmlFile>中给出路径

Pom.xml

中进行了一些更改
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.0.0-M4</version>
            <configuration>
                <suiteXmlFiles>
                    <suiteXmlFile>build/${suiteFile}</suiteXmlFile>
                </suiteXmlFiles>
            </configuration>
        </plugin>
    </plugins>
</build>

运行命令:

$ cd路径/到/您的/项目

$ mvn test -DsuiteFile=testng.xml

$ mvn clean test -DsuiteFile=testng.xml

参考youtube链接: https://www.youtube.com/watch?v=lQCyVy-g1e8&t=436s


注意:

如果您的testng.xml文件不属于任何文件夹,而您只想每次调用testng.xml,则项目中没有其他xml文件。

简单地放置<suiteXmlFile>testng.xml</suiteXmlFile> 运行命令

$ cd路径/到/您的/项目

$ mvn test

本文链接:https://www.f2er.com/3112456.html

大家都在问