讨伐Cucumber行为驱动

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


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

功能: 百度搜索的测试用例
  场景大纲: 分别搜索<word>
    假如我打开火狐浏览器
    输入百度的网址后,页面跳转到"https://www.baidu.com/"
    输入“<word>”,点击搜索按钮之后
    那么页面第一行会显示出“<result>同时关闭火狐浏览器
    例子:
      |word   |result        |
      |中国   |中国_百度百科 |
      |美国   |美国_百度百科 |
      |英国   |英国_百度百科 |
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.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;

public class Baidu_3 {

    public static WebDriver driver;

    @假如("^我打开火狐浏览器$")
    public void openFirefox() throws Throwable{
        System.setProperty("webdriver.firefox.marionette", "src/main/resourcec/geckodriver.exe");
        driver = new FirefoxDriver();
        driver.manage().window().maximize();
    }

    @当("^输入百度的网址后,页面跳转到\"(.*?)\"$")
    public void openBaiduHomePage(String url) throws Throwable{
        driver.get(url);
    }

    @当("^输入“(.*?)”,点击搜索按钮之后$")
    public void searchChina(String searchWord) throws Throwable{
        driver.findElement(By.xpath(".//*[@id='kw']"))
                .sendKeys(searchWord);
        driver.findElement(By.xpath(".//*[@id='su']"))
                .click();
        Thread.sleep(2000);
    }

    @那么("^页面第一行会显示出“(.*?)”$")
    public void keyword(String searchResult) throws Throwable{
        Assert.assertEquals(driver.findElement(By.xpath(".//*[@id='1']/h3/a")).getText(),
                searchResult);
        Thread.sleep(2000);
    }

    @同时("^关闭火狐浏览器$")
    public void quit(){
        driver.close();
        driver.quit();
    }
}
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 {

}

猜你喜欢

转载自blog.csdn.net/yjlch1016/article/details/78991162