一些官方提供的Frank-Cucumber代码,可以参考去写我们自己的自动化测试代码

WAIT_TIMEOUT = 240require 'rspec/expectations'# -- See -- #
Then /^I wait to see "([^\"]*)"$/ do |expected_mark|Timeout::timeout(WAIT_TIMEOUT) dountil view_with_mark_exists( expected_mark )sleep 0.1endend
endThen /^I wait to not see "([^\"]*)"$/ do |expected_mark|sleep 3Timeout::timeout(WAIT_TIMEOUT) dowhile element_exists( "view marked:'#{expected_mark}'" )sleep 0.1endend
endThen /^I wait to see a navigation bar titled "([^\"]*)"$/ do |expected_mark|Timeout::timeout(30) dovalues = frankly_map( 'navigationItemView', 'accessibilityLabel' )until values.include?(expected_mark)values = frankly_map( 'navigationItemView', 'accessibilityLabel' )sleep 0.1endend
endThen /^I wait to not see a navigation bar titled "([^\"]*)"$/ do |expected_mark|Timeout::timeout(30) dovalues = frankly_map( 'navigationItemView', 'accessibilityLabel' )while values.include?(expected_mark)values = frankly_map( 'navigationItemView', 'accessibilityLabel' )sleep 0.1endend
endThen /^I should see a "([^\"]*)" button$/ do |expected_mark|check_element_exists("button marked:'#{expected_mark}'")
endThen /^I should see "([^\"]*)"$/ do |expected_mark|check_element_exists("view marked:'#{expected_mark}'")
endThen /^I should not see "([^\"]*)"$/ do |expected_mark|check_element_does_not_exist("view marked:'#{expected_mark}'")
endThen /I should see the following:/ do |table|values = frankly_map( 'view', 'accessibilityLabel' )table.raw.each do |expected_mark|values.should include( expected_mark.first )end
endThen /I should not see the following:/ do |table|values = frankly_map( 'view', 'accessibilityLabel' )table.raw.each do |expected_mark|values.should_not include( expected_mark.first )end
endThen /^I should see a navigation bar titled "([^\"]*)"$/ do |expected_mark|values = frankly_map( 'navigationItemView', 'accessibilityLabel' )values.should include(expected_mark)
endThen /^I should see an alert view titled "([^\"]*)"$/ do |expected_mark|values = frankly_map( 'alertView', 'message')puts valuesvalues.should include(expected_mark)
endThen /^I should not see an alert view$/ docheck_element_does_not_exist( 'alertView' )
endThen /^I should see an element of class "([^\"]*)" with name "([^\"]*)" with the following labels: "([^\"]*)"$/ do |className, classLabel, listOfLabels|arrayOfLabels = listOfLabels.split(',');arrayOfLabels.each do |label|check_element_exists("view marked:'#{classLabel}' parent view:'#{className}' descendant view marked:'#{label}'")end
endThen /^I should see an element of class "([^\"]*)" with name "([^\"]*)" with a "([^\"]*)" button$/ do |className, classLabel, buttonName|check_element_exists("view marked:'#{classLabel}' parent view:'#{className}' descendant button marked:'#{buttonName}'")
endThen /^I should not see a hidden button marked "([^\"]*)"$/ do |expected_mark|element_is_not_hidden("button marked:'#{expected_mark}'").should be_false
endThen /^I should see a nonhidden button marked "([^\"]*)"$/ do |expected_mark|element_is_not_hidden("button marked:'#{expected_mark}'").should be_true
endThen /^I should see an element of class "([^\"]*)"$/ do |className|element_is_not_hidden("view:'#{className}'")
endThen /^I should not see an element of class "([^\"]*)"$/ do |className|selector = "view:'#{className}'"element_exists_and_is_not_hidden = element_exists( selector ) && element_is_not_hidden(selector)element_exists_and_is_not_hidden.should be_false
end# -- Type/Fill in -- #When /^I type "([^\"]*)" into the "([^\"]*)" text field$/ do |text_to_type, field_name|text_fields_modified = frankly_map( "textField placeholder:'#{field_name}'", "setText:", text_to_type )raise "could not find text fields with placeholder '#{field_name}'" if text_fields_modified.empty?#TODO raise warning if text_fields_modified.count > 1
end# alias
When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |text_field, text_to_type|When %Q|I type "#{text_to_type}" into the "#{text_field}" text field|
endWhen /^I fill in text fields as follows:$/ do |table|table.hashes.each do |row|When %Q|I type "#{row['text']}" into the "#{row['field']}" text field|end
end# -- Rotate -- #
Given /^the device is in (a )?landscape orientation$/ do |ignored|# for some reason the simulator sometimes starts of reporting its orientation as 'flat'. Workaround for this is to rotate the device then wait a bitif 'flat' == frankly_current_orientationrotate_simulator_rightsleep 1end unless frankly_oriented_landscape?rotate_simulator_leftsleep 1raise "expected orientation to be landscape after rotating left, but it is #{frankly_current_orientation}" unless frankly_oriented_landscape?end
endGiven /^the device is in (a )?portrait orientation$/ do |ignored|# for some reason the simulator sometimes starts of reporting its orientation as 'flat'. Workaround for this is to rotate the device then wait a bitif 'flat' == frankly_current_orientationrotate_simulator_rightsleep 1end unless frankly_oriented_portrait?rotate_simulator_leftsleep 1raise "Expected orientation to be portrait after rotating left, but it is #{frankly_current_orientation}" unless frankly_oriented_portrait?end
endWhen /^I simulate a memory warning$/ dosimulate_memory_warning
endThen /^I rotate to the "([^\"]*)"$/ do |direction|if direction == "right"rotate_simulator_rightelsif direction == "left"rotate_simulator_leftelse raise %Q|Rotation direction specified ("#{direction}") is invalid. Please specify right or left.|endsleep 1
end# -- touch -- #
When /^I touch "([^\"]*)"$/ do |mark|selector = "view marked:'#{mark}' first"if element_exists(selector)touch( selector )elseraise "Could not touch [#{mark}], it does not exist."  endsleep 1
endWhen /^I touch "([^\"]*)" if exists$/ do |mark|sleep 1selector = "view marked:'#{mark}' first"if element_exists(selector)touch(selector)sleep 1end
endWhen /^I touch the first table cell$/ dotouch("tableViewCell first")
endWhen /^I touch the table cell marked "([^\"]*)"$/ do |mark|touch("tableViewCell marked:'#{mark}'")
endWhen /^I touch the (\d*)(?:st|nd|rd|th)? table cell$/ do |ordinal|ordinal = ordinal.to_i - 1touch("tableViewCell index:#{ordinal}")
endThen /I touch the following:/ do |table|values = frankly_map( 'view', 'accessibilityLabel' )table.raw.each do |expected_mark|touch( "view marked:'#{expected_mark}'" )sleep 2end
endWhen /^I touch the button marked "([^\"]*)"$/ do |mark|touch( "button marked:'#{mark}'" )
endWhen /^I touch the "([^\"]*)" action sheet button$/ do |mark|touch( "actionSheet threePartButton marked:'#{mark}'" )
endWhen /^I touch the (\d*)(?:st|nd|rd|th)? action sheet button$/ do |ordinal|ordinal = ordinal.to_itouch( "actionSheet threePartButton tag:#{ordinal}" )
endWhen /^I touch the (\d*)(?:st|nd|rd|th)? alert view button$/ do |ordinal|ordinal = ordinal.to_itouch( "alertView threePartButton tag:#{ordinal}" )
end# -- switch -- #When /^I flip switch "([^\"]*)" on$/ do |mark|selector = "view:'UISwitch' marked:'#{mark}'"views_switched = frankly_map( selector, 'setOn:animated:', true, true )raise "could not find anything matching [#{uiquery}] to switch" if views_switched.empty?
endWhen /^I flip switch "([^\"]*)" off$/ do |mark|selector = "view:'UISwitch' marked:'#{mark}'"views_switched = frankly_map( selector, 'setOn:animated:', false, true )raise "could not find anything matching [#{uiquery}] to switch" if views_switched.empty?
endWhen /^I flip switch "([^\"]*)"$/ do |mark|touch("view:'UISwitch' marked:'#{mark}'")
endThen /^switch "([^\"]*)" should be on$/ do |mark|
#  switch_states = frankly_map( "view:'Switch' marked:'#{mark}'", "isOn" )switch_states = frankly_map( "view accesibilityLabel:'#{mark}'", "isOn" )puts "test #{switch_states.inspect}"if switch_states == 0puts "Switch #{mark} is ON"elseputs "Switch #{mark} is OFF, flim switch ON"Then %Q|I flip switch "#{mark}"|end
endThen /^switch "([^\"]*)" should be off$/ do |mark|switch_states = frankly_map( "view:'UISwitch' marked:'#{mark}'", "isOn" )puts "test #{switch_states.inspect}"if switch_states == 0puts "Switch #{mark} is ON, flip switch OFF"Then %Q|I flip switch "#{mark}"|elseputs "Switch #{mark} is OFF"end
end# -- misc -- #When /^I wait for ([\d\.]+) second(?:s)?$/ do |num_seconds|num_seconds = num_seconds.to_fsleep num_seconds
endThen /^a pop\-over menu is displayed with the following:$/ do |table|sleep 1table.raw.each do |expected_mark|check_element_exists "actionSheet view marked:'#{expected_mark}'"end
endThen /^I navigate back$/ dotouch( "navigationItemButtonView" )
endWhen /^I dump the DOM$/ dodom = frankly_dump
endWhen /^I quit the simulator/ doquit_simulator
end

