17
借助 WebDriver 动化 Web 测试 Yugang Fan 英特尔

借助 WebDriver 动化 Web - Tizendownload.tizen.org/misc/media/tds2014/slides/EnableYour...• WebDriver • BDD • 为驱动测试 • 架构 • 例 • 基于 WebDriver 的为驱动测试

  • Upload
    others

  • View
    10

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 借助 WebDriver 动化 Web - Tizendownload.tizen.org/misc/media/tds2014/slides/EnableYour...• WebDriver • BDD • 为驱动测试 • 架构 • 例 • 基于 WebDriver 的为驱动测试

借助 WebDriver 执⾏行 ⾃自动化 Web 测试

Yugang Fan 英特尔

Page 2: 借助 WebDriver 动化 Web - Tizendownload.tizen.org/misc/media/tds2014/slides/EnableYour...• WebDriver • BDD • 为驱动测试 • 架构 • 例 • 基于 WebDriver 的为驱动测试

议程

2

•  背景 •  挑战 •  WebDriver •  BDD •  ⾏行为驱动测试 •  架构 •  ⽰示例 •  基于 WebDriver 的⾏行为驱动测试 •  总结 •  参考资料

Page 3: 借助 WebDriver 动化 Web - Tizendownload.tizen.org/misc/media/tds2014/slides/EnableYour...• WebDriver • BDD • 为驱动测试 • 架构 • 例 • 基于 WebDriver 的为驱动测试

背景

•  Web 应⽤用是指任何在 web 浏览器中运⾏行的软件。它通过⽀支持浏览器的编程语⾔言(例如 JavaScript、HTML 和 CSS 三者的结合)创建⽽而成并且依赖于 web 浏览器交付应⽤用

•  对于 web 运⾏行时,web 应⽤用是⼀一种使⽤用

JavaScript、HTML 和 CSS 等语⾔言编写的打包应⽤用。

•  Crosswalk 是 Tizen 上的默认 web 运⾏行时。

app.cs s

….. Video. mp4

config .xml

app.js

index. html

3

Page 4: 借助 WebDriver 动化 Web - Tizendownload.tizen.org/misc/media/tds2014/slides/EnableYour...• WebDriver • BDD • 为驱动测试 • 架构 • 例 • 基于 WebDriver 的为驱动测试

背景

app.wgt

IVI

4

可穿戴式 … …

电视 ⼿手机

Page 5: 借助 WebDriver 动化 Web - Tizendownload.tizen.org/misc/media/tds2014/slides/EnableYour...• WebDriver • BDD • 为驱动测试 • 架构 • 例 • 基于 WebDriver 的为驱动测试

挑战

5

•  难以在 web 应⽤用中应⽤用图像识别或平台本地 UI ⾃自动化解决⽅方案

•  Web UI 布局和元素的多样性(multi-formity)需要更为便捷的测试设计和开发⽅方法

•  现有的浏览器测试⾃自动化技术和⼯工具在 web 应⽤用或 web 运⾏行时⽅方⾯面仍存有空⽩白

Page 6: 借助 WebDriver 动化 Web - Tizendownload.tizen.org/misc/media/tds2014/slides/EnableYour...• WebDriver • BDD • 为驱动测试 • 架构 • 例 • 基于 WebDriver 的为驱动测试

WebDriver

6

•  http://www.w3.org/TR/webdriver/:WebDriver API 由连线协议和⼀一套接⼝口进⾏行定义,可发现和操作⻚页⾯面上的 DOM 元素,并控制单独控制流程中包含浏览器的⾏行为

•  多数常⽤用 WebDriver 规格参数为 selenium2.0:Chrome、Firefox、IE 和 Opera ……

•  越来越多的框架采⽤用 WebDriver 实施 Web UI ⾃自动化,例如 Watir WebDriver 和 Appium

Page 7: 借助 WebDriver 动化 Web - Tizendownload.tizen.org/misc/media/tds2014/slides/EnableYour...• WebDriver • BDD • 为驱动测试 • 架构 • 例 • 基于 WebDriver 的为驱动测试

