- 浏览: 2487457 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
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 759RESTful JSON Mock Server C ... -
Performance Tool(7)Improve Lua and Wrk
2015-01-17 06:37 1008Performance Tool(7)Improve Lua ... -
Performance Tool(6)Gatling Upgrade to 2.1.2 Version Or wrk
2015-01-10 01:15 938Performance Tool(6)Gatling Upg ... -
Performance Tool(5)Upgrade to 2.0.x
2014-08-27 03:34 1095Performance Tool(5)Upgrade to 2 ... -
Performance Tool(4)CSV File Data Feeder
2014-08-25 10:50 985Performance Tool(4)CSV File Dat ... -
wrk with LuaJIT
2014-08-19 06:30 1298wrk with LuaJITHere is an exa ... -
Performance Tool(3)Gatling Upgrade and Cluster
2014-07-25 02:32 1291Performance Tool(3)Gatling Upgr ... -
WRK a HTTP Benchmarking Tool
2014-03-07 04:42 1101WRK a HTTP Benchmarking Tool1 ... -
Performance Tool(1)Gatling
2013-03-15 05:28 1265Performance Tool(1)Gatling 1. ... -
Jenkins Configuration(4)Improve Shell Script Debug/Info Message
2013-01-07 06:32 1285Jenkins Configuration(4)Improve ... -
Jenkins Configuration(3)Shell Script
2012-12-28 01:17 2626Jenkins Configuration(3)Shell S ... -
Eclipse Plugin(2)SOAP UI
2012-06-08 10:48 1319Eclipse Plugin(2)SOAP UI Plugi ... -
Spring3 and REST Integeration(VII)Controller JUnit Test and Mock/Spring Test MVC
2012-04-06 15:57 1884Spring3 and REST Integeration(V ... -
Spring3 and REST Integration(VI)Controller JUnit Test and Mock/Spring HandlerAda
2012-04-06 15:51 1781Spring3 and REST Integration(VI ... -
Spring3 and REST Integration(V)Controller JUnit Test and Mock/HandlerAdapter
2012-04-06 15:41 2806Spring3 and REST Integration(V) ... -
Spring3 and REST Integration(IV)Controller JUnit Test and Mock/Servlet
2012-04-06 15:13 1908Spring3 and REST Integration(IV ... -
Jbehave(2)Some Improvement and POM changes
2012-03-28 23:11 1399Jbehave(2)Some Improvement and ... -
buildr(1)Introduce and Install
2011-12-23 16:37 2133buildr(1)Introduce and Install ... -
WarcraftIII Problem on English Win7
2011-07-25 10:18 1904WarcraftIII Problem on English ... -
Web Performance Test Tool
2011-05-10 15:37 1401Web Performance Test Tool 1. F ...
相关推荐
jbehave-spring-sample
JBehave-Web JBehave 是 JBehave 的扩展集合,以与 HTTP 和 Web 相关的方式扩展其功能。模块网络Selenium。 与 Selenium 1.0 和 2.0 的绑定允许 JBehave 在网站上运行。 网络跑者。 一个允许非开发人员同步实验运行...
jbehave source 4.0,详情请查看官网
jbehave core用于BDD Java自动化代码开发jar包
JBehave教程 的代码。
#jbehave-webtest-todomvc 一个简单的演示项目,将Serenity与JBehave和JUnit结合使用,并针对应用程序运行测试。 该项目使用JDK 1.8和gradle运行。 要运行演示,请运行: gradle clean test aggregateSerenity报告...
jbehave_example BDD概念。 Java Jbehave示例项目
jbehave-tutorial-maste
SeAuto JBehave 示例 介绍 该项目旨在成为那些想要快速实施和使用 SeAuto for JBehave 的模板项目。 设置说明 先决条件: 下载并安装 下载并安装 如果您有偏好,该页面上的任何版本都可以使用 Firefox,用于运行...
解压 jbehave 站点资源并将 jbehave 报告链接到 maven 报告
mod-mongo-persistor.zip,Vert.x Vert.x 2.x的MongoDB持久化模块**已被**弃用**-请改用
Etsy.com网站上的JBehave Selenium教程教程使用, 和对预先现有的网站展示BDD如何允许Web应用程序的行为的描述和测试。模组“ etsy-selenium”模块运行(通过maven)故事来验证Etsy.com的行为。 它使用Selenium来...
JBehave BDD框架的一个简单demo——JBehave 这个项目使用selenium和Junit库来演示一些使用JBehave的测试小例子
jbehave-testng-example完整的入门专案与范例一个简单加法器BDD范例使用JBehave + TestNG
gitter-scala.zip,纯功能scala gitter api客户端纯功能gitter api客户端
Jbehave学习[整理].pdf
JBehave教程 JBehave 教程的存储库
jbehave-最小示例jBehave 测试报告和 jenkins 插件的最小示例。
本教程使用 JBehave 3.x 和 Selenium 2.x 来测试 。 要求 Eclipse 或 Netbeans。 Java SE 1.8 最新版本。 Maven 3.0.3 最新版本 运行故事 这将构建源 mvn clean package 这将运行在 pom.xml 上配置的所有故事 ...