calabashandroidAPI文档.docx
- 文档编号:15063400
- 上传时间:2023-06-30
- 格式:DOCX
- 页数:12
- 大小:18.55KB
calabashandroidAPI文档.docx
《calabashandroidAPI文档.docx》由会员分享,可在线阅读,更多相关《calabashandroidAPI文档.docx(12页珍藏版)》请在冰点文库上搜索。
calabashandroidAPI文档
calabash-androidAPI文档
RubyAPI文档1.Calabash-android启动
Apk的重签名:
calabash-androidresign***.apk作用:
为了保证在虚拟机或真机上的apk正常运行。
Apk的运行:
calabash-androidrun***.apk作用:
启用apk完成ruby测试。
第一次运行的时候会在当前目录下生成test-server文件夹。
P:
经过一些简单的测试,需要apk具有internet的权限,即:
name="android.permission.INTERNET"/> 2.calabash-android查询 Apk的测试: calabash-androidconsole***.apk若当前目录下也没有test-server文件夹,也会生成test-server文件夹。 查询apk界面的一些控件及组件,需要输入一下命令 start_test_server_in_background作用是启动虚拟机运行当下的***.apk..如果不输入此命令,只需在虚拟机打开你当前要测的apk。 Query 基本形式: query(uiquery,*args) 查询的结果是以数组的形式的。 我们以button为例: query(“button”) 返回当前界面上所有的button以args的键值对形式,最前面的为数组的下标,从0开始。 query(“buttonindex: 1”) 返回数组下标为‘1’的button的所有信息。 query(“buttonindex: 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(“buttonid: button”)错误的查询方式。 P: 对空格也严格把关query(“button“)错误的查询。 Waiting 基本形式 Wait_for(options,&block) 我们在ruby中的使用: 1.wait_for_elements_exist(elements_arr,options={})Eg: wait_for_elements_exist(["TextViewtext: '#{arg1}'"],: timeout=>10) 在最大的等待时间为10秒的情况下查询["TextViewtext: '#{arg1}'"]是否存在。 存在返回真。 2.wait_for_elements_do_not_exist(elements_arr,options={}) Eg: wait_for_elements_do_not_exist(["buttonmarked: 'Save'","*marked: 'Pleasesign in'"],: timeout=>2) 在最大的等待时间为2秒的情况下marked对应了button的”text”的值“*”可以表示缺省的”button”。 不存在返回真。 3wait_for Eg: wait_for(: timeout=>5){query("buttonmarked: 'Save'").size>0} 这会检查是否存在一个匹配“button”,标明: ”save”。 它将等待最多5秒(如果超过5秒传球失败)。 它会发出查询,直到它被发现或5秒。 Assertions 1.check_element_exists(query) Eg: check_element_exists("viewmarked: '#{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("buttonindex: 0") touch("button") touch(query("buttonindex: 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"}) 如果前缀和名称是零,它会使用默认值。 注意到应用程序的截图和嵌入到cucumberreporters。 Pullandpushfilesandfoldersfromandtothedevice 基本形式 pull(remote,local) Eg: pull("/sdcard/file.jpg","file.jpg") push(local,remote) Eg: push("file.jpg","/sdcard/file.jpg") 使用adb的规则同样适用于: 将无法从受限制的文件夹,如/data/data 如果目标路径已经存在,它无预警覆盖 对于文件,必须提供完整的目标路径,即 将无法正常工作。 Read,writeandclearSharedPreferencesget_preferences(name) Eg: preferences=get_preferences("my_preferences")可用于给定的名称,返回hash。 set_preferences(name,hash) Eg: set_preferences("my_preferences",{: name=>"wadus",: email=>"wadus@",: id =>8,: active=>true}) 作为给定名称的首选项设置给定的hash。 clear_preferences(name) Eg: clear_preferences("my_preferences") 清除为给定的名称的preferences。 从一个activity到另一个activity Eg: When(/^用户进入到下一个界面"(.*? )"$/)do|arg1| wait_for_activityarg1 end 必须有wait_for_activityactivity否则无法从另一个activity上获得焦点,即无法对另一个activity上的控件或组件进行操作。 1.Query Query(“*”) 查询界面上所有的控件 Query(“button”) 查询界面上所有的button,进过本人测试在android上xml文件上的所有控件都可以查到,我们由此也可以猜测到查询就是通过读取xml上的信息来进行筛选匹配的。 Query(“*marked: ? text? ”) 查询界面文本信息为’text‘的所有控件,因为我们点击界面大都都已’text‘来来标明控件,所以这个很有必要。 2.Touch (1)Button 通过id来点击button Touch(“buttonid: ? „”) 通过文本标记来点击button Touch(“buttonmarked: ? „”) 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/^Iclickonscreen(\d+)%fromtheleftand(\d+)%fromthetop$/do|x,y| performAction('click_on_screen',x,y) end Then/^Itouchthe"([^\"]*)"text$/do|text| performAction('click_on_text',text) End Given/^Ipressthe"([^\"]*)"button$/do|buttonText| performAction('press_button_with_text',buttonText) 或者Touch(“buttonmarked: ? buttonText„”) End (2)spinner 下拉框的选取及点击 Then/^Iselect"([^\"]*)"from"([^\"]*)"$/do|item_text,spinner_content_description| performAction('select_item_from_named_spinner',spinner_content_description,item_text) End (3)checkbox 选择框的选取及点击 Then/^Itogglecheckboxnumber(\d+)$/do|checkboxNumber| performAction('toggle_numbered_checkbox',checkboxNumber) End (4)系统控件 返回键 Then/^Igoback$/do performAction('go_back') end 菜单键 Then/^Ipressthemenukey$/do performAction('press_menu')end 发送键(确认键) Then/^Ipresstheenterbutton$/do performAction('send_key_enter')end 左划 Then/^Iswipeleft$/do performAction('swipe','left')end 右划 Then/^Iswiperight$/do performAction('swipe','right')End 向下滚动 Then/^Iscrolldown$/do performAction('scroll_down') end 向上滚动 Then/^Iscrollup$/do performAction('scroll_up') end 3.Wait 等待时间 Then/^Iwaitfor(\d+)seconds$/do|seconds| performAction('wait',seconds) End 等待文本出现 Then/^Iwaitfor"([^\"]*)"toappear$/do|text| performAction('wait_for_text',text)End 在一定时间内等待文本出现 Then/^Iwaitupto(\d+)secondsfor"([^\"]*)"toappear$/do|timeout,text| performAction('wait_for_text',text,timeout)End 等待table的出现 Then/^Iwaitforthe"([^\"]*)"tabtoappear$/do|tab| performAction('wait_for_tab',tab)End 4.Assert 断言text Then/^Iseethetext"([^\"]*)"$/do|text| performAction('assert_text',text,true)En 断言activity Then/^the"([^\"]*)"activityshouldbeopen$/do|expected_activity| actual_activity=performAction('get_activity_name')['message'] raise"Thecurrentactivityis#{actual_activity}"unless(actual_activity==expected_activity||actual_activity==expected_activity+'Activity') End 断言list Then/^Ishouldseefollowinglist: $/do|expected_table| result=performAction('get_list_item_text') response_table=result['bonusInformation'] response_table.each_with_indexdo|row_data,index| row_data=JSON.parse(row_data) response_table[index]=row_data end expected_table.diff! (response_table) End 断言list的某一条记录 Then/^The"([^\"]*)"forrow(\d+)shouldbe"([^\"]*)"$/do|view_id,row,value| response=performAction('get_list_item_properties','1',row)['bonusInformation'] response=JSON.parse(response[0]) if(response['children']) found_id=false response['children'].eachdo|view| if(view['id']==view_id) raise"Textis#{view['text']},expected#{value}"unless(view['text']==value) found_id=true end end raise"CouldnotfindviewwithID: #{view_id}"unless(found_id) else raise"IDis#{response['id']},expected#{view_id}"unless(response['id']==view_id) raise"Textis#{response['text']},expected#{view_id}"unless(response['text']==value) end End 断言TimePicker时间 Given/^Isetthetimeto"(\d\d: \d\d)"onTimePickerwithindex"([^\"]*)"$/do|time,index| performAction('set_time_with_index',time,index) end 断言时间 Given/^Isetthe"([^\"]*)"timeto"(\d\d: \d\d)"$/do|content_description,time| performAction('set_time_with_description',content_description,time)end 5enter_text 搜索框输入 Then/^Ienter"([^\"]*)"intosearchfield$/do|text| performAction('enter_query_into_numbered_field',text,1)end Then/^Ienter"([^\"]*)"intosearchfieldnumber(\d+)$/do|text,number| performAction('enter_query_into_numbered_field',text,number)End Text的输入 Then/^Ienter"([^\"]*)"into"([^\"]*)"$/do|text,name| performAction('enter_text_into_named_field',text,name)end 清除 Then/^Iclear"([^\"]*)"$/do|name| performAction('clear_named_field',name) End 在DatePicker上输入时间 Given/^Isetthedateto"(\d\d-\d\d-\d\d\d\d)"onDatePickerwithindex"([^\"]*)"$/do|date, index| performAction('set_date_with_index',date,index) end 自定义的输入时间 Given/^Isetthe"([^\"]*)"dateto"(\d\d-\d\d-\d\d\d\d)"$/do|content_description,date| performAction('set_date_with_description',content_description,date)End 6.Long_press 长按并选择编号 Then/^Ilongpress"([^\"]*)"andselectitemnumber"([^\"]*)"$/do|text_to_press,index| performAction('press_long_on_text_and_select_with_index',text_to_press,index) end 长按并选择内容 Then/^Ilongpress"([^\"]*)"andselect"([^\"]*)"$/do|text_to_press,context_text| performAction('press_long_on_text_and_select_with_text',text_to_press,context_text) end 长按 Then/^Ilongpress"([^\"]*)"$/do|text_to_press| performAction('press_long_on_text',text_to_press)end 新增: 点击页面上的图片按钮 performAction("press_image_button_number","2")从1开始 点击listview中的某项 performAction('press_list_item',10,0) 第二个参数最多只能点击屏幕上显示的个数 第三个参数表示屏幕上的第几个listitem 对于继承于listview的gridview以及自己写的继承类同样适用 获得当前activity的名字 puts(performAction("get_activity_name")) 样例输出: {"bonusInformation"=>[],"message"=>"LoginActivity","success"=>true} Puts(performAction("get_activity_name")[“message”]) 将应用置为横屏 performAction("set_activity_orientation","landscape")竖屏 performAction("set_activity_orientation","portrait") performAction("finish_opened_activities")关闭所有activity
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- calabashandroidAPI 文档
![提示](https://static.bingdoc.com/images/bang_tan.gif)