- 浏览: 2551904 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
Jbehave(1) First Web Page Sample
1. jbehave totorial sample
use git bash on my win7 system, from the start menu, choose git bash
>pwd
>cd /d/book/jbehave
>git clone https://github.com/jbehave/jbehave-tutorial.git jbehave-tutorial
change the pom.xml, from
<properties>
<jbehave.core.version>3.6.SNAPSHOT</jbehave.core.version>
<jbehave.web.version>3.5.SNAPSHOT</jbehave.web.version>
<jbehave.site.version>3.1.1</jbehave.site.version>
</properties>
to
<properties>
<jbehave.core.version>3.5.1</jbehave.core.version>
<jbehave.web.version>3.4</jbehave.web.version>
<jbehave.site.version>3.1.1</jbehave.site.version>
</properties>
>mvn install
error messages:
[WARNING] Failed to run story etsy_search.story
org.jbehave.core.failures.UUIDExceptionWrapper: org.jbehave.core.failures.Before
OrAfterFailed: Method beforeStory (annotated with @BeforeStory in class org.jbeh
ave.web.selenium.PerStoryWebDriverSteps) failed: org.openqa.selenium.WebDriverEx
ception: Cannot find firefox binary in PATH. Make sure firefox is installed. OS
appears to be: VISTA
Build info: version: '2.5.0', revision: '13548', time: '2011-08-24 13:44:31'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.ver
sion: '1.6.0_26'
Driver info: driver.version: unknown
Solutions:
download and install Firefox 3.x version in the default directory
>mvn install -Dmeta.filter="+color red"
In a directory target/view, a page named 'reports.html' has been generated.
2. Analynize the sample
etsy-stories-java-spring/src/main/stories/ all the stories are here.
etsy-stories-java-spring/src/main/java/org/jbehave/tutorials/etsy/EtsyDotComStories.java
This is the entry of the tests.
etsy-stories-java-spring/resources/etsy-steps.xml contains the Spring configuration for composition the steps.
3. Study some concepts and ideas
3.1 Write a textual story
create a textual story file store_locator.story
Store Locator Story
Narrative:
Store Locator Function, we can locate a store.
As a user, we can get the current location.
#Scenario: Get Current Location
#Given open home page
#When click the store locator link
#Then get the store locator page button id is uselocation
#When click the button user location
#Then get the google map, the text is 'No stores found in the specified location'
Scenario: Search the Store Location with 78704
Given open home page
When click the store locator link
Then get the store locator page button id is uselocation
When type in the 78704 ZIP code
Then get some stores, see the map button
Scenario: Search the Store Location with 78730
Given open home page
When click the store locator link
Then get the store locator page button id is uselocation
When type in the 78730 ZIP code
Then get some stores, see the map button
3.2 Map all steps to Java methods
Map all the story to our Java methods:
private Home home;
private StoreLocator storeLocator;
public PetcoSteps(PetcoPageFactory pageFactory) {
home = pageFactory.newHome();
storeLocator = pageFactory.newStoreLocator();
}
@Given("open home page")
public void openHomePage() {
home.go();
}
@When("click the store locator link")
public void clickTheStoreLocatorLink() {
home.goToStoreLocator();
}
@Then("get the store locator page button id is $buttonId")
public void getTheStoreLocatorPage(String buttonId) {
MatcherAssert.assertThat(storeLocator.hasButton(buttonId),
Matchers.is(true));
}
@When("click the button user location")
public void clickTheButtonUserLocation() {
storeLocator.clickUserLocator();
}
@Then("get the google map, the text is $message")
public void getTheGoogleMap(String message) {
MatcherAssert.assertThat(storeLocator.hasText(message),
Matchers.is(true));
}
@When("type in the $zipCode ZIP code")
public void typeTheZipCode(String zipCode) {
storeLocator.typeZIPCode(zipCode);
}
@Then("get some stores, see the map button")
public void getMapButton() {
MatcherAssert
.assertThat(storeLocator.hasMapButton(), Matchers.is(true));
}
3.3 Configuration in Spring
my configuration sample is petco-steps.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="driverProvider" class="org.jbehave.web.selenium.FirefoxWebDriverProvider" >
</bean>
<bean id="petcoPageFactory" class="com.easybddweb.vendors.petco.pages.PetcoPageFactory">
<constructor-arg ref="driverProvider"/>
</bean>
<bean id="petcoSteps" class="com.easybddweb.vendors.petco.steps.PetcoSteps">
<constructor-arg ref="petcoPageFactory"/>
</bean>
<bean id="petcoLifecycleSteps" class="com.easybddweb.vendors.petco.steps.PetcoLifecycleSteps">
<constructor-arg ref="driverProvider"/>
</bean>
</beans>
4.4 We use maven and plugin to run these tests
<plugins>
<plugin>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-maven-plugin</artifactId>
<version>${jbehave.core.version}</version>
<executions>
<execution>
<id>unpack-view-resources</id>
<phase>process-resources</phase>
<goals>
<goal>unpack-view-resources</goal>
</goals>
</execution>
<execution>
<id>embeddable-stories</id>
<phase>integration-test</phase>
<configuration>
<includes>
<include>${stories}</include>
</includes>
<excludes />
<generateViewAfterStories>true</generateViewAfterStories>
<ignoreFailureInStories>true</ignoreFailureInStories>
<ignoreFailureInView>false</ignoreFailureInView>
<threads>${threads}</threads>
<skip>${skip}</skip>
<metaFilters>
<metaFilter>${meta.filter}</metaFilter>
</metaFilters>
</configuration>
<goals>
<goal>run-stories-as-embeddables</goal>
</goals>
</execution>
<execution>
<id>map-stories</id>
<phase>integration-test</phase>
<configuration>
<includes>
<include>**/*StoryMaps.java</include>
</includes>
</configuration>
<goals>
<goal>map-stories-as-embeddables</goal>
</goals>
</execution>
<execution>
<id>report-stepdocs</id>
<phase>integration-test</phase>
<configuration>
<includes>
<include>${stories}</include>
</includes>
</configuration>
<goals>
<goal>report-stepdocs-as-embeddables</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
Ok, the first example for web page test is done. The related things are maven2, jbehave, junit, spring, selenium.
The details are in the sample project easybddweb-1.0.zip.
references:
http://jbehave.org/
http://yangzb.iteye.com/blog/309354
http://jbehave.org/introduction/
http://jbehave.org/documentation/
http://jbehave.org/reference/stable/getting-started.html
https://github.com/jbehave/jbehave-tutorial
http://jbehave.org/reference/stable/running-examples.html
http://groups.google.com/group/webdriver/msg/1f307c5a78c6f8d3?pli=1
1. jbehave totorial sample
use git bash on my win7 system, from the start menu, choose git bash
>pwd
>cd /d/book/jbehave
>git clone https://github.com/jbehave/jbehave-tutorial.git jbehave-tutorial
change the pom.xml, from
<properties>
<jbehave.core.version>3.6.SNAPSHOT</jbehave.core.version>
<jbehave.web.version>3.5.SNAPSHOT</jbehave.web.version>
<jbehave.site.version>3.1.1</jbehave.site.version>
</properties>
to
<properties>
<jbehave.core.version>3.5.1</jbehave.core.version>
<jbehave.web.version>3.4</jbehave.web.version>
<jbehave.site.version>3.1.1</jbehave.site.version>
</properties>
>mvn install
error messages:
[WARNING] Failed to run story etsy_search.story
org.jbehave.core.failures.UUIDExceptionWrapper: org.jbehave.core.failures.Before
OrAfterFailed: Method beforeStory (annotated with @BeforeStory in class org.jbeh
ave.web.selenium.PerStoryWebDriverSteps) failed: org.openqa.selenium.WebDriverEx
ception: Cannot find firefox binary in PATH. Make sure firefox is installed. OS
appears to be: VISTA
Build info: version: '2.5.0', revision: '13548', time: '2011-08-24 13:44:31'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.ver
sion: '1.6.0_26'
Driver info: driver.version: unknown
Solutions:
download and install Firefox 3.x version in the default directory
>mvn install -Dmeta.filter="+color red"
In a directory target/view, a page named 'reports.html' has been generated.
2. Analynize the sample
etsy-stories-java-spring/src/main/stories/ all the stories are here.
etsy-stories-java-spring/src/main/java/org/jbehave/tutorials/etsy/EtsyDotComStories.java
This is the entry of the tests.
etsy-stories-java-spring/resources/etsy-steps.xml contains the Spring configuration for composition the steps.
3. Study some concepts and ideas
3.1 Write a textual story
create a textual story file store_locator.story
Store Locator Story
Narrative:
Store Locator Function, we can locate a store.
As a user, we can get the current location.
#Scenario: Get Current Location
#Given open home page
#When click the store locator link
#Then get the store locator page button id is uselocation
#When click the button user location
#Then get the google map, the text is 'No stores found in the specified location'
Scenario: Search the Store Location with 78704
Given open home page
When click the store locator link
Then get the store locator page button id is uselocation
When type in the 78704 ZIP code
Then get some stores, see the map button
Scenario: Search the Store Location with 78730
Given open home page
When click the store locator link
Then get the store locator page button id is uselocation
When type in the 78730 ZIP code
Then get some stores, see the map button
3.2 Map all steps to Java methods
Map all the story to our Java methods:
private Home home;
private StoreLocator storeLocator;
public PetcoSteps(PetcoPageFactory pageFactory) {
home = pageFactory.newHome();
storeLocator = pageFactory.newStoreLocator();
}
@Given("open home page")
public void openHomePage() {
home.go();
}
@When("click the store locator link")
public void clickTheStoreLocatorLink() {
home.goToStoreLocator();
}
@Then("get the store locator page button id is $buttonId")
public void getTheStoreLocatorPage(String buttonId) {
MatcherAssert.assertThat(storeLocator.hasButton(buttonId),
Matchers.is(true));
}
@When("click the button user location")
public void clickTheButtonUserLocation() {
storeLocator.clickUserLocator();
}
@Then("get the google map, the text is $message")
public void getTheGoogleMap(String message) {
MatcherAssert.assertThat(storeLocator.hasText(message),
Matchers.is(true));
}
@When("type in the $zipCode ZIP code")
public void typeTheZipCode(String zipCode) {
storeLocator.typeZIPCode(zipCode);
}
@Then("get some stores, see the map button")
public void getMapButton() {
MatcherAssert
.assertThat(storeLocator.hasMapButton(), Matchers.is(true));
}
3.3 Configuration in Spring
my configuration sample is petco-steps.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="driverProvider" class="org.jbehave.web.selenium.FirefoxWebDriverProvider" >
</bean>
<bean id="petcoPageFactory" class="com.easybddweb.vendors.petco.pages.PetcoPageFactory">
<constructor-arg ref="driverProvider"/>
</bean>
<bean id="petcoSteps" class="com.easybddweb.vendors.petco.steps.PetcoSteps">
<constructor-arg ref="petcoPageFactory"/>
</bean>
<bean id="petcoLifecycleSteps" class="com.easybddweb.vendors.petco.steps.PetcoLifecycleSteps">
<constructor-arg ref="driverProvider"/>
</bean>
</beans>
4.4 We use maven and plugin to run these tests
<plugins>
<plugin>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-maven-plugin</artifactId>
<version>${jbehave.core.version}</version>
<executions>
<execution>
<id>unpack-view-resources</id>
<phase>process-resources</phase>
<goals>
<goal>unpack-view-resources</goal>
</goals>
</execution>
<execution>
<id>embeddable-stories</id>
<phase>integration-test</phase>
<configuration>
<includes>
<include>${stories}</include>
</includes>
<excludes />
<generateViewAfterStories>true</generateViewAfterStories>
<ignoreFailureInStories>true</ignoreFailureInStories>
<ignoreFailureInView>false</ignoreFailureInView>
<threads>${threads}</threads>
<skip>${skip}</skip>
<metaFilters>
<metaFilter>${meta.filter}</metaFilter>
</metaFilters>
</configuration>
<goals>
<goal>run-stories-as-embeddables</goal>
</goals>
</execution>
<execution>
<id>map-stories</id>
<phase>integration-test</phase>
<configuration>
<includes>
<include>**/*StoryMaps.java</include>
</includes>
</configuration>
<goals>
<goal>map-stories-as-embeddables</goal>
</goals>
</execution>
<execution>
<id>report-stepdocs</id>
<phase>integration-test</phase>
<configuration>
<includes>
<include>${stories}</include>
</includes>
</configuration>
<goals>
<goal>report-stepdocs-as-embeddables</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
Ok, the first example for web page test is done. The related things are maven2, jbehave, junit, spring, selenium.
The details are in the sample project easybddweb-1.0.zip.
references:
http://jbehave.org/
http://yangzb.iteye.com/blog/309354
http://jbehave.org/introduction/
http://jbehave.org/documentation/
http://jbehave.org/reference/stable/getting-started.html
https://github.com/jbehave/jbehave-tutorial
http://jbehave.org/reference/stable/running-examples.html
http://groups.google.com/group/webdriver/msg/1f307c5a78c6f8d3?pli=1
发表评论
-
RESTful JSON Mock Server
2015-03-19 11:58 801RESTful JSON Mock Server C ... -
Performance Tool(7)Improve Lua and Wrk
2015-01-17 06:37 1038Performance Tool(7)Improve Lua ... -
Performance Tool(6)Gatling Upgrade to 2.1.2 Version Or wrk
2015-01-10 01:15 979Performance Tool(6)Gatling Upg ... -
Performance Tool(5)Upgrade to 2.0.x
2014-08-27 03:34 1128Performance Tool(5)Upgrade to 2 ... -
Performance Tool(4)CSV File Data Feeder
2014-08-25 10:50 1032Performance Tool(4)CSV File Dat ... -
wrk with LuaJIT
2014-08-19 06:30 1338wrk with LuaJITHere is an exa ... -
Performance Tool(3)Gatling Upgrade and Cluster
2014-07-25 02:32 1337Performance Tool(3)Gatling Upgr ... -
WRK a HTTP Benchmarking Tool
2014-03-07 04:42 1145WRK a HTTP Benchmarking Tool1 ... -
Performance Tool(1)Gatling
2013-03-15 05:28 1297Performance Tool(1)Gatling 1. ... -
Jenkins Configuration(4)Improve Shell Script Debug/Info Message
2013-01-07 06:32 1338Jenkins Configuration(4)Improve ... -
Jenkins Configuration(3)Shell Script
2012-12-28 01:17 2683Jenkins Configuration(3)Shell S ... -
Eclipse Plugin(2)SOAP UI
2012-06-08 10:48 1352Eclipse Plugin(2)SOAP UI Plugi ... -
Spring3 and REST Integeration(VII)Controller JUnit Test and Mock/Spring Test MVC
2012-04-06 15:57 1912Spring3 and REST Integeration(V ... -
Spring3 and REST Integration(VI)Controller JUnit Test and Mock/Spring HandlerAda
2012-04-06 15:51 1822Spring3 and REST Integration(VI ... -
Spring3 and REST Integration(V)Controller JUnit Test and Mock/HandlerAdapter
2012-04-06 15:41 2840Spring3 and REST Integration(V) ... -
Spring3 and REST Integration(IV)Controller JUnit Test and Mock/Servlet
2012-04-06 15:13 1993Spring3 and REST Integration(IV ... -
Jbehave(2)Some Improvement and POM changes
2012-03-28 23:11 1430Jbehave(2)Some Improvement and ... -
buildr(1)Introduce and Install
2011-12-23 16:37 2189buildr(1)Introduce and Install ... -
WarcraftIII Problem on English Win7
2011-07-25 10:18 1948WarcraftIII Problem on English ... -
Web Performance Test Tool
2011-05-10 15:37 1459Web Performance Test Tool 1. F ...
相关推荐
JBehave-Web JBehave 是 JBehave 的扩展集合,以与 HTTP 和 Web 相关的方式扩展其功能。模块网络Selenium。 与 Selenium 1.0 和 2.0 的绑定允许 JBehave 在网站上运行。 网络跑者。 一个允许非开发人员同步实验运行...
1. **配置JBehave**: 首先需要在`pom.xml`中添加JBehave和Spring的依赖,确保项目可以使用这两个库。 2. **创建步骤类**: 在`src/main/java`下创建步骤类,这些类将实现故事文件中定义的行为步骤。 3. **编写故事...
jbehave source 4.0,详情请查看官网
jbehave core用于BDD Java自动化代码开发jar包
1. **JBehave**:这是一个 BDD 框架,它帮助开发者以自然语言编写测试案例,提高代码的可读性和维护性。JBehave 支持多种故事格式,并可以与其他测试框架(如 JUnit 或 TestNG)集成。 2. **PicoContainer**:...
**1. jBehave 的核心概念** - **故事(Stories)**:在 jBehave 中,故事是描述软件功能的自然语言文本,它们通常由三部分组成:背景(Background)、场景(Scenarios)和步骤(Steps)。背景提供了故事的上下文,...
1. **故事文件**:首先,创建一个故事文件,用Markdown或其他支持的格式编写故事。每个故事都包含一个或多个场景,每个场景又由一组步骤组成。 2. **步骤定义**:然后,你需要编写Java类来实现这些故事中的步骤。...
1. **自然语言故事**:JBehave支持用简单的英语短语编写测试故事,使非程序员也能理解测试目标。 2. **步骤定义**:每个故事由一系列步骤组成,这些步骤可以通过Java方法进行定义和实现。 3. **故事执行**:JBehave...
1. **JBehave Core**: JBehave 是Java领域的一个BDD框架,它将故事作为测试的中心,这些故事可以以自然语言形式编写,使得非技术人员也能理解。它支持多种故事格式,包括文本、XML和Java注解。JBehave与JUnit、...
#jbehave-webtest-todomvc 一个简单的演示项目,将Serenity与JBehave和JUnit结合使用,并针对应用程序运行测试。 该项目使用JDK 1.8和gradle运行。 要运行演示,请运行: gradle clean test aggregateSerenity报告...
SeAuto JBehave 示例 介绍 该项目旨在成为那些想要快速实施和使用 SeAuto for JBehave 的模板项目。 设置说明 先决条件: 下载并安装 下载并安装 如果您有偏好,该页面上的任何版本都可以使用 Firefox,用于运行...
总之,JBehave项目是一个很好的学习资源,它展示了如何在Java环境中利用BDD框架进行测试驱动开发,以及如何结合Selenium进行Web应用程序的自动化测试。通过研究这个项目,开发者可以提升对BDD的理解,掌握JBehave的...
1. **Thucydides**:一个强大的Java库,用于自动化Web应用程序的端到端测试,提供详细的测试报告和测试管理工具。 2. **JBehave**:一个BDD框架,允许用自然语言编写测试,使非技术人员也能理解测试目标。 3. **BDD...
解压 jbehave 站点资源并将 jbehave 报告链接到 maven 报告
1. **示例项目(Sample Projects)**: 包含了使用JBehave编写的测试案例,帮助初学者理解如何组织故事文件和步骤类。 2. **配置文件(Configuration Files)**: 如 `pom.xml`(如果是Maven项目)展示了如何在项目中...
1. **设置项目结构**:创建一个Maven项目,并配置pom.xml文件,引入jBehave相关的依赖库。 2. **编写故事文件**:使用纯文本格式(如.feature)编写故事文件,描述业务场景。 3. **实现步骤**:根据故事文件中的步骤...
1. **行为驱动开发(BDD)**:BDD是一种软件开发方法,强调以用户需求为导向,通过编写可执行的故事来描述软件行为。在这个项目中,你会学到如何用自然语言表述业务需求,并转化为可测试的代码。 2. **jBehave框架*...
Etsy.com网站上的JBehave Selenium教程教程使用, 和对预先现有的网站展示BDD如何允许Web应用程序的行为的描述和测试。模组“ etsy-selenium”模块运行(通过maven)故事来验证Etsy.com的行为。 它使用Selenium来...
1. **什么是 JBehave**: JBehave 是一个 Java 实现的行为驱动开发 (BDD) 框架,它允许开发者使用简洁的自然语言编写测试用例。这些用例以故事的形式描述了软件的功能需求,使得业务人员和开发人员之间能够进行更有效...