当前位置: 首页 > 知识库问答 >
问题:

当尝试运行Maven项目时,Selenium WebDriver/Cucumber测试无法执行

赖浩荡
2023-03-14

我试图使用Selenium/Java为我的自动化脚本运行maven项目。但是,当我执行mvn test命令时,测试并没有运行。请让我知道当我尝试运行maven项目时,cucumber测试没有被执行的问题是什么。

[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>
[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] ------------------------------------------------------------------------
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.
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();
      }
    }

共有1个答案

秦彦君
2023-03-14

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

默认情况下,Surefire插件将自动包含具有以下通配符模式的所有测试类:

“**/test*.Java”-包括其所有子目录和以“test”开头的所有Java文件名。
“**/*test.Java”-包括其所有子目录和以“test”结尾的所有Java文件名。
“**/*test.Java”-包括其所有子目录和以“test”结尾的所有Java文件名。
“**/*testcase.Java”-包括其所有子目录和以“testcase”结尾的所有Java文件名。
“**/*testcase.Java”-包括其所有子目录和以“testcase”结尾的所有Java文件名。

您的类名为Epic2TestRunner.java,因此默认情况下无法识别它。将其重命名为testepic2runner.javaepic2runnertest.java是可能的解决方案。

 类似资料:
  • 有没有人能告诉我为什么我不能使用Maven运行任何测试。 已配置SureFire插件 在runner类下设置胶合代码 “测试”被追加到runner类 注意:如果我将文件作为Junit运行,那么它可以正确地运行所有场景。只有当我使用Maven运行它时,才不会运行任何测试。

  • 我正在尝试使用 maven build 作为运行配置在 eclipse 中运行cucumber测试。当我运行配置时,构建成功,但浏览器不调用。因此,测试未运行。测试被跳过,给出一个信息“没有什么可编译的 - 所有类都是最新的”。我能够通过将功能文件作为cucumber功能运行来成功运行相同的测试。 请告诉我为什么要跳过测试。也让我知道运行maven构建cucumber测试的步骤。下面是我使用的po

  • 这是我添加的公共类NewEmptyJUnitTest的代码{ 这是pom.xml文件 我一直收到这个错误:

  • 我试图按照本教程在IntelliJ中设置Maven JavaFX项目https://openjfx.io/openjfx-docs/#maven(带Maven的IntelliJ非模块化)但无论我做什么,它都失败了。 我一直在尝试很多互联网建议。我尝试在pom中设置VM变量,我确保JAVA\u HOME指向我的JDK 12目录,并检查项目结构中JDK的设置是否正确。 这是我的pom文件: 这是输出:

  • 我向Eclipse导入了一个新项目。这是一个maven项目。我没有任何编译器错误。我向eclipse添加了一个新的tomcat服务器,我还在项目运行时添加了该服务器。一切都应该没事的。但当我尝试运行一个项目时,我会得到运行时错误。 pro 09,2016 12:30:40 PM org.apache.Catalina.core.ContainerBase StartInterral严重:启动jav

  • 我有3个maven项目。项目1,项目2 为此,我在项目2 pom.xml文件中添加了这个 我的pom。Project3的xml是- 在项目3中,我添加了testng。xml文件来运行测试。现在如果我运行这个测试。xml文件,那么我所有的测试用例都成功运行了。如果我尝试使用maven测试运行测试用例,那么它会失败。 我已经在下面的pom文件中包含了testng.xml文件,以便使用maven运行te