Ruby API 文档
1.Calabash-android启动
Apk的重签名: calabash-android resign ***.apk 作用:为了保证在虚拟机或真机上的apk正常运行。 Apk的运行: calabash-android run ***.apk
作用:启用apk 完成ruby测试。第一次运行的时候会在当前目录下生成test-server文件夹。 P:经过一些简单的测试,需要apk具有internet的权限,即:
2.calabash-android 查询 Apk的测试: calabash-android console ***.apk 若当前目录下也没有test-server文件夹,也会生成test-server文件夹。 查询apk界面的一些控件及组件,需要输入一下命令 start_test_server_in_background 作用是启动虚拟机运行当下的***.apk..如果不输入此命令,只需在虚拟机打开你当前要测的apk 。 Query 基本形式:query(uiquery,*args) 查询的结果是以数组的形式的。我们以button为例: query(“button”) 返回当前界面上所有的button 以args的键值对形式,最前面的为数组的下标,从0开始。 query(“button index:1”) 返回数组下标为‘1’的button的所有信息。 query(“button index:1”).first.keys 返回数组下标为'1'的button的所有的key。包括(id ,enable, contentDescription, class ,text ,rect ,description) query(“button”,”key”) 对应了3查询出来的所有的key,经测试有严格区分大小写,\和\查询不出. query(“button”,”text”,”length”) 返回button上text的长度 也是以args形式 测试只有\可以返回长度. 查询”id”时,如果某个button没有ID,将返回错误结果。 query(\将button的text以小写的单词返回。 P:同样适用于\“checkbox” “edittext””checkedtextview””radiobutton” radiogrounp”等等。 P:query(“button id:button”) 错误的查询方式。 P:对空格也严格把关 query(“button “)错误的查询。 Waiting 基本形式 Wait_for(options,&block) 我们在ruby中的使用: 1.wait_for_elements_exist(elements_arr, options={}) Eg:wait_for_elements_exist( [\ 在最大的等待时间为10秒的情况下 查询[\是否存在。存在返回真。 2.wait_for_elements_do_not_exist(elements_arr, options={}) Eg:wait_for_elements_do_not_exist( [\marked:'Save'\\marked:'Please sign in'\ 在最大的等待时间为2秒的情况下 marked对应了button的”text”的值 “*”可以表示缺省的”button”。不存在返回真。 3wait_for Eg:wait_for(:timeout => 5) { query(\ 这会检查是否存在一个匹配“button”,标明:”save”。它将等待最多 5秒(如果超过5秒传球失败)。它会发出查询,直到它被发现或5秒。 Assertions 1.check_element_exists(query) Eg:check_element_exists(\2.check_element_does_not_exist(query) 3.Check_view_with_mark_exists(expected_mark) Touch 基本形式 touch(uiquery,option={}) Eg:touch(\ *的缺省值可以是id 或text 。点击。 一些等价的表达式: touch(\touch(\ touch(query(\touch(query(\touch(query(\ Screenshot 基本形式: screenshot(options={:prefix=>nil, :name=>nil}) Eg:screenshot({:prefix => \ screenshot_embed(options={:prefix=>nil, :name=>nil, :label => nil}) Eg:screenshot_embed({:prefix => \如果前缀和名称是零,它会使用默认值。 注意到应用程序的截图和嵌入到cucumber reporters。 Pull and push files and folders from and to the device 基本形式 pull(remote, local) Eg:pull(\push(local, remote) Eg:push(\使用adb的规则同样适用于: 将无法从受限制的文件夹,如 /data/data 如果目标路径已经存在,它无预警覆盖 对于文件,必须提供完整的目标路径,即 将无法正常工作。 Read, write and clear SharedPreferences get_preferences(name) Eg:preferences = get_preferences(\可用于给定的名称,返回hash。 set_preferences(name, hash) Eg:set_preferences(\=> 8, :active => true}) 作为给定名称的首选项设置给定的hash。 clear_preferences(name) Eg:clear_preferences(\清除为给定的名称的preferences。 从一个activity到另一个activity Eg: When(/^用户进入到下一个界面 \ wait_for_activity arg1 end 必须有wait_for_activity activity 否则无法从另一个activity上获得焦点,即无法对另一个activity上的控件或组件进行操作。 1.Query Query(“*”) 查询界面上所有的控件 Query(“button”) 查询界面上所有的button,进过本人测试在android上xml文件上的所有控件都可以查到,我们由此也可以猜测到查询就是通过读取xml上的信息来进行筛选匹配的。 Query(“* marked:?text?”) 查询界面文本信息为’text‘的所有控件,因为我们点击界面大都都已’text‘来来标明控件,所以这个很有必要。 2.Touch (1) Button 通过id来点击button Touch(“button id:? ? ”) 通过文本标记来点击button Touch(“button marked:? ? ”) performAction('press_button_with_text', buttonText) 通过buttonNumber来点击图片按钮 performAction('press_image_button_number', buttonNumber) 通过text来点击文本 performAction('click_on_text',text) 点击屏幕的位置 performAction('click_on_screen',x, y) Eg: Then /^I click on screen (\\d+)% from the left and (\\d+)% from the top$/ do |x, y| performAction('click_on_screen',x, y) end Then /^I touch the \ performAction('click_on_text',text) End Given /^I press the \ performAction('press_button_with_text', buttonText) 或者 Touch(“button marked:? buttonText ? ”)
相关推荐: