代码之家  ›  专栏  ›  技术社区  ›  Aditya

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

  •  1
  • Aditya  · 技术社区  · 6 年前

    我试图用Sele/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] ------------------------------------------------------------------------
    

    转轮类

    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 回复  |  直到 6 年前
        1
  •  3
  •   SubOptimal    6 年前

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

    默认情况下,Surefire插件将自动包含 following wildcard patterns:

    “**/test *.java”包含所有的子目录和从“test”开始的所有Java文件名。
    “**/*Test.java”包括所有的子目录和所有用“test”结束的Java文件名。
    “**/*Test.java”包括所有的子目录和所有用“测试”结束的Java文件名。
    “**/*TestCase.java”-包括所有的子目录和所有的“用TestCase'结束的Java文件名”。

    你的班级叫 Epic2TestRunner.java 因此,默认情况下无法识别。将其重命名为 TestEpic2Runner.java Epic2RunnerTest.java 可能的解决办法。