Cucumber 使用例子
1. junit 配置
@RunWith(Cucumber.class)
@CucumberOptions(format ={"pretty","html:target/cucumber"},
features={"src/main/java/demoapp"},tags={"@third"})
public class test { }
# language: zh-CN
功能:测试
@third
场景大纲:一些测试
假如 firstw "demo"
当 demoinfo <name>
那么 appdemo <info>
例子:
|name| info|
|first|dalong|
|second|aaaaa|
Feature:Belly
@first
ScenarioOutline: a few cukes
Given firstw "demo"
When demoinfo <name>
Then appdemo <info>
Examples:
|name| info|
|first|dalong|
|second|aaaaa|
publicclassMyStepdefs{
@Given("I have (\\d+) cukes in my belly")
publicvoid I_have_cukes_in_my_belly(int cukes){
System.out.format("Cukes: %n\n", cukes);
}
@When("^I wait (\\d+) hour$")
publicvoid i_wait_hour(int arg1)throwsThrowable{
// Write code here that turns the phrase above into concrete actions
thrownewPendingException();
}
@Then("^dodemo$")
publicvoid dodemo()throwsThrowable{
// Write code here that turns the phrase above into concrete actions
System.out.println("dodemo");
}
@Given("^first \"([^\"]*)\"$")
publicvoid first(String arg1)throwsThrowable{
// Write code here that turns the phrase above into concrete actions
System.out.println("first"+": "+ arg1);
}
@Then("^my belly should growl$")
publicvoid my_belly_should_growl()throwsThrowable{
// Write code here that turns the phrase above into concrete actions
thrownewPendingException();
}
@Given("^first demo$")
publicvoid first_demo()throwsThrowable{
// Write code here that turns the phrase above into concrete actions
System.out.println("first_demo");
}
@When("^user names$")
publicvoid user_names(DataTable arg1)throwsThrowable{
// Write code here that turns the phrase above into concrete actions
// For automatic transformation, change DataTable to one of
// List<YourType>, List<List<E>>, List<Map<K,V>> or Map<K,V>.
// E,K,V must be a scalar (String, Integer, Date, enum etc)
List<List<String>>list= arg1.raw();
System.out.println(list.get(0));
System.out.println(arg1.toString());
}
@When("^demoinfo ([^\"]*)$")
publicvoid demoinfo_name(String name)throwsThrowable{
// Write code here that turns the phrase above into concrete actions
System.out.println(name+"demoinfo_name");
//Assert.assertTrue(false);
}
@Then("^appdemo ([^\"]*)$")
publicvoid appdemo_info(String name )throwsThrowable{
// Write code here that turns the phrase above into concrete actions
System.out.println(name+"appdemo_info");
}
@When("^call me$")
publicvoid call_me()throwsThrowable{
// Write code here that turns the phrase above into concrete actions
System.out.println("call me");
}
@Then("^docall$")
publicvoid docall()throwsThrowable{
// Write code here that turns the phrase above into concrete actions
System.out.println("docall");
}
@Given("^firstw \"([^\"]*)\"$")
publicvoid firstw(String arg1)throwsThrowable{
// Write code here that turns the phrase above into concrete actions
System.out.println("firstw");
}
@When("^demoinfo$")
publicvoid demoinfo()throwsThrowable{
// Write code here that turns the phrase above into concrete actions
System.out.println("demoinfo");
}
@When("^printinfos$")
publicvoid printinfos(List<String> info)throwsThrowable{
// Write code here that turns the phrase above into concrete actions
// For automatic transformation, change DataTable to one of
// List<YourType>, List<List<E>>, List<Map<K,V>> or Map<K,V>.
// E,K,V must be a scalar (String, Integer, Date, enum etc)
info.forEach(newConsumer<String>(){
@Override
publicvoid accept(String t){
// TODO Auto-generated method stub
System.out.println(t+"demo info");
}
});
}
@Then("^appdemo$")
publicvoid appdemo()throwsThrowable{
// Write code here that turns the phrase above into concrete actions
System.out.println("appdemo");
}
}
<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version><!--$NO-MVN-MAN-VER$ -->
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>sonatype-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
Cucumber 使用例子的更多相关文章
- (转载)中文Appium API 文档
该文档是Testerhome官方翻译的源地址:https://github.com/appium/appium/tree/master/docs/cn官方网站上的:http://appium.io/s ...
- 中文Appium API 文档
该文档是Testerhome官方翻译的源地址:https://github.com/appium/appium/tree/master/docs/cn官方网站上的:http://appium.io/s ...
- Cucumber语法及测试用例<一>
工作原因,最近一直在研究cucumber的 语法以及它和java之间的关系.鉴于是初学者且代码基础薄弱,我开始摸索前行,感谢分享博客且也在一路前行的人儿们. 1.基本语法为:此处举例两种区别一看即知- ...
- Cucumber命令行接口
1. cucumber的命令行选项 首先查看命令行选项.和其它命令行工具一样,cucumber提供了—help选项.下面是cucumber帮助的一个缩减版本: $ cucumber --help -r ...
- uiautomator+cucumber实现自动化测试
前提 由于公司业务要求,所以自动化测试要达到以下几点: 跨应用的测试 测试用例可读性强 测试报告可读性强 对失败的用例有截图保存并在报告中体现 基于以上几点,在对自动化测试框架选型的时候就选择了uia ...
- Cucumber 行为驱动开发简介
Cucumber 是一个能够理解用普通语言 描述的测试用例的支持行为驱动开发(BDD)的自动化测试工具,用Ruby编写,支持Java和.Net等多种开发语言. 现在看看Cucumber中用到的术语 . ...
- 行为驱动:Cucumber + Selenium + Java(四) - 实现测试用例的参数化
在上一篇中,我们介绍了Selenium + Cucumber + Java框架下的使用Tags对测试用例分组的实现方法,这一篇我们用数据表格来实现测试用例参数化. 4.1 什么是用例参数化 实际测试中 ...
- 【Cucumber】【命令行】
知识点 参考:https://www.cnblogs.com/worklog/p/5253297.html cucumber的命令行选项 首先查看命令行选项.和其它命令行工具一样,cucumber提供 ...
- cucumber java从入门到精通(4)Scenario Outline及数据驱动
cucumber java从入门到精通(4)Scenario Outline及数据驱动 到目前为止,我们的TodoList类工作良好,不过离我们的预期--任务清单系统还是有不少差距,究其原因不过如下: ...
随机推荐
- 设计模式--抽象工厂模式C++实现
抽象工厂模式C++实现 1定义 为创建一组相关或者依赖的对象提供一个接口,且无需指定他们的具体类 2类图 3实现 class AbstractProduct { protected: Abstract ...
- ES6 HttpApplication Middleware
const HttpRequest = function() { this.query = '' } function HttpResponse() { this.body = [] this.sta ...
- Python中的map和reduce函数简介
①从参数方面来讲: map()函数: map()包含两个参数,第一个是参数是一个函数,第二个是序列(列表或元组).其中,函数(即map的第一个参数位置的函数)可以接收一个或多个参数. reduce() ...
- grunt-init 默认模板目录更正
grunt-init是依赖grunt项目管理的脚手架工具,各种优点无须赘述,默认的template路径的作用:可以把自定义或其他模板放置其中,应用的时候直接调用模板名,不用每次寻找路径: 在安装gru ...
- Mysql加载配置默认路径
查看命令 mysqld --verbose --help|grep "Default options" -n1 输出结果 11-12:Default options are rea ...
- 重温MVC基础入门
重温MVC基础入门 简介 本文主要是作者回顾MVC基础的文章,整合个人认为基础且重点的信息,通过简单实践进行复习. 相关代码地址:https://github.com/OtherRuan/Revi ...
- HDU 2669 Romantic (扩展欧几里得定理)
Romantic Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- DS导入导出命令详解
1.导出例子如下:$DSHOME/../../Clients/istools/cli/istool export -dom dpapp01 -u edpusr -p edpusr -ar /home/ ...
- JQuery遍历CheckBox踩坑记
$("#checkbox_id").attr("checked"); //获取一个CheckBox的状态(有没有被选中,返回true/false) $(&quo ...
- Java虚拟机访问读写其他进程的数据--RandomAccessFile
RandomAccessFile 是Java输入/输出流体系中功能最丰富的文件内容访问类,它提供了众多的方法来访问文件内容,它既可以读取文件内容,也可以向文件输出数据.并且它支持“任意访问”的方式,程 ...