欢迎关注微信公众号,搜索软件测试工程师之路,一起学习,分享,成长。

ruby+watir+cucumber的自动化的设计

上一篇 / 下一篇  2016-01-08 16:51:44 / 个人分类:ruby+cucumber+watir

本次的场景自动化主要有以下几步:

拿到需求,需求分析,需求确认,测试策略,测试计划,测试用例,选择自动化用例,设计自动化用例,设计自动化脚本。运行并调试自动化脚本。

1.      此次的需求是这样的

需求就省略了。大概的需求就是在homepage页面新增三个下拉框控件,三个下拉框控件又是有逻辑关系的。


1.      需求分析和确认是这样的

这个就不多说了,和手工测试一样一样的。

 

2.      测试策略是这样的

也不多说了。

 

3.      测试计划是这样的

不多说了。

 

4.      自动化用例的确认和设计

第一条自动化用例:

don't select any filter, click search

转化成自动化用例是这样的:

步骤是这样的:

打开abtest url——打开URL——确认core wizard加载完成——选择cruise——选择filter——点击查询按钮——验证跳转到cruise result页面

 

第二条自动化用例:

select going to(Alaska) and departure
port(Cape Town),click search

 

第三条自动化用例:

select departure month(April 2016) and
cruise length(3-5 nights),click search

 

第四条自动化用例:

select going to(Australia) and cruise line(pricess cruises) and departure port(cairns),departure month(dec 2015) and cruise length(1-2 nights),click search

5.  确定自动化框架

此次自动化用的是cucumber+watir+ruby的框架,cucumber用作case层,watir用作函数层,ruby用作更底层的函数和方法。

 

6.  设计自动化脚本

设计自动化脚本之前,要了解watir调用。

Watir调用:

启动浏览器browser = watir::Browser.new

打开网址:browser.goto  ‘ url’

输入文本值:browser.text_field(:name,’ name’).set ‘ value1’

输入多行文本值:browser.text_field(:name, ‘ name’).set ‘value3’

操作单选按钮方法:browser.radio(:value, ‘value’).set

                  browser.radio(:value, ‘value’).clear

 

操作多选按钮的方法:browser.checkbox(:value, ‘value’).set

browser.checkbox(:value, ‘value’).clear

   

点击按钮的方法:browser.button(:name, ‘ name’).click

操作dropdownlist的方法:browser.select_list(:name, ‘name’).clear

browser.select_list(:name, ‘name’).options

browser.select_list(:name, ‘name’).select  ‘value’

操作页面中的文本:puts browser.text.include? ‘ value’

检查页面的标题:puts browser.title == ‘value’

 

然后将自动化用例的每个步骤转化成一个函数,例如

打开abtest url

这步转化成自动化用例:

give语句,Given Abacusid of "9016" is switched to the bucket value "1"

 

然后将步骤对应的函数写出来

 

When /^Abacusid of \"(\d*)\" is switched to the bucket value \"(\d*)\"$/ do |test_id, bucket_value|

  #@browser = Watir::Browser.new :firefox

  $env.logger.step "Switching AB Test ID of '#{test_id}' to the bucket value '#{bucket_value}'"

  url = $env.url + "/tools/abacus/overrides?abme=#{test_id}&abmb=0&abmv=#{bucket_value}"

  $env.logger.step "Navigating to '#{url}'"

  @browser.goto(url)

end

 

7.    运行并调试自动化脚本

最终成功的脚本如下:

Feature: cruise search

  In order to verify cruise search works well

  As a user on the Expedia sites

  I want to see cruise works well with hotel LOB

 

# verify cruise search with default parameters works well

  @apac @cruise @cruise_search_without_parameters_as_guest_works_well @trunk

  Scenario Outline: cruise search without parameters as guest works well

    Given Abacusid of "9016" is switched to the bucket value "1"

    Given the user visits the E3Home page

    Then the SearchWizard module must be displayed

    And user click cruise only tab

    Then the SearchWizard module must be displayed

    And user click search button

 

  Examples:

    | site_lang |

    | en_US     |

 

 @apac @cruise @cruise_search_with_two_parameters_as_guest_works_well @trunk

 Scenario Outline: cruise search with two parameters as guest works well

    Given Abacusid of "9016" is switched to the bucket value "1"

    Given the user visits the E3Home page

    Then the SearchWizard module must be displayed

    And user click cruise only tab

    Then the SearchWizard module must be displayed

    And user choose "<dest>" and "<cruline>" and "<deport>" and departure_month and cruise_length

    And user click search button

   Then page must be cruise search result page

 

 

 Examples:

   |site_lang | dest | cruline | deport |

   | en_US   | Africa | Crystal Cruises | Cape Town |

 

 

对应的stepdefinition

 

When /^Abacusid of \"(\d*)\" is switched to the bucket value \"(\d*)\"$/ do |test_id, bucket_value|

  #@browser = Watir::Browser.new :firefox

  $env.logger.step "Switching AB Test ID of '#{test_id}' to the bucket value '#{bucket_value}'"

  url = $env.url + "/tools/abacus/overrides?abme=#{test_id}&abmb=0&abmv=#{bucket_value}"

  $env.logger.step "Navigating to '#{url}'"

  @browser.goto(url)

end

 

When /^user click Cruise radio button$/ do

  current_page.cruise_search_widget.cruise_radio_button.click

end

 

When /^user click cruise only tab$/ do

  @browser.link(:id=>"tab-cruise-tab").click

  $env.logger.info "Search for cruise only!"

end

 

When /^user click search button$/ do

  @browser.button(:id,"search-button").click

  #@browser.search-button.click

  #@browser.link(:id=>"search-button").click

end

 

When /^user choose "([^"]*)" and "([^"]*)" and "([^"]*)" and departure_month and cruise_length$/ do |desti, cruline, deport|

  #@browser.find_element(:id, "cruise-destination").find_elements(:tag_name, "option")[3].click

  @browser.select_list(:id, "cruise-destination").select(desti);

  @browser.select_list(:id, "cruise-line").select(cruline);

  @browser.select_list(:id, "cruise-departureport").select(deport)

 

end

 

Then /^page must be cruise search result page$/ do

 

End

 

8.   自动化正式上线

其中最重要的是cucumber的语法,这个特别简单,然后是watir函数调用等,再者是ruby的使用。



TAG:

 

评分:0

我来说两句

日历

« 2024-05-17  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 17365
  • 日志数: 17
  • 建立时间: 2015-01-19
  • 更新时间: 2016-05-26

RSS订阅

Open Toolbar