java - 执行功能文件时控制台不显示任何打印输出
问题描述
我正在尝试将步骤定义中编写的输出打印到 Eclipse 控制台中。但我在控制台中看不到任何输出
我已将以下这些依赖项添加到我的项目中,并且我还在跑步者类中包含了“漂亮”和单色:true
<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>sampleProject</groupId>
<artifactId>sampleProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>sampleProject</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-core -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-core</artifactId>
<version>4.7.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.8</version>
<scope>system</scope>
<systemPath>${java.home}\lib\tools-1.8.0.jar</systemPath>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>4.7.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>4.7.1</version>
</dependency>
<dependency>
<groupId>net.sourceforge.cobertura</groupId>
<artifactId>cobertura</artifactId>
<version>2.1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.masterthought</groupId>
<artifactId>cucumber-reporting</artifactId>
<version>4.8.0</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-jvm-deps</artifactId>
<version>1.0.6</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-jvm -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-jvm</artifactId>
<version>4.7.1</version>
<type>pom</type>
</dependency>
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>gherkin</artifactId>
<version>5.1.0</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-html</artifactId>
<version>0.2.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit-dep -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit-dep</artifactId>
<version>4.11</version>
<type>pom</type>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>compile</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-testng -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>4.7.1</version>
</dependency>
</dependencies>
</project>
例如,如果我在步骤定义中打印任何内容,例如 System.out.println("2+2");
当我运行此代码时,仅在控制台中看到以下行
[RemoteTestNG] detected TestNG version 6.14.3
Starting ChromeDriver 76.0.3809.68 (420c9498db8ce8fcd190a954d51297672c1515d5-refs/branch-heads/3809@{#864}) on port 9315
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
Aug 02, 2019 11:54:35 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Feature: Check addition in Google calculatorcontent
In order to verify that Google calculator work correctly
As a user of Google
I should be able to get correct addition result
Scenario: Addition # src/main/java/Features/sample.feature:6
Given I open Google # SampleStepDef.I_open_google()
When I enter "2+2" in search textbox # SampleStepDef.I_enter_in_search_textbox(String)
Then I should get result as "4" # SampleStepDef.I_should_get_correct_result(String)
PASSED: runScenario("Addition", "Check addition in Google calculatorcontent")
Runs Cucumber Scenarios
===============================================
控制台不显示除此之外的任何其他内容。
它也不会显示通过或失败的场景和步骤的数量,例如
1 Scenarios ([33m1 undefined[0m)
3 Steps ([33m3 undefined[0m)
0m0.000s
这是我的 tesRunner 代码包 Runner;
import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;
@CucumberOptions(
features = "src/main/java/Features",
glue = {"StepDefinitions"},
// tags = "@SmokeTest",
monochrome = true,
dryRun = false,
strict = true,
plugin = {
"pretty",
"html:target/cucumber-reports/cucumber-pretty",
"json:target/cucumber-reports/CucumberTestReport.json",
"rerun:target/cucumber-reports/rerun.txt"
}
)
public class TestRunner extends AbstractTestNGCucumberTests {
}
和 stepDefinition 代码
package StepDefinitions;
import java.util.concurrent.TimeUnit;
import org.testng.Assert;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.By;
import io.cucumber.java.After;
import io.cucumber.java.Before;
import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
public class SampleStepDef {
protected WebDriver driver;
private static Logger Log = Logger.getLogger(Logger.class.getName());
@Before
public void setup() {
System.setProperty("webdriver.chrome.driver","C:\\Users\\Admin\\Downloads\\chromedriver.exe");
driver = new ChromeDriver();
}
@Given("^I open Google$")
public void I_open_google() {
//Set implicit wait of 10 seconds and launch google
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.get("https://www.google.co.in");
}
@When("^I enter \"([^\"]*)\" in search textbox$")
public void I_enter_in_search_textbox(String additionTerms) {
//Write term in google textbox
WebElement googleTextBox = driver.findElement(By.id("gbqfq"));
googleTextBox.sendKeys(additionTerms);
//Click on searchButton
WebElement searchButton = driver.findElement(By.id("gbqfb"));
searchButton.click();
}
@Then("^I should get result as \"([^\"]*)\"$")
public void I_should_get_correct_result(String expectedResult) {
//Get result from calculator
WebElement calculatorTextBox = driver.findElement(By.id("cwos"));
String result = calculatorTextBox.getText();
//Verify that result of 2+2 is 4
Assert.assertEquals(result, expectedResult);
driver.close();
}
@After
public void closeBrowser() {
driver.quit();
}
}
解决方案
对于 cucumber-jvm 4.5.0 及更高版本,为了在运行结束时查看汇总统计信息,您需要通过您在运行器类中定义的插件显式询问它。如果您添加“摘要”(因为您已经“漂亮”),您应该能够再次看到场景/步骤的总数和花费的时间。这已通过https://github.com/cucumber/cucumber-jvm/pull/1670改变
推荐阅读
- flutter - Flutter 不再工作,Xcode 构建需要很长时间,然后失败
- java - 使用 VOLLEY 将 onclickListener 放入 RecyclerViewAdapter 时,图像未显示在新 Activity 中
- php - 在 foreach 循环中排序
- email - 每封电子邮件在指定的时间延迟上触发
- javascript - react-native-webview 导航到 URL 列表?
- linux - 在一个命令中创建文件并写入文件
- javascript - {EASY} 快速 API 返回值字典错误
- prettier - 如何在 TypeScript 中为模板文字导入 Prettier 的 html 标签?
- sql - 关于SQL和NoSQL如何管理存储的问题
- c# - AppDomain.Unload 留下 RuntimeType+RuntimeTypeCache 对象/由于某种原因被拉出