Cucumber行为驱动,
简称BDD,
其核心思想是把自然语言转换成代码;
但在敏捷开发的过程中,
这种东西极大的束缚了测试人员的手脚,
感觉它像封建时代的八股文,
要遵守严格的韵律,
反正我个人十分反感;
就像在做功能测试的时候,
那种基于Excel文档的测试;
自动化测试的目的是解放双手、提高效率,
而不是跳入另外一个坑。

Cucumber行为驱动的本意是想让各方:
如业务人员、运营人员、产品经理、开发工程师和普通用户都参与到测试用例的设计与执行中来,
让各方都能读懂,
所以才规定了严格的语法,
不允许测试人员去修改格式;
但是现实生活中,
其实只有测试人员在做测试工作,
当你的自动化用例达到100个以上时,
你还采用这种结构,
那要写到什么时候?
敏捷开发的过程中,
开发周期短,
测试周期就更短了。
综上所述,
Cucumber不适合甲方公司!

用Maven构建Cucumber依赖:

    <dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<scope>test</scope>
<version>1.2.5</version>
</dependency> <dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm</artifactId>
<version>1.2.5</version>
<type>pom</type>
</dependency> <dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-testng</artifactId>
<version>1.2.4</version>
</dependency> baiduSearch.feature配置文件:


# language: zh-CN

功能: 百度搜索的测试用例
场景大纲: 分别搜索<word>
假如我打开火狐浏览器
当输入百度的网址后,页面跳转到"https://www.baidu.com/"
当输入<word>,点击搜索按钮之后
那么页面标题会变为<result>
同时关闭火狐浏览器
例子:
|word |result |
|Selenium |Selenium_百度搜索 |
|JMeter |JMeter_百度搜索 |
|Appium |Appium_百度搜索 |

这个文件是可以直接运行的,会在控制台输出:

Undefined step: 假如 我打开火狐浏览器

Undefined step: 当 输入百度的网址后,页面跳转到"https://www.baidu.com/"

Undefined step: 当 输入Selenium,点击搜索按钮之后

Undefined step: 那么 页面标题会变为Selenium_百度搜索

Undefined step: 同时 关闭火狐浏览器

Undefined step: 假如 我打开火狐浏览器

Undefined step: 当 输入百度的网址后,页面跳转到"https://www.baidu.com/"

Undefined step: 当 输入JMeter,点击搜索按钮之后

Undefined step: 那么 页面标题会变为JMeter_百度搜索

Undefined step: 同时 关闭火狐浏览器

Undefined step: 假如 我打开火狐浏览器

Undefined step: 当 输入百度的网址后,页面跳转到"https://www.baidu.com/"

Undefined step: 当 输入Appium,点击搜索按钮之后

3 Scenarios (3 undefined)
15 Steps (15 undefined)
0m0.000s

You can implement missing steps with the snippets below:

@假如("^我打开火狐浏览器$")
public void 我打开火狐浏览器() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}

@当("^输入百度的网址后,页面跳转到\"([^\"]*)\"$")
public void 输入百度的网址后_页面跳转到(String arg1) throws Throwable {
Undefined step: 那么 页面标题会变为Appium_百度搜索

// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}

@当("^输入Selenium,点击搜索按钮之后$")
public void 输入selenium_点击搜索按钮之后() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}

@那么("^页面标题会变为Selenium_百度搜索$")
public void 页面标题会变为selenium_百度搜索() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@那么("^关闭火狐浏览器$")
public void 关闭火狐浏览器() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}

@当("^输入JMeter,点击搜索按钮之后$")
public void 输入jmeter_点击搜索按钮之后() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}

@那么("^页面标题会变为JMeter_百度搜索$")
public void 页面标题会变为jmeter_百度搜索() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}

@当("^输入Appium,点击搜索按钮之后$")
public void 输入appium_点击搜索按钮之后() throws Throwable {
Undefined step: 同时 关闭火狐浏览器

// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}

@那么("^页面标题会变为Appium_百度搜索$")
public void 页面标题会变为appium_百度搜索() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();}

测试用例类CucumberBaidu.java:

import cucumber.api.java.zh_cn.假如;
import cucumber.api.java.zh_cn.同时;
import cucumber.api.java.zh_cn.当;
import cucumber.api.java.zh_cn.那么;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.testng.Assert; public class CucumberBaidu { private static WebDriver driver; @FindBy(xpath = ".//*[@id='kw']")
private WebElement inputBox;
//输入框 @FindBy(xpath = ".//*[@id='su']")
private WebElement searchButton;
//搜索按钮 @假如("^我打开火狐浏览器$")
public void openFirefox() throws Throwable{
System.setProperty("webdriver.firefox.marionette",
"src/main/resourcec/geckodriver.exe");
driver = new FirefoxDriver();
PageFactory.initElements(driver, this);
driver.manage().window().maximize();
} @当("^输入百度的网址后,页面跳转到\"(.*)\"$")
public void openBaiduHomePage(String url) throws Throwable{
driver.get(url);
//不需要去声明百度首页的地址,因为它会从配置文件里面读取
} @当("^输入(.*),点击搜索按钮之后$")
public void searchChina(String searchWord) throws Throwable{
inputBox.sendKeys(searchWord);
searchButton.click();
Thread.sleep(2000);
} @那么("^页面标题会变为(.*)$")
public void keyword(String searchResult) throws Throwable{
Assert.assertEquals(driver.getTitle(), searchResult);
Thread.sleep(2000);
} @同时("^关闭火狐浏览器$")
public void quit(){
driver.close();
driver.quit();
}
}