转载于:https://www.cnblogs.com/simonshi2012/archive/2011/08/31/2160734.html

Frank-Cucumber - Core Frank Steps相关推荐

  1. Cucumber入门之_argument

    a) Multi-line Text 在feature文件中,我们可以嵌入多行文本(multi-line string)作为参数,我们需要用一对三个双引号把我们的文本括起来.<The RSpec ...

  2. cucumber html模板,Cucumber使用进阶

    摘要 本文从实际使用Cucumber这一工具的角度,以Cucumber-JVM实现为基础,采用了不同的事例阐述了:如何编写feature文件,如何从feature文件生成对应的Steps,如何生成不同 ...

  3. Cucumber使用进阶

    摘要 本文从实际使用Cucumber这一工具的角度,以Cucumber-JVM实现为基础,采用了不同的事例阐述了:如何编写feature文件,如何从feature文件生成对应的Steps,如何生成不同 ...

  4. 源于Design Pattern Explanation with C++ Implementation的 设计模式 C++

    1.创建型模式 (Creational Pattern) 1.1 工厂模式(Factory Pattern ) 1.2  抽象工厂模式(Abstract Factory Pattern ) 1.3   ...

  5. 征文连载丨MogDB企业应用之七种武器

    2022年8月4日至9月9日,墨天轮社区联合云和恩墨发起了首届「MogDB 主题征文活动」,邀请各位技术从业者学习.使用 MogDB 数据库,分享使用心得与实战案例,一起探索这款融合了众多创新特性的商 ...

  6. nextcloud如何填写数据库_nextcloud安装教程

    2019.07.29更新强烈推荐使用群辉,至少网盘功能比较省心,同步功能也有,还支持各种娱乐性质的功能. 好了,进入正题 之前有一段时间在寻找作为个人网盘的一些系统或者软件,本来是期待那种类似seaf ...

  7. SitePoint播客#152:芬兰对面

    Episode 152 of The SitePoint Podcast is now available! This week the panel is made up of Louis Simon ...

  8. OpenGauss 3.0.0 (Lite 版)轻量版部署

    背景 openGauss 3.0.0 版本是openGauss社区继2.0.0之后发布的又一个Release版本,版本维护生命周期为3.5年.3.0.0版本在高性能.高可用.高安全.高智能.工具链等方 ...

  9. MogDB企业应用 之 七种武器

    MogDB企业应用 之 七种武器 如今江湖上最卷的门派,非国产数据库莫属.各位大侠们往往把精力放在拼内功(内核/架构).拼身法(性能).拼拳脚(功能/兼容性).拼江湖地位(生态/社区).然而好像并不怎 ...

  10. impdp 并行_Oracle expdp/impdp常用性能优化方法

    Oracle expdp/impdp常用性能优化方法 expdp/impdp在进行数据迁移时速度极快,通过一定的优化方法,我们让expdp和impdp跑得更加快 1,parallel,在很多oracl ...