浏览器中的 WebDriver ⽀支持

远程端

XDriver Selenium

2.0 WebDriver

API Bindings

本地端

基于 HTTP 连线协议的 JSON

Java

Python

Ruby

C#

Node.js

……

URL 导航

控制 Windows

元素处理

截屏

执⾏行 Javascript

……

基于 HTTP 的 JSON

7

Page 8: 借助 WebDriver 动化 Web - Tizendownload.tizen.org/misc/media/tds2014/slides/EnableYour...• WebDriver • BDD • 为驱动测试 • 架构 • 例 • 基于 WebDriver 的为驱动测试

Web 运⾏行时中的 WebDriver ⽀支持

基于 Android 的 Crosswalk

主机 PC

Selenium 2.0 Crosswalk APP

Tizen 设备 基于 Tizen 的 Crosswalk

Xwalkdriver

主机 PC

Selenium 2.0 Crosswalk APP

基于 Ubuntu 的 Crosswalk

Xwalkdriver

主机 PC

Selenium 2.0 Crosswalk APP

Android 设备

Xwalkdriver

8

Page 9: 借助 WebDriver 动化 Web - Tizendownload.tizen.org/misc/media/tds2014/slides/EnableYour...• WebDriver • BDD • 为驱动测试 • 架构 • 例 • 基于 WebDriver 的为驱动测试

BDD

9

⾏行为驱动开发

• 灵活的软件开发技术⽀支持开发⼈人员、QA 和⾮非技术⼈人员以及业务⼈人员在软件项⺫⽬目中互相协作。

• 我们的解决⽅方案遵循 BDD 原则,⽀支持写⼊入通⽤用语⾔言⻛风格的⽤用户测试,从⽽而验证 web 应⽤用和 web 平台,提供便捷、⾼高效的⽅方式进⾏行开发、管理和执⾏行测试案例,并且易于与⾼高级别测试框架进⾏行整合。

Page 10: 借助 WebDriver 动化 Web - Tizendownload.tizen.org/misc/media/tds2014/slides/EnableYour...• WebDriver • BDD • 为驱动测试 • 架构 • 例 • 基于 WebDriver 的为驱动测试

基于 BDD 的测试

Feature:Calculator Demo Test Scenario:Check if 7*8=56 ?

When launch “calculator-test“ And I press “7" And I press “*” And I press “8" And I press “=“ Then I should see "56"

BDD 测试案例

? BDD ⼯工具

应⽤用

10

Page 11: 借助 WebDriver 动化 Web - Tizendownload.tizen.org/misc/media/tds2014/slides/EnableYour...• WebDriver • BDD • 为驱动测试 • 架构 • 例 • 基于 WebDriver 的为驱动测试

架构

•  “⾏行为” — 采⽤用基于 BDD 的开源 Python 作为默认的 BDD ⼯工具进⾏行应⽤用测试⾃自动化

•  “ATIP”(Python 中的应⽤用测试) — 开发⼀一个“⾏行为” 约束(binding)库,作为应⽤用与“⾏行为”之间的联系,并采⽤用 WebDriver 实施⾯面向 web 应⽤用的具体 BDD 措施

Selenium 2.0

XDriver

Android* 本地 API

(例如UiAutomator)

Tizen 本地 API

基于 Tizen 的 Crosswalk 应⽤用

基于 Android 的Crosswalk 应⽤用

基于多种平台的浏览器, 例如 chrome/firefox

Android 应⽤用和系统

Tizen 应⽤用和系统

BDD 测试案例

“⾏行为” ATIP

11

Page 12: 借助 WebDriver 动化 Web - Tizendownload.tizen.org/misc/media/tds2014/slides/EnableYour...• WebDriver • BDD • 为驱动测试 • 架构 • 例 • 基于 WebDriver 的为驱动测试

示例

BDD test cases *.feature file

