尝试 运行 Maven 项目时,Selenium WebDriver / Cucumber 测试未执行

Selenium WebDriver / Cucumber Tests are not getting executed when tried to run Maven Project

我正在尝试使用 selenium/java 为我的自动化脚本 运行 Maven 项目。但是,当我执行 mvn test 命令时,测试没有得到 运行。请让我知道当我尝试 运行 maven 项目时,黄瓜测试没有被执行的问题。

[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------< KSAEpic3MavenProj:KSAEpic3 >---------------------
[INFO] Building KSAEpic3 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ KSAEpic3 -
--
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ KSAEpic3 ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ KS
AEpic3 ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] Copying 5 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ KSAEpic
3 ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ KSAEpic3 ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.628 s
[INFO] Finished at: 2018-07-26T08:57:14+04:00
[INFO] ------------------------------------------------------------------------

下面是我的 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>KSAEpic3MavenProj</groupId>
  <artifactId>KSAEpic3</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>KSAEpic3</name>

  <dependencies> 
 <dependency> 
 <groupId>junit</groupId> 
 <artifactId>junit</artifactId>
 <version>4.12</version> 
 <scope>test</scope> </dependency> 

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

 <dependency>
 <groupId>info.cukes</groupId>
 <artifactId>cucumber-java</artifactId>
 <version>1.2.4</version> 
 <scope>test</scope>
 </dependency> 

 <dependency> 
 <groupId>info.cukes</groupId> 
 <artifactId>cucumber-junit</artifactId> 
 <version>1.2.4</version>
 <scope>test</scope>
 </dependency> 

    <dependency>
    <groupId>com.aventstack</groupId>
    <artifactId>extentreports</artifactId>
    <version>3.0.6</version>
    <scope>provided</scope>
</dependency>

 <dependency>
    <groupId>com.vimalselvam</groupId>
    <artifactId>cucumber-extentsreport</artifactId>
    <version>3.0.1</version>
</dependency>

<dependency>
    <groupId>org.freemarker</groupId>
    <artifactId>freemarker</artifactId>
    <version>2.3.23</version>
</dependency>

<dependency>
    <groupId>org.mongodb</groupId>
    <artifactId>bson</artifactId>
    <version>3.2.2</version>
</dependency>

<dependency>
    <groupId>commons-lang</groupId>
    <artifactId>commons-lang</artifactId>
    <version>2.6</version>
</dependency>

<dependency>
    <groupId>ojdbc14</groupId>
    <artifactId>ojdbc14</artifactId>
    <version>10.2.0.3.0</version>
</dependency>

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

</dependency>

 </dependencies> 


</project>

当 运行 来自 IDE -

时记录
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building KSAEpic3 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ KSAEpic3 ---
[debug] execute contextualize
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ KSAEpic3 ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ KSAEpic3 ---
[debug] execute contextualize
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 5 resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ KSAEpic3 ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.10:test (default-test) @ KSAEpic3 ---
[INFO] Surefire report directory: D:\Maven WorkSpace\KSAEpic3\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12.751s
[INFO] Finished at: Thu Jul 26 09:41:48 GST 2018
[INFO] Final Memory: 8M/19M
[INFO] ------------------------------------------------------------------------

亚军Class

package testrunner;

import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(

        plugin={"pretty", "html:target/cucumber", "json:target/JSON/Output.json"},      
                features={"D:/KSA-Online Banking-AutomationFramework/Epic2Maven/src/test/resources/features"},

//      plugin={"com.cucumber.listener.ExtentCucumberFormatter:"},
tags={"@SI_TransferBtwAccounts"},

        glue={"stepdefinition"}

        )

public class Epic2TestRunner {

}

专题文件 -

@SI_TransferBtwAccounts
Feature: Verify that SI is setup successfully Between the accounts and record is inserted in DB
Scenario: Verify that SI is setup successfully between the accounts
Given When browser is launched and KSA URL is loaded
    When STAFFUser1 logins to application
    When Password is entered
    When clicked on Login button
    When clicks on Pay&Transfer Icon
    When clicks on Transfer link
    When clicks on StandingInstruction link
     When selects TransferBtwAccount option
      When enters Trnsfrbtwaccamount in the field
    When FromandToDate are captured
       When Terms&Conditions are checked
    When clicked on continue button
       When StartandEnd Dates are verified in pre-confirmation screen
    When Entered OTP
    When clicked on Confirm button
    When Captured the Reference number
    When Record is displayed in StandingInstruction DB
    When record is displayed in the Standing Instruction menu
    Then user should be logged out of application.

StepDefinition 文件 -

public class Transfer_SI_BtwAccounts  extends Browser_Initialization {

    private static String FromDate , ToDate, SIRefnum, refnumber, PurposeofTransferText, amount;

    @When("^STAFFUser(\d+) logins to application$")
    public void staffuser_logins_to_application(int arg1) throws Throwable {
        // Write code here that turns the phrase above into concrete actions
try {

            c_InputText("KSAOnlineBanking_Login_Username", GetPropertValue("StaffUssername"));

        } catch (Exception e ) {
            Assert.fail("unable to enter username"); 

        }
    }

    @When("^selects TransferBtwAccount option$")
    public void selects_TransferBtwAccount_option() throws Throwable {
        // Write code here that turns the phrase above into concrete actions
       try {

           Thread.sleep(10000);

            c_click("TransferList");

            c_click("SI-BTWACC");

       } catch (Exception e ) {
           Assert.fail("unable to select option");
       }
    }

    @When("^enters Trnsfrbtwaccamount in the field$")
    public void enters_Trnsfrbtwaccamount_in_the_field() throws Throwable {
        // Write code here that turns the phrase above into concrete actions
      try {
          Thread.sleep(6000);

          c_InputText("TBTWACCAmountField",GetPropertValue("EnterAmount"));

      } catch (Exception e ) {
          e.printStackTrace();
      }
    }

如果没有明确指定,测试的名称 class 很重要。

默认情况下,Surefire 插件会自动包含所有测试 classes following wildcard patterns:

"**/Test*.java" - includes all of its subdirectories and all Java filenames that start with "Test".
"**/*Test.java" - includes all of its subdirectories and all Java filenames that end with "Test".
"**/*Tests.java" - includes all of its subdirectories and all Java filenames that end with "Tests".
"**/*TestCase.java" - includes all of its subdirectories and all Java filenames that end with "TestCase".

您的 class 名为 Epic2TestRunner.java,因此默认情况下无法识别。将其重命名为 TestEpic2Runner.javaEpic2RunnerTest.java 将是一个可能的解决方案。