zoukankan      html  css  js  c++  java
  • 关于cucumber的feature里用法的一些总结

    @RunWith(Cucumber.class)

    Cucumber will default to looking for feature files under the same package as RunCucksTest. You can also change the location(s) it will look for feature files by supplying the "features" option with the @CucumberOptions annotation (in RunCucksTest). 

    2.1 Feature 简述

             Feature可以定义为项目的独立单元或功能。举一个很常见的社交网站的例子。此产品/项目的功能如何?几个基本特征可以确定为:从社交网站创建和删除用户、社交网站的用户登录功能、在社交网站上分享照片或视频、发送朋友请求、注销

             到目前为止,当谈论Cucumber时,被测产品的每个独立功能都可以被称为一个Feature。这是最佳实践,当开始测试,在导出测试脚本之前,应该确定要测试的功能。

             Feature通常包含要为该Feature测试的场景列表。用户存储功能的文件,要测试的功能和场景的描述称为功能文件。

             Gherkins中的测试功能的关键字是“Feature”。建议的最佳做法是,在feature文件中的feature标题下面写入feature的小描述。这将满足良好的文档的需要。

    2.2 Feature Files

             写入Cucumber测试的文件称为Featurefiles。对于每个被测功能,建议应该有一个单独的feature file。feature file的扩展名必须为“.feature”。可以根据需要创建任意数量的feature file。为了具有有组织的结构,每个feature应当具有一个feature file。例如:

            

    用于feature的名称,featurefile的命名约定取决于个人的选择。在Cucumber中没有关于名字的基本规则。一个简单的feature file由以下关键字/部分组成:

    Feature:待测功能的名称。

    Description(可选):描述测试中的功能。

    Scenario:什么是测试场景。

    Given:在执行测试步骤之前的先决条件。

    When:为了执行下一步骤,应该匹配的特定条件。

    Then:如果满足WHEN中提到的条件,应该会发生什么。

    * AND关键字是用于显示两个条件之间的连接词。AND可用于任何其他关键字,如GIVENWHENTHEN

             在Feature file中没有写入逻辑细节。

    2.3 Steps定义

             已经准备好定义的测试场景的FeatureFile。然而,工作没有完成,Cucumber并不知道如何执行Feature File中描述特定场景所对应的代码。

             这就需要一个中间步骤---Step定义文件。Step定义文件存储在FeatureFile定义场景的每个step映射上,而该Feature File带有可执行的功能代码。所以,当Cucumber执行Feature File中提到的场景Step时,它扫描Step定义文件并计算出要调用哪个函数。

    Step定义文件的例子

    [java] view plain copy
     
    1. public void goToCsdn() {   
    2. driver = new FirefoxDriver();  
    3.  driver.navigate().to("https://passport.csdn.net/account/login?ref=toolbar");  
    4.  }   
    5.  @When "^user logs in using Username as "([^"]*)" and Password as "([^"]*)"$"   
    6.  public void I_enter_Username_as_and_Password_as(String arg1, String arg2) {   
    7.  driver.findElement(By.id("username")).sendKeys(arg1);   
    8.  driver.findElement(By.id("password")).sendKeys(arg2);   
    9.  driver.findElement(By.className("logging")).click();   
    10.  }   
    11.  @Then"^login should be unsuccessful$"   
    12.  public void validateRelogin() {   
    13.  if(driver.getCurrentUrl().equalsIgnoreCase("http://my.csdn.net/my/mycsdn")){   
    14.  System.out.println("Test Pass");   
    15.  }   
    16.  else {  
    17.  System.out.println("Test Failed");   
    18.  }   
    19.  driver.close();   
    20.  }<strong style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">   </strong>  

             因此,对于每个函数,想要执行每个测试Step(即GIVEN / THEN / WHEN)中的任何代码,都可以在Step定义文件中写入。确保已经为每个步骤定义了代码/函数。这个函数可以是Java函数,该函数中使用Java和Selenium命令来自动化的测试步骤。

  • 相关阅读:
    noip模拟赛 寻宝之后
    noip模拟赛 剪纸
    noip模拟赛 天天和不可描述
    noip模拟赛 罪犯分组
    noip模拟赛 天天寄快递
    Uva10562
    Uva10305 Ordering Tasks
    Uva 816 Abbott's Revenge
    Uva1103 Ancient Messages
    Uva297 Quadtrees
  • 原文地址:https://www.cnblogs.com/meimeilove/p/7284662.html
Copyright © 2011-2022 走看看