2017-05-30 25 views
0

我是Selenium Cucumber的新手,嘗試使用Eclipse設置基本的Selenium Cucumber JVM,但是當我將Testrunner作爲JUnit運行時,註釋缺失,我需要手動在步驟中添加測試步驟定義。下面是我的特徵& JUnit測試轉輪Selenium - Cucument JUnit Test Runner - 沒有得到註釋

Feature: Gmail Login 
@Scenario1 
Scenario: User logs into GMail 
Given Open Browser 
When Enter gmail link 
Then Enter login details 

TestRunner.java 

package cucumberTest; 
import org.junit.runner.RunWith; 
import cucumber.api.CucumberOptions; 
import cucumber.api.junit.Cucumber; 
@RunWith(Cucumber.class) 
@CucumberOptions(features = "C:\\XXXX-PATH\\Feature" 
    ,glue={"stepDefinition"}, 
     tags={"@Scenario1"}, 
     monochrome=true 
     ) 
public class TestRunner { 

} 

當我執行TestRunner.java作爲JUnit中,段缺少註釋,因此步驟定義需要手動寫入 1方案(1未定義) 4步驟(4未定義) 可以實現失蹤與下面的代碼片段步驟:

Given("^Open Browser$",() -> { 
// Write code here that turns the phrase above into concrete actions 
throw new PendingException(); 
}); 

When("^Enter gmail link$",() -> { 
// Write code here that turns the phrase above into concrete actions 
throw new PendingException(); 
}); 

能有人幫我

<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>cucmber_test</groupId> 
    <artifactId>cucmber_test</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <build> 
     <sourceDirectory>src</sourceDirectory> 
     <plugins> 
      <plugin> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>3.6.1</version> 
       <configuration> 
        <source>1.8</source> 
        <target>1.8</target> 
        <fork>true</fork> 
       <executable>C:\Program Files\Java\jdk1.8.0_111\bin\javac.exe</executable> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
    <dependencies> 
     <dependency> 
    <groupId>info.cukes</groupId> 
    <artifactId>cucumber-java</artifactId> 
    <version>1.2.3</version> 
    <scope>test</scope> 
</dependency> 
<dependency> 
    <groupId>info.cukes</groupId> 
    <artifactId>cucumber-junit</artifactId> 
    <version>1.2.3</version> 
    <scope>test</scope> 
</dependency> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>4.12</version> 
     </dependency> 
     <dependency> 
      <groupId>commons-logging</groupId> 
      <artifactId>commons-logging</artifactId> 
      <version>1.2</version> 
     </dependency> 
<dependency> 
    <groupId>info.cukes</groupId> 
    <artifactId>cucumber-junit</artifactId> 
    <version>1.0.2</version> 
    <scope>test</scope> 
</dependency> 
<dependency> 
    <groupId>org.seleniumhq.selenium</groupId> 
    <artifactId>selenium-java</artifactId> 
    <version>2.47.1</version> 
</dependency> 
    </dependencies> 
</project> 
+0

那麼最近你遇到的實際/實際問題/錯誤/困難是什麼? 'JUnit'的'annotations'被Cucumber'特徵'文件中的特徵描述所取代。感謝 – DebanjanB

+0

您需要在stepDefinition類文件中定義@given和「@when」方法;通過複製建議的確切語法 – kushal

+0

感謝您的迴應,我沒有得到testrunner中建議的準確語法,@given沒有創建,只有給定創建,因此我需要在StepDefinition中手動添加@語法。猜猜我缺少任何版本 – Gayathri

回答

0

這可能是因爲您正在使用Java 8 lambda樣式的步驟定義。在Java 8樣式步驟定義中,不需要@符號。這也不是問題。您可以運行腳本並且不會影響執行。請查看鏈接https://cucumber.io/docs/reference/jvm瞭解更多詳情。