2017-04-02 4 views
2

내 Selenium Java + TestNG 프로젝트에서 Cucumber를 시도하고 있습니다. 일단 빈 단계 정의가있는 .feature 파일을 실행하면 붙여 넣기를 단계 정의 클래스에 복사 할 수있는 스 니펫을 가져와야합니다. 그러나 나는 상자 밖에서 사용할 수없는 이상한 포맷을 가지고있다.Cucumber에서 발췌문 Java TestNG가 이상하게 보입니다.

Given@Given이어야합니다. 맞습니까? public void()은 없습니다.

무엇이 원인 일 수 있습니까? 고맙습니다.

2 Scenarios (2 undefined) 
 
5 Steps (5 undefined) 
 
0m0.000s 
 
You can implement missing steps with the snippets below: 
 
Given("^User is on Home Page$",() -> { 
 
    // Write code here that turns the phrase above into concrete actions 
 
    throw new PendingException(); 
 
}); 
 
When("^User enters UserName and Password$",() -> { 
 
    // Write code here that turns the phrase above into concrete actions 
 
    throw new PendingException(); 
 
}); 
 
Then("^He can visit the practice page$",() -> { 
 
    // Write code here that turns the phrase above into concrete actions 
 
    throw new PendingException(); 
 
}); 
 
When("^User LogOut from the Application$",() -> { 
 
    // Write code here that turns the phrase above into concrete actions 
 
    throw new PendingException(); 
 
}); 
 
Then("^he cannot visit practice page$",() -> { 
 
    // Write code here that turns the phrase above into concrete actions 
 
    throw new PendingException(); 
 
});

이것은 내 glue file

package glue; 
 
import java.io.IOException; 
 
import org.testng.annotations.Test; 
 
import cucumber.api.CucumberOptions; 
 
import cucumber.api.testng.AbstractTestNGCucumberTests; 
 
import cucumber.api.testng.TestNGCucumberRunner; 
 
@Test(groups = "cucumber") 
 
@CucumberOptions(features = "C:\\Users\\workspace\\cucumber\\src\\test\\java\\feature\\logintest.feature", 
 
glue = "C:\\Users\\workspace\\cucumber\\src\\test\\java\\glue\\Glue.java", 
 
plugin = {"html:C:\\Users\\workspace\\cucumber\\logs"}) 
 
    
 
public class Glue extends AbstractTestNGCucumberTests { 
 
    @Test(groups = "cucumber", description = "Runs Cucumber Features") 
 
    public void runCukes() throws IOException { 
 
     
 
    } 
 
}

이 내 .feature 파일입니다

Feature: Login 
 
Scenario: Successful Login with Valid Credentials 
 
Given User is on Home Page 
 
When User enters UserName and Password 
 
Then He can visit the practice page 
 
Scenario: Successful LogOut 
 
When User LogOut from the Application 
 
Then he cannot visit practice page

이 내 종속

<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-testng --> 
 
<dependency> 
 
    <groupId>info.cukes</groupId> 
 
    <artifactId>cucumber-testng</artifactId> 
 
    <version>1.2.5</version> 
 
</dependency> 
 
    
 
<!-- https://mvnrepository.com/artifact/info.cukes/gherkin --> 
 
<dependency> 
 
    <groupId>info.cukes</groupId> 
 
    <artifactId>gherkin</artifactId> 
 
    <version>2.12.2</version> 
 
</dependency> 
 

 
<dependency> 
 
    <groupId>info.cukes</groupId> 
 
    <artifactId>cucumber-java8</artifactId> 
 
    <version>1.2.5</version> 
 
    <scope>test</scope> 
 
</dependency>

답변

2

그 아래 stepDefintion 파일의 형식 (자바 컴파일러 확인이 당신은, 오이 java8 종속성을 사용하는 것입니다 버전은 1.8이어야합니다).

@Given 주석 오이 자바에있을 것입니다

주석, 나는 내 컴퓨터의 작업에서 실행

import cucumber.api.java8.En; 

public class stepDefinitions implements En{ 

public stepDefinitions(){ 
    Given("^User is on Home Page$",() -> { 
     // Write code here that turns the phrase above into concrete actions 
     System.out.println("Test1"); 
    }); 

    When("^User enters UserName and Password$",() -> { 
     // Write code here that turns the phrase above into concrete actions 
     System.out.println("Test2"); 
    }); 

    Then("^He can visit the practice page$",() -> { 
     // Write code here that turns the phrase above into concrete actions 
     System.out.println("Test3"); 
    }); 

    When("^User LogOut from the Application$",() -> { 
     // Write code here that turns the phrase above into concrete actions 
     System.out.println("Test4"); 
    }); 

    Then("^he cannot visit practice page$",() -> { 
     // Write code here that turns the phrase above into concrete actions 
     System.out.println("Test5"); 
    }); 
    } 
} 

오이 java8에서 일을 시도하고 작동하는지 알려 드릴 것입니다 감안할 때 너를 위해서.

참조 용 링크 : http://codoid.com/cucumber-lambda-expressions/