一、打开Eclipse,新建一个maven项目,打开pom.xml

 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>Cucumber</groupId>
<artifactId>Cucumber</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging> <name>Cucumber</name>
<url>http://maven.apache.org</url>
<repositories>
<repository>
<id>sonatype-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> <dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>2.3.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>2.3.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.5.3</version>
</dependency>
</dependencies> </project>

二、新建一个RunCukesTest运行类

 package mypackage;

 import org.junit.runner.RunWith;

 import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber; @RunWith(Cucumber.class)
@CucumberOptions(
format = {"pretty", "html:target/cucumber"})
public class RunCukesTest { }

三、新建一个文件baiduSearch.feature

 Feature: 百度搜索
打开百度进行搜索 Scenario: 百度搜索selenium
Given Go to baidu home
When I find baidu logo
And Type the search text "selenium"
And Click the submit
Then Wait the query result

四、新建一个业务类BaiduSearchStepfs

 package mypackage;

 import cucumber.api.java.en.And;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When; import java.util.concurrent.TimeUnit; import org.junit.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait; public class BaiduSearchStepfs {
private WebDriver driver; @Given("^Go to baidu home$")
public void go_to_baidu_home() throws Exception {
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("http://www.baidu.com/");
} @When("^I find baidu logo")
public WebElement i_find_baidu_logo() {
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait
.until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath("//div[@id='lg']/img"))));
return element;
} @And("^Type the search text \"([^\"]*)\"$")
public void type_the_search_text(String searchText) throws Throwable {
driver.findElement(By.id("kw")).clear();
driver.findElement(By.id("kw")).sendKeys(searchText);
} @And("^Click the submit$")
public void click_the_submit() {
driver.findElement(By.id("su")).click();
} @Then("^Wait the query result")
public void wait_the_query_result() throws InterruptedException {
Thread.sleep(10000);
Assert.assertEquals("selenium_百度搜索", driver.getTitle());
driver.close();
driver.quit();
}
}

Cucumber java + Webdriver(一)的更多相关文章

  1. cucumber java从入门到精通(4)Scenario Outline及数据驱动

    cucumber java从入门到精通(4)Scenario Outline及数据驱动 到目前为止,我们的TodoList类工作良好,不过离我们的预期--任务清单系统还是有不少差距,究其原因不过如下: ...

  2. cucumber java从入门到精通(3)简单实现及断言

    cucumber java从入门到精通(3)简单实现及断言 上一节里我们定义了step的java代码实现文件,step就是测试步骤及断言的集合,我们先定义出来,以后可以驱动开发以及在持续集成时重用. ...

  3. cucumber java从入门到精通(2)用代码定义步骤

    cucumber java从入门到精通(2)用代码定义步骤 上一节里我们定义了feature文件,feature文件就是自然语言描述的用例文件,它有一定的章法,具体的潜规则是: 使用Feature关键 ...

  4. cucumber java从入门到精通(1)初体验

    cucumber java从入门到精通(1)初体验 cucumber在ruby环境下表现让人惊叹,作为BDD框架的先驱,cucumber后来被移植到了多平台,有cucumber-js以及我们今天要介绍 ...

  5. Java WebDriver 使用经验

    0x00 背景 WebDriver作为Selenium项目的工具之一,可以高效的操作各类主流浏览器包括诸如:chrome.IE.Firefox.Safari,并同时支持windows和*nux系统.W ...

  6. linux+java+webdriver chrome handless无界面启动

    网上现有的解决方案要么是windows下的,要么是python的,搞了一天终于解决了,记录如下. 1 下载chrome linux版和对应版本的webdriver,我这里使用的是chrome66和ch ...

  7. 行为驱动:Cucumber + Java - 实现数据的参数化

    1.什么是参数化 实际设计测试用例过程中,我们经常会用等价类.边界值这样的方法,针对一个功能进行测试数据上的测试,比如一个输入框,正向数据.逆向数据,非法输入等等 2.Cucumber的数据驱动 同上 ...

  8. java webdriver的api的封装

    我们来看一下官网提供的代码写法,即最原始的写法: driver.findElement(By.id("kw")).click() 这样写是没任何问题的,但这样没有把元素对象,数据, ...

  9. (java) webdriver 启动firefox driver时,加载firebug的扩展

    去网上下载一个firebug.xpi(对应版本, 我的ff是17,可以使用firebug-1.11.4.xpi,最好使用非firefox浏览器下载,不然提示你直接安装到firefox) @Before ...

随机推荐

  1. HTML5 <iframe> 标签

    iframe 元素会创建包含另外一个文档的内联框架(即行内框架). 即页面中嵌入另外一个独立的页面使用iframe,熟悉src是嵌套的页面的路径地址,scrolling属性可以设置iframe的滚动条 ...

  2. day68

    昨日回顾:1 虚拟环境 -1 pycharm里创建 -2 用命令串讲2 视图层: 1 Request对象---GET,POST,method,body,FILES,META,path(只是路径),ge ...

  3. Ubuntu系统上双节点部署OpenStack

    安装和部署双节点OpenStack 介绍: 1.宿主机:Win10操作系统 2.在VMware下创建两台虚拟机: devstack-controller:控制节点 + 网络节点 + 块存储节点 + 计 ...

  4. Python 调用 Redis API

    安装Redis包 在\Python27\Scripts目录下执行 pip install redis Python操作Redis __author__ = 'Edward' import redis ...

  5. ISCSI工作流程target和initiator

    随着企业级的数据呈指数增长,传统的集中式存储方案已无法满足其存储要求,因而存储区域网(storage area network,SAN)技术被广泛应用,但其存在距离短.价格贵和构建复杂等不足.基于iS ...

  6. 20155220 Exp9 Web安全基础实践

    Exp9 Web安全基础实践 实验过程 开启webgoat 输入java -jar webgoat-container-7.1-exec.jar,来运行webgoat 在浏览器输入localhost: ...

  7. Luogu P4322 [JSOI2016]最佳团体

    JZdalao昨天上课讲的题目,话说JSOI的题目是真的不难,ZJOI的题目真的是虐啊! 题意很简单,抽象一下就是:有一棵树,一次只能选从根到某个节点上的链上的所有点,问从中取出k个节点所得到的总价值 ...

  8. 分享一下个人学PS的过程

    得知Photoshop这款软件是在上大学的时候,2010年.学校学生会的科技部纳新,要求新人会PPT.word.Excel和Photoshop.当时有一个Photoshop大神,成为了学生会科技部的主 ...

  9. SQL Server 常用内置函数

    本文用于收集在运维中经常使用的系统内置(built-in)函数,持续整理中 一,常用Metadata函数 1,查看数据库的ID和Name db_id(‘DB Name’),db_name('DB ID ...

  10. 以e2e_cli为例漫谈fabric的一些基础知识点

    在刚接触fabric的时候一般都是直接跟着wiki的教程一步步安装配置,执行一系列命令,最终将其运行起来,但很多人对其中的运行流程及其基础知识点可能不是很了解.基于此今天我将以$FABRIC_ROOT ...