Cucumber java + Webdriver (3) 关于RunCukesTest.java 和 BaiduSearchStepfs.java
来源:互联网 发布:山海关 知乎 编辑:程序博客网 时间:2024/06/14 12:52
1、RunCukesTest
1.1 用于启动测试
上面运行测试的方式,这里也可以用其他启动方式来运行。如在类RunCukesTest.java中,右键点击Run RunCukesTest1.2 RunCukesTest.java内容
@RunWith(Cucumber.class)@CucumberOptions( features = {"src/test/resources/feature/"}, format = {"pretty", "html:target/cucumber", "json:target/cucumber.json"}, glue = {"com.cucumber"})public class RunCukesTest {}上述代码的浅解
@RunWith(Cucumber.class) 这是一个运行器 ,指用Cucumber来运行测试
@ CucumberOptions中的features,用于指定我们项目中要运行的feature的目录
@ CucumberOptions中的format,用于指定我们项目中要运行时生成的报告,并指定之后可以在target目录中找到对应的测试报告
@ CucumberOptions中的glue,用于指定项目运行时查找实现step定义文件的目录
2、BaiduSearchStepfs
2.1 对第一个feature的理解
该类是用代码来实现feature中的具体定义步骤。Feature文件中,是通过一些关键字来定义各个步骤,如以下一些,实际过程中还包括更多的关键字,先看下Feature中的内容:
• Feature 随着项目的进行会发现,所有的feature文件都是以该关键字开始。一般用来简单的描述写该feature实现什么功能。并在其下一行可以做更详细的说明
例子:
Feature:百度搜索
打开百度进行搜索
• Background 该关键字目前没用到,但是很重要。后面有机会会详细学习下
• Scenario 该关键字是用来定义具体要测试的功能点,比如常见的登录功能等
例子:
Scenario : 百度搜索selenium
• Given 是steps实现的一种,即是一个步骤,它是scenario中我们环境等所需要的条件.
例子:
Given Go to the url "http://www.baidu.com/"
• When 也是steps,表示scenario中我们执行测试例子中的某个动作等
例子:
When I find baidu logo
• And (or but) 和Given\When\Then的功能类似,如进行When,然后其他后续做某个操作时,用到该关键字
例子:
And Type the search text "selenium"
• Then 该关键字一般表示测试的预期结果,可进行断言等
2.2 BaiduSearchStepfs.java内容
Cucumber运行时,会根据feature文件中定义的step,来查找对应的具体实现
看BaiduSearchStepfs.java文件中的方法:@Given("^Go to the url \"([^\"]*)\"$") //1 public void go_to_the_url(String site) throws Exception { //2 driver = new ChromeDriver(); //3 driver.manage().window().maximize(); //4 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); //5 driver.get(site); //6 }第1行
@Given("^Go to the url \"([^\"]*)\"$")
用来对应feature文件中的step Given Go to the url "http://www.baidu.com/"。
这里传了一个字符串参数,用正则表达式来匹配对应的字符串
要注意,括号里面的内容,正常是以”^”开头、”$”结尾
第2~6行则是该步骤具体的实现内容,这里是用selenium Webdriver来实现
- Cucumber java + Webdriver (3) 关于RunCukesTest.java 和 BaiduSearchStepfs.java
- Cucumber java + Webdriver (6) Cucumber的数据驱动
- Cucumber java + Webdriver (5) Tags的使用
- appium+java+cucumber+selenium-webdriver android
- Cucumber+java
- Cucumber java + Webdriver (1) 所需环境的安装
- Cucumber java + Webdriver (2) 开始编写第一个Test
- Cucumber java + Webdriver (7) 结合Page Object,使用LoadableComponent
- 关于watir selenium和webdriver soda cucumber
- Cucumber-java初使用
- Cucumber java + Webdriver (4) 使用自动化测试的Page对象模式
- Cucumber java + Webdriver (8) 使用命令行风格来编写测试场景(Scenario)
- Cucumber-java入门基础篇
- java+selenium+cucumber框架之before和after
- intelj idea cucumber java搭建教程
- cucumber java从入门到精通(5)使用maven创建cucumber java项目
- Selenium Webdriver java
- Selenium Webdriver java 积累
- Tomcat热部署方法(3种)
- linux .deb 包的制作
- LNMP配置优化
- Maven---leaning01
- CSS框架——SASS
- Cucumber java + Webdriver (3) 关于RunCukesTest.java 和 BaiduSearchStepfs.java
- ecplise中git的提交/更新
- 二维码扫描
- datepicker只选择年月的设置技巧
- JDOM 解析xml
- [AndroidUI]自定义view(四):实现圆形圆角图片
- HTML 部分组件
- jquery的注释
- java中定时任务的实现