Feature:Web Storage Test Scenario:storage load page times When launch "w3c-webstorage-app" And I go to “test.html" And I press "clear_button" And I reload

Then I should see "viewed this page 1 time(s)."And I reload And I reload And I reload And I reload Then I should see "viewed this page 5 time(s)."

ATIP steps

@step(u'I go to "{url}"') def i_visit_url(context, url): assert context.app.switch_url(url, True) @step(u'I reload') def reload(context): assert context.app.reload()

@step(u'I press "{key}"') def i_press(context, key): assert context.app.press_element_by_key(key ……………………………………………..)

ATIP low level implementations

def switch_url(self, url, with_prefix=True): if with_prefix:

url = urljoin(self.url_prefix, url) try:

self. driver.get(url) except Exception as e: print "Failed to visit %s:%s" %

(url, e) return False return True

……………………………………..

Selenium2.0 WebDriver API

12

Page 13: 借助 WebDriver 动化 Web - Tizendownload.tizen.org/misc/media/tds2014/slides/EnableYour...• WebDriver • BDD • 为驱动测试 • 架构 • 例 • 基于 WebDriver 的为驱动测试

基于 WebDriver 的⾏行为驱动测试

xwalkdriver

Feature:Calculator Demo Test Scenario:Check if 7*8=56 ?

When launch “calculator-test“ And I press "seven" And I press "mult" And I press "eight" And I press "equals“ Then I should see "56"

BDD Test Cases

Selenium 2.0 ATIP “⾏行为”

13

Page 14: 借助 WebDriver 动化 Web - Tizendownload.tizen.org/misc/media/tds2014/slides/EnableYour...• WebDriver • BDD • 为驱动测试 • 架构 • 例 • 基于 WebDriver 的为驱动测试

总结

14

•  采⽤用 Crosswalk web 测试⾃自动化和实例应⽤用测试⾃自动化:https://github.com/crosswalk-project/crosswalk- test-suite

•  轻松扩展⾄至任何 web 应⽤用、浏览器、以及带有 WebDriver ⽀支持的 web 运⾏行时

Page 15: 借助 WebDriver 动化 Web - Tizendownload.tizen.org/misc/media/tds2014/slides/EnableYour...• WebDriver • BDD • 为驱动测试 • 架构 • 例 • 基于 WebDriver 的为驱动测试

后续措施

15

•  在 ATIP 中⽀支持更多的预定义场景

•  ATIP 中的本地和混合应⽤用⽀支持

•  在 ATIP 中提供多种应⽤用⽀支持

•  ⽀支持 BDD 措施以及 Python API

•  根据 W3C WebDriver 规格更新进⾏行调整

Page 16: 借助 WebDriver 动化 Web - Tizendownload.tizen.org/misc/media/tds2014/slides/EnableYour...• WebDriver • BDD • 为驱动测试 • 架构 • 例 • 基于 WebDriver 的为驱动测试

参考资料

16

•  https://github.com/crosswalk-project/crosswalk-test-suite/wiki/WebDriver- Based-Behavior-Driven-Test

•  https://github.com/crosswalk-project/crosswalk-test-suite

• https://github.com/crosswalk-project/crosswalk-test- suite/tree/master/tools/atip

•  http://docs.seleniumhq.org/projects/

• http://pythonhosted.org/behave/

Page 17: 借助 WebDriver 动化 Web - Tizendownload.tizen.org/misc/media/tds2014/slides/EnableYour...• WebDriver • BDD • 为驱动测试 • 架构 • 例 • 基于 WebDriver 的为驱动测试

"• '

, •

• '.. - . .' ,, , •  I ' ..- .,- . \ •

• • ' "• ' •

' .•

TIZE 开发者 峰会 2014

TM

•• • .'. ....,. •

上海 fil!:ffi}e.rat9fil!:mle.rat9fil!:ml

TIZEN7f :M d$ti( ..t5$)

•• ' "

- . _, . . - - ' . •• I

e

-..... '

• •

•I•

'

'"4

49 •' •

•• •

'•"