我从不同方面调查了这个问题,但到目前为止还没有任何进展。我有一个项目,使用Cucumber for Java在JUnit上运行selenium驱动程序。我使用 Maven 。 这是运行测试的 TestRunner :
package com.task.lab;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
@CucumberOptions(features = "C:\\Users\\admin\\IdeaProjects\\bddtesting\\src\\test\\java\\com\\task\\lab\\features",
glue = "C:\\Users\\admin\\IdeaProjects\\bddtesting\\src\\test\\java\\com\\task\\lab\\steps")
public class TestRunner {
}
此处的功能文件:
Feature: Login to Gmail
Scenario Outline: login compose and delete letter
Given: User is on SignIn page
When: User enters <Email> and <Password>
Then: User sends letter to <Receiver> and alert is displayed letter is sent
Examples:
|Email |Password |Receiver
|testaccount@gmail.com |okokokokok |testtest@gmail.com
|testaccount@gmail.com |okokokokok |testtest@gmail.com
的pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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>com.task.lab.bddtesting</groupId>
<artifactId>bddtesting</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-support</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-core</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm</artifactId>
<version>1.2.5</version>
<type>pom</type>
</dependency>
</dependencies>
最后我的Steps.Defs类:
package com.task.lab.steps;
import com.task.lab.decorator.bo.businessobjects.GmailMessage;
import com.task.lab.decorator.bo.businessobjects.Login;
import com.task.lab.driver.DriverObject;
import com.task.lab.propertyreader.ReadPropertyFile;
import cucumber.api.java.After;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
public class StepDefs {
private Login login = new Login();
@Given("^User is on SignIn page$")
public void openSignInPage(){
LOG.info("Logging in");
DriverObject.getDriver();
DriverObject.getDriver().get(ReadPropertyFile.readGmailURL());
}
@When("^User enters (\\S+) and (\\S+)$")
public void enterCredentials(String email, String password) throws Throwable {
login = new Login();
login.login(email, password);
}
@Then("^User sends letter to (\\S+) and alert is displayed letter is sent$")
public void composeLetter(String receiver){
GmailMessage gmail = new GmailMessage();
gmail.sendMessage(receiver);
}
@After
public void closeBrowser(){
DriverObject.releaseThread();
}
}
当我尝试从窗口运行TestRunner时,我收到错误未找到测试。正如我之前调查的那样,原因可能是我运行了测试单元,而不是Main类。因此,我将此项目的Intelij Setting重新配置为从 Cucumber for Java 运行,并将Main类指定为cucumber.api.cli.Main
。但是,这给了我另一个错误Test framework quit unexpectedly
。我也尝试过只运行功能文件,在这种情况下测试是绿色的,但事实上,没有传递任何方案或步骤,因为控制台中的输出显示:
0 Scenarios
0 Steps
0m0,000s
我还重新安装了我的Intelij到Ultimate版本,但结果是一样的。有人可以帮我看看我做错了吗?
答案 0 :(得分:1)
所以,我怀疑这个问题很小。在我未来的文件中,我删除了&#34;:&#34;并用垂直线关闭我的桌子&#34; |&#34;:
fetch(url)
.then(res => res.json())
.then(res => return res.articles.map(article => article.description) )
.then(res => fetch(otherUrl, { descriptions: res }))
.then(res => {
})
像魅力一样工作。