资源预览内容
第1页 / 共9页
第2页 / 共9页
第3页 / 共9页
第4页 / 共9页
第5页 / 共9页
第6页 / 共9页
第7页 / 共9页
第8页 / 共9页
第9页 / 共9页
亲,该文档总共9页全部预览完了,如果喜欢就下载吧!
资源描述
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,经测试有严格区分大小写,rect和description查询不出.query(“button”,”text”,”length”)返回 button 上 text 的长度 也是以 args 形式 测试只有id text可以返回长度.查询”id”时,如果某个 button 没有 ID,将返回错误结果。query(button,text,toLowerCase)将 button 的 text 以小写的单词返回。P:同样适用于button,textview “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( TextView text:#arg1, :timeout = 10)在最大的等待时间为 10 秒的情况下 查询TextView text:#arg1是否存在。存在返回真。2.wait_for_elements_do_not_exist(elements_arr, options=)Eg:wait_for_elements_do_not_exist( button marked:Save, * marked:Please sign in, :timeout = 2)在最大的等待时间为 2 秒的情况下 marked 对应了 button 的”text”的值 “*”可以表示缺省的”button”。不存在返回真。3wait_forEg:wait_for(:timeout = 5) query(button marked:Save).size 0 这会检查是否存在一个匹配“button”,标明:”save”。它将等待最多 5 秒(如果超过 5 秒传球失败) 。它会发出查询,直到它被发现或 5 秒。Assertions1.check_element_exists(query)Eg:check_element_exists(view marked:#expected_mark)2.check_element_does_not_exist(query)3.Check_view_with_mark_exists(expected_mark)Touch基本形式touch(uiquery,option=)Eg:touch(* marked:Save)*的缺省值可以是 id 或 text 。点击。一些等价的表达式:touch(button index:0)touch(button)touch(query(button index:0)touch(query(button).first)touch(query(button)Screenshot基本形式:screenshot(options=:prefix=nil, :name=nil)Eg:screenshot(:prefix = /tmp, :name=my.png)screenshot_embed(options=:prefix=nil, :name=nil, :label = nil)Eg:screenshot_embed(:prefix = /tmp, :name=my.png, :label = Mine)如果前缀和名称是零,它会使用默认值。注意到应用程序的截图和嵌入到 cucumber reporters。Pull and push files and folders from and to the device基本形式pull(remote, local)Eg:pull(/sdcard/file.jpg, file.jpg)push(local, remote)Eg:push(file.jpg, /sdcard/file.jpg)使用 adb 的规则同样适用于:将无法从受限制的文件夹,如 /data/data如果目标路径已经存在,它无预警覆盖对于文件,必须提供完整的目标路径,即将无法正常工作。Read, write and clear SharedPreferencesget_preferences(name)Eg:preferences = get_preferences(my_preferences)可用于给定的名称,返回 hash。set_preferences(name, hash)Eg:set_preferences(my_preferences, :name = wadus, :email = waduswadus.com, :id = 8, :active = true)作为给定名称的首选项设置给定的 hash。clear_preferences(name)Eg:clear_preferences(my_preferences)清除为给定的名称的 preferences。从一个 activity 到另一个 activityEg:When(/用户进入到下一个界面 (.*?)$/) do |arg1| wait_for_activity arg1end必须有 wait_for_activity activity 否则无法从另一个 activity 上获得焦点,即无法对另一个activity 上的控件或组件进行操作。1.QueryQuery(“*”)查询界面上所有的控件Query(“button”)查询界面上所有的 button,进过本人测试在 android 上 xml 文件上的所有控件都可以查到,我们由此也可以猜测到查询就是通过读取 xml 上的信息来进行筛选匹配的。Query(“* marked:text”)查询界面文本信息为text的所有控件,因为我们点击界面大都都已text来来标明控件,所以这个很有必要。2.Touch(1 ) Button通过 id 来点击 button Touch(“button id: ”)通过文本标记来点击 buttonTouch(“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)endThen /I touch the (*) text$/ do |text|performAction(click_on_text,text)EndGiven /I press the (*) button$/ do |buttonText|performAction(press_button_with_text, buttonText) 或者 Touch(“button marked: buttonText ”)End(2)spinner下拉框的选取及点击Then /I select (*) from (*)$/ do |item_text, spinner_content_description|performAction(select_item_from_named_spinner, spinner_content_description, item_text)End(3)checkbox选择框的选取及点击Then /I toggle checkbox number (d+)$/ do |checkboxNumber|performAction(toggle_numbered_checkbox, checkboxNumber) End(4)系统控件返回键Then /I go back$/ doperformAction(go_back)end菜单键Then /I press the menu key$/ doperformAction(press_menu)end发送键(确认键)Then /I press the enter button$/ doperformAction(send_key_enter)end左划Then /I swipe left$/ doperformAction(swipe, left)end右划Then /I swipe right$/ doperformAction(swipe, right)End向下滚动Then /I scroll down$/ doperformAction(scroll_down)end向上滚动Then /I scroll up$/ doperformAction(
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号