最新文章

  1. 计算机导论成绩分为几部分,计算机导论复习题(选择部分)汇总.docx
  2. [Luogu] P4198 楼房重建
  3. java队列_RPC远程调用和消息队列MQ的区别
  4. OpenCV检测子像素中的角点位置
  5. matlab波形振幅,MATLAB正交振幅调制解调仿真分析(一)
  6. spring-boot注解详解(三)
  7. c3p0 0.9.1.2 配套mysql_连接数据库,使用c3p0技术连接MySQL数据库
  8. java求水电费_java水电费管理系统
  9. H5实现微信摇一摇功能
  10. 坦克世界 与服务器连接中断,坦克世界怎么老是显示与服务器连接已中断
  11. arch模型的思路_时间序列--ARCH模型
  12. java文件名中不能包含的字符,使用Java 7编写包含非英语字符的文件名时,zip条目不正确...
  13. C#Excel上传批量导入sqlserver
  14. 面试一家公司之前需要做的准备
  15. 看看淘宝的工程师如何评论12306
  16. docker 安装 Nginx 并配置反向代理
  17. UvaLive6441(期望概率dp)
  18. python3.x和python2.x唯一区别_Python3.x和Python2.x的区别
  19. 键盘录入 写入文件 quit时 结束
  20. LNK 2001错误 原因以及解决办法

热门文章

  1. ECMAScript-函数
  2. 无线测温采集设备及无线测温监控系统的选型指导-安科瑞王婧
  3. chemdraw如何改中文_教你如何快速自定义ChemDraw默认设置
  4. 论文笔记:Improving Conversational Recommender Systems via Knowledge Graph based Semantic Fusion(KDD2020)
  5. 【HDL】Verilog HDL仿真工具iverilog(Icarus Verilog)
  6. 课程设计---族谱管理系统(c++)
  7. 详解Maven多模块Spring Boot项目从创建到打包
  8. iOS之小功能模块--彩虹动画进度条学习和自主封装改进
  9. JUC学习 - 原子操作增强类LongAdder、LongAccumulator
  10. C++ 编写一个解释器