- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们设法在 Eclipse 中使用 JBehave 创建和运行具有国际化故事的测试。
一切顺利。
但是当我们尝试使用 maven 插件运行它们时,我们无法解决编码问题(例如,不是从故事中读取“场景”,而是得到“场景”:显然是 UTF8 编码问题) .
有人找到了让 JBehave 使用 maven 插件阅读 UTF8 中的故事的方法吗?
我们已经尝试过的:
<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">
...
<properties>
<jbehave.version>3.6.5</jbehave.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<resource.encoding>UTF-8</resource.encoding>
</properties>
<build>
<testOutputDirectory>target/classes</testOutputDirectory>
<testResources>
<testResource>
<directory>src/test/resources</directory>
</testResource>
<testResource>
<directory>src/test/story</directory>
</testResource>
</testResources>
<plugins>
...
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
<additionalBuildcommands>
<buildcommand>com.google.gdt.eclipse.core.webAppProjectValidator</buildcommand>
</additionalBuildcommands>
<additionalProjectnatures>
<projectnature>com.google.gwt.eclipse.core.gwtNature</projectnature>
</additionalProjectnatures>
<classpathContainers>
<classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
</classpathContainers>
<additionalConfig>
<file>
<name>.settings/org.eclipse.core.resources.prefs</name>
<content>
<![CDATA[eclipse.preferences.version=1
encoding/<project>=UTF-8]]>
</content>
</file>
</additionalConfig>
</configuration>
</plugin>
<plugin>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-maven-plugin</artifactId>
<version>${jbehave.version}</version>
<executions>
<execution>
<id>run-stories-as-embeddables</id>
<phase>test</phase>
<configuration>
<scope>test</scope>
<includes>
<include>**/*Story.java</include>
</includes>
<ignoreFailureInStories>true</ignoreFailureInStories>
<ignoreFailureInView>false</ignoreFailureInView>
</configuration>
<goals>
<goal>run-stories-as-embeddables</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-jbehave-site-resources</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<overwriteReleases>false</overwriteReleases>
<overwriteSnapshots>true</overwriteSnapshots>
<artifactItems>
<artifactItem>
<groupId>org.jbehave.site</groupId>
<artifactId>jbehave-site-resources</artifactId>
<version>3.1.1</version>
<type>zip</type>
<outputDirectory>
${project.build.directory}/jbehave/view
</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
<execution>
<id>unpack-jbehave-reports-resources</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<overwriteReleases>false</overwriteReleases>
<overwriteSnapshots>true</overwriteSnapshots>
<artifactItems>
<artifactItem>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-core</artifactId>
<version>${jbehave.version}</version>
<outputDirectory>
${project.build.directory}/jbehave/view
</outputDirectory>
<includes>
**\/*.css,**\/*.ftl,**\/*.js
</includes>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
...
<!-- JBehave Dependencies -->
<dependency>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-core</artifactId>
<version>${jbehave.version}</version>
</dependency>
<!-- Test Frameworks Dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.8.4</version>
<scope>test</scope>
</dependency>
</dependencies>
最佳答案
我在继承 org.jbehave.core.io.LoadFromClasspath 类方面取得了一些成功,我在我的配置中将其用作故事加载器,即
MostUsefulConfiguration().useStoryLoader(new LoadFromClasspathUtf8());
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.io.IOUtils;
import org.jbehave.core.io.InvalidStoryResource;
import org.jbehave.core.io.LoadFromClasspath;
public class LoadFromClasspathUtf8 extends LoadFromClasspath {
public LoadFromClasspathUtf8(Class<?> loadFromClass) {
super(loadFromClass);
}
public LoadFromClasspathUtf8(ClassLoader classLoader) {
super(classLoader);
}
@Override
public String loadResourceAsText(String resourcePath) {
InputStream stream = resourceAsStream(resourcePath);
try {
return IOUtils.toString(stream, "UTF-8");
} catch (IOException e) {
throw new InvalidStoryResource(resourcePath, stream, e);
}
}
}
关于Maven JBehave : encoding stories UTF8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10429163/
我使用 jBehave 和 WebDriver 创建了一些测试。 当我通过 Maven 执行它们时,执行是安全的: 测试 1 打开导航 执行第一个故事的所有步骤 关闭导航 测试 2 打开导航 执行第二
我想从 JBehave 生成一份报告,其中仅列出每个场景的名称和通过/失败状态。如果根据场景结果给出故事的通过/失败状态(如果所有场景都通过故事通过),则可获得奖励积分。像这样的东西: PASS:
我的故事情节如下 Scenario: Given user is on Login page When user types login details with xxx as user xxx as
我正在使用 JBehave 进行场景测试。 在使用教程时,我在 pom.xml 中收到如下错误 Missing artifact org.jbehave:jbehave-core:zip:resour
这是我可以开始工作的示例。 http://ivanz.com/2011/05/25/java-bdd-with-jbehave-and-watij-in-eclipse-with-junit/ 问题:
我在 eclipse 的 jbehave .feature 文件中使用 JUnitReportingRunner,如下所示。但仅运行 BeforeStories 和 AfterStories,并且 .
当我运行在 eclipse 中编写的 jbehave IT 测试时出现此异常。 org.jbehave.core.io.storyresourcenotfound 我在 test/java/packa
以下步骤: 创建新的 Maven Java 项目 下载 JBehave JAR 文件版本 3.6.8 并将其添加到配置构建路径 > 添加外部 jar 并添加 JUnit4 通过帮助安装 Eclipse
我不知道为什么,但 JBehave 没有考虑给定故事中的失败。如果给定故事发生故障,它将不会执行该故事的其余步骤,但会执行给定故事的其余步骤。这是一个例子: GivenStories: stories
我在 JBehave 中有一个“何时”,在某些情况下应该抛出异常。但是,我找不到任何有关如何处理此问题的文档。这是我的场景: 假设游戏有 6 个现有赌注,且游戏的最大赌注为 6当用户下注时 没有 th
我正在尝试创建并运行一个简单的 JUnitStory 来运行 .story 文件。 我有这个: class Scenario1 extends JUnitStory { @Delegate M
我已将 jbehave 与 Selenium 集成。我正在通过命令行运行测试,如下所示 C:\eclipse_workspace\MySeleniumTests>mvn clean test -Dwe
想象一下我有以下jBehave故事: When I create servers with properties: | processor | ram | os | | i5 | 8
我已经创建了故事/场景。喜欢: Scenario: Create a new Firm Given a Firm Test When Firm Test is valid Then New Firm
您好,我有一个场景,我需要测试搜索服务是否返回正确的结果。所以我的故事看起来像这样: Narrative: In order to easily discover if a player is reg
我正在尝试实现一个简单的程序来学习如何使用 jBehave!!。该程序正在添加两个数字。我从这里安装了eclipse的插件 http://jbehave.org/eclipse-integration
我为 JBehave 自动测试编写了一些场景。这里需要写几个相似的场景,不同的是常量参数。 为了不复制很多脚本,我希望将参数添加到我的故事中,并使用不同的参数多次调用它。 我如何使用“GivenSto
我的情况是这样的: 我有一个包含多个场景的 JBehave 故事。每个场景都会写入一些文件,检查它们是否符合预期。然后下一个场景的 @BeforeScenario 导致框架删除输出文件。 当某些场景失
我在 eclipse 中使用 maven 有一个 Jbehave 和 selenium 项目。最初我是为一个故事做的,但现在我写了两个故事,我希望这两个故事在测试中运行。但只有一个故事文件通过程序。我
我正在使用 JBehave 编写 BDD 集成测试。 问题:JBehave 在执行单个步骤时清除对象(实例变量)的状态 代码:步骤定义: public class StepDefs { pri
我是一名优秀的程序员,十分优秀!