驱动类CucumberDriver.java:
import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests; @CucumberOptions(
features = "baiduSearch.feature",
format = {"pretty",
"html:target/cucumber-html-report",
"json:target/cucumber-json-report.json"}
)
/*指定cucumber.feature文件,在工程的根目录下
命令行/控制台输出日志
生成html测试报告
生成json测试报告*/ public class CucumberDriver extends AbstractTestNGCucumberTests { } 运行一把,查看测试报告:



												

讨伐Cucumber行为驱动的更多相关文章

  1. Cucumber 行为驱动开发简介

    Cucumber 是一个能够理解用普通语言 描述的测试用例的支持行为驱动开发(BDD)的自动化测试工具,用Ruby编写,支持Java和.Net等多种开发语言. 现在看看Cucumber中用到的术语 . ...

  2. Cucumber测试驱动开发

     Cucumber是一种BDD实践开发工具,属于敏捷开发的组成部分.      在敏捷开发中,对用户进行需求分析时,不是像传统的P&D的开发方式,首先编写大量的用户需求分析文档,而是通过一个个 ...

  3. 行为驱动:Cucumber + Selenium + Java(一) - 环境搭建

    1.1 什么是行为驱动测试 说起行为驱动,相信很多人听说过. 行为驱动开发-BDD(Behavior Driven Development)是一个诞生于2003年的软件开发理念.其关键思想在于通过与利 ...

  4. 行为驱动:BDD框架之Cucumber初探

    1.cucumber cucumber早在ruby环境下应用广泛,作为BDD框架的先驱,cucumber后来被移植到了多平台,简单来说cucumber是一个测试框架,就像是juint或是rspec一样 ...

  5. 行为驱动:Cucumber + Selenium + Java(五) - 使用maven来实现cucumber测试和报告

    在上一篇中,我们介绍了Selenium + Cucumber + Java框架下的测试用例参数化/数据驱动,这一篇我们来使用maven去搭建cucumber框架以及实现测试报告. 5.1 为什么要用m ...

  6. 行为驱动:Cucumber + Selenium + Java(四) - 实现测试用例的参数化

    在上一篇中,我们介绍了Selenium + Cucumber + Java框架下的使用Tags对测试用例分组的实现方法,这一篇我们用数据表格来实现测试用例参数化. 4.1 什么是用例参数化 实际测试中 ...

  7. 行为驱动:Cucumber + Selenium + Java(三) - 使用标签实现测试分组

    在上一篇中,我们写出了Selenium + Cucumber + Java环境下的第一个BDD自动化测试用例,这一篇我们说说怎么用标签对用例进行分组. 3.1 Cucumber标签 实际工作中,我们的 ...

  8. 行为驱动:Cucumber + Selenium + Java(二) - 第一个测试

    在上一篇中,我们搭建好了Selenium + Cucumber + Java的自动化测试环境,这一篇我们就赶紧开始编写我们的第一个BDD测试用例. 2.1 创建features 我们在新建的java项 ...

  9. 行为驱动:Cucumber + Selenium + Java(二) - extentreports 测试报告+jenkins持续集成

    1.extentreports 测试报告 pom文件 <dependency> <groupId>com.vimalselvam</groupId> <art ...

随机推荐

  1. 【转】一看你就懂,超详细java中的ClassLoader详解

    http://blog.csdn.net/briblue/article/details/54973413 ClassLoader翻译过来就是类加载器,普通的java开发者其实用到的不多,但对于某些框 ...

  2. CSharp调用C++编写的DLL的方法

    自己比较懒,有的时候想写点东西,但由于文笔不行.技术不行也就没有怎么写.经常是用到什么.学习什么的时候,简单写点,权当是个学习笔记.上博客的次数也很少,有人给我留言也是没有怎么及时的回复,深感抱歉! ...

  3. mui的事件实现(持续更新)

    长按事件: mui('.mui-scroll').on('longtap', '.index-tab-item', function(e) { alert("长按生效") }); ...

  4. 使用Spring框架能带来那些好处?

    1.Dependency Injection(DI)方法使得构造器和JavaBean properties文件中的依赖关系一目了然. 2.与EJB容器相比较,Ioc容器更加趋向于轻量级.这样一来Ioc ...

  5. 2小时学会spring boot 以及spring boot进阶之web进阶(已完成)

    1:更换Maven默认中心仓库的方法 <mirror> <id>nexus-aliyun</id> <mirrorOf>central</mirr ...

  6. Webpack学习笔记九 webpack优化总结

    webpack 优化笔记 webpack4 自带的优化包括 swingTree(摇摆树)和作用域提升 swingTree 比如入口文件 index.js引入通用方法 util, 里面有 10个方法, ...

  7. 20181009noip HZ EZ 两校联考trade(优先队列,贪心)

    题面戳这里 思路: 裸的,贪心... 考场上写了一个数据分治(70ptsDP,30pts线段树优化贪心,GG了后30分) 这道题其实很简单的 我们看图: 我们在A时刻买一个东西,在B时刻卖出去,我们可 ...

  8. oracle的局部本地分区索引

    环境:oracle 12.2.0.1 注:未确定10g,11g是否有这些特性.现在基本不用10g,主要用12c,11g. 毫无疑问,这种 特性对于dba或者实施人员而言显得很重要,尤其当你的数据库主要 ...

  9. 路由器基础配置之ospf基础配置

    我们将以上面的拓扑图进行本次ospf的实验,目的是能当三台pc机互通 先配置好pc机的IP地址,注意一定要给pc机设置好网关,接下来配置路由器的IP地址 router4 enable 进入特权模式 c ...

  10. 禁止鼠标点右键 - 防止刷新页面 - 禁止复制 chrome 和 firefox不能复制

    document.oncontextmenu = function () {//点右键,啥反应都没有了 return false; } document.onkeydown = function () ...