appium
Posted 我是Jimny
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了appium相关的知识,希望对你有一定的参考价值。
电话键
KEYCODE_CALL 拨号键 5
KEYCODE_ENDCALL 挂机键 6
KEYCODE_HOME 按键Home 3
KEYCODE_MENU 菜单键 82
KEYCODE_BACK 返回键 4
KEYCODE_SEARCH 搜索键 84
KEYCODE_CAMERA 拍照键 27
KEYCODE_FOCUS 拍照对焦键 80
KEYCODE_POWER 电源键 26
KEYCODE_NOTIFICATION 通知键 83
KEYCODE_MUTE 话筒静音键 91
KEYCODE_VOLUME_MUTE 扬声器静音键 164
KEYCODE_VOLUME_UP 音量增加键 24
KEYCODE_VOLUME_DOWN 音量减小键 25
控制键
KEYCODE_ENTER 回车键 66
KEYCODE_ESCAPE ESC键 111
KEYCODE_DPAD_CENTER 导航键 确定键 23
KEYCODE_DPAD_UP 导航键 向上 19
KEYCODE_DPAD_DOWN 导航键 向下 20
KEYCODE_DPAD_LEFT 导航键 向左 21
KEYCODE_DPAD_RIGHT 导航键 向右 22
KEYCODE_MOVE_HOME 光标移动到开始键 122
KEYCODE_MOVE_END 光标移动到末尾键 123
KEYCODE_PAGE_UP 向上翻页键 92
KEYCODE_PAGE_DOWN 向下翻页键 93
KEYCODE_DEL 退格键 67
KEYCODE_FORWARD_DEL 删除键 112
KEYCODE_INSERT 插入键 124
KEYCODE_TAB Tab键 61
KEYCODE_NUM_LOCK 小键盘锁 143
KEYCODE_CAPS_LOCK 大写锁定键 115
KEYCODE_BREAK Break/Pause键 121
KEYCODE_SCROLL_LOCK 滚动锁定键 116
KEYCODE_ZOOM_IN 放大键 168
KEYCODE_ZOOM_OUT 缩小键 169
组合键
KEYCODE_ALT_LEFT Alt+Left
KEYCODE_ALT_RIGHT Alt+Right
KEYCODE_CTRL_LEFT Control+Left
KEYCODE_CTRL_RIGHT Control+Right
KEYCODE_SHIFT_LEFT Shift+Left
KEYCODE_SHIFT_RIGHT Shift+Right
基本
KEYCODE_0 按键‘0‘ 7
KEYCODE_1 按键‘1‘ 8
KEYCODE_2 按键‘2‘ 9
KEYCODE_3 按键‘3‘ 10
KEYCODE_4 按键‘4‘ 11
KEYCODE_5 按键‘5‘ 12
KEYCODE_6 按键‘6‘ 13
KEYCODE_7 按键‘7‘ 14
KEYCODE_8 按键‘8‘ 15
KEYCODE_9 按键‘9‘ 16
KEYCODE_A 按键‘A‘ 29
KEYCODE_B 按键‘B‘ 30
KEYCODE_C 按键‘C‘ 31
KEYCODE_D 按键‘D‘ 32
KEYCODE_E 按键‘E‘ 33
KEYCODE_F 按键‘F‘ 34
KEYCODE_G 按键‘G‘ 35
KEYCODE_H 按键‘H‘ 36
KEYCODE_I 按键‘I‘ 37
KEYCODE_J 按键‘J‘ 38
KEYCODE_K 按键‘K‘ 39
KEYCODE_L 按键‘L‘ 40
KEYCODE_M 按键‘M‘ 41
KEYCODE_N 按键‘N‘ 42
KEYCODE_O 按键‘O‘ 43
KEYCODE_P 按键‘P‘ 44
KEYCODE_Q 按键‘Q‘ 45
KEYCODE_R 按键‘R‘ 46
KEYCODE_S 按键‘S‘ 47
KEYCODE_T 按键‘T‘ 48
KEYCODE_U 按键‘U‘ 49
KEYCODE_V 按键‘V‘ 50
KEYCODE_W 按键‘W‘ 51
KEYCODE_X 按键‘X‘ 52
KEYCODE_Y 按键‘Y‘ 53
KEYCODE_Z 按键‘Z‘ 54
*** Settings ***
Library AppiumLibrary
Library Collections
Library String
Library Dialogs
*** Test Cases ***
打开app
Comment Open Application http://localhost:4723/wd/hub alias=tudouapp platformName=android platformVersion=4.4 deviceName=‘Android Simulator‘
... app=${CURDIR}/Tudou_Phone_tudouweb.apk
Comment Open Application http://localhost:4723/wd/hub alias=tudouapp platformName=Android platformVersion=4.4 deviceName=‘Android Simulator‘
... appActivity=com.tudou.ui.activity.WelcomeActivity appPackage=com.tudou.android
Comment Open Application http://localhost:4723/wd/hub alias=tudouapp platformName=Android platformVersion=4.4 deviceName=‘Android Simulator‘
... browserName=Chrome
Comment Go To Url http://www.baidu.com
后台app
Open Application http://localhost:4723/wd/hub alias=tudouapp platformName=Android platformVersion=4.4 deviceName=‘Android Simulator‘ appActivity=com.tudou.ui.activity.WelcomeActivity
... appPackage=com.tudou.android
sleep 10s
Background App 5
关闭app
Open Application http://localhost:4723/wd/hub alias=tudouapp platformName=Android platformVersion=4.4 deviceName=‘Android Simulator‘ appActivity=com.tudou.ui.activity.WelcomeActivity
... appPackage=com.tudou.android
sleep 10s
Close All Applications
删除app
Open Application http://localhost:4723/wd/hub alias=tudouapp platformName=Android platformVersion=4.4 deviceName=‘Android Simulator‘ appActivity=com.tudou.ui.activity.WelcomeActivity
... appPackage=com.tudou.android
Remove Application com.tudou.android
重置app
Open Application http://localhost:4723/wd/hub alias=tudouapp platformName=Android platformVersion=4.4 deviceName=‘Android Simulator‘ appActivity=com.tudou.ui.activity.WelcomeActivity
... appPackage=com.tudou.android
Pause Execution
Reset Application
定位
Open Application http://localhost:4723/wd/hub alias=tudouapp platformName=Android platformVersion=4.4 deviceName=‘Android Simulator‘ appActivity=com.tudou.ui.activity.WelcomeActivity
... appPackage=com.tudou.android
Pause Execution
Comment Click Element id=com.tudou.android:id/mytudouText
Comment Click Element name=我的
Comment Click Element xpath=//android.widget.TextView[contains(@text,‘我的‘)]
Comment Click Element class="android".widget.TextView
Click Element android=new UiSelector().text("我的")
Pause Execution
Close All Applications
输入
Open Application http://localhost:4723/wd/hub alias=tudouapp platformName=Android platformVersion=4.4 deviceName=‘Android Simulator‘ appActivity=com.tudou.ui.activity.WelcomeActivity
... appPackage=com.tudou.android unicodeKeyboard=${True} resetKeyboard=${True}
Pause Execution
Comment Input Text id=com.tudou.android:id/login_name asdasd
Comment Input Text id=com.tudou.android:id/login_pwd 2312121
Comment Input Value id=com.tudou.android:id/login_name 34534534sdf
按键
Open Application http://localhost:4723/wd/hub alias=tudouapp platformName=Android platformVersion=4.4 deviceName=‘Android Simulator‘ appActivity=com.tudou.ui.activity.WelcomeActivity
... appPackage=com.tudou.android unicodeKeyboard=${True} resetKeyboard=${True}
Pause Execution
Comment Press Keycode 3
Comment Press Keycode 24
清空内容
Open Application http://localhost:4723/wd/hub alias=tudouapp platformName=Android platformVersion=4.4 deviceName=‘Android Simulator‘ appActivity=com.tudou.ui.activity.WelcomeActivity
... appPackage=com.tudou.android unicodeKeyboard=${True} resetKeyboard=${True}
Pause Execution
Clear Text id=com.tudou.android:id/login_name
点击按钮
Open Application http://localhost:4723/wd/hub alias=tudouapp platformName=Android platformVersion=4.4 deviceName=‘Android Simulator‘ appActivity=com.tudou.ui.activity.WelcomeActivity
... appPackage=com.tudou.android unicodeKeyboard=${True} resetKeyboard=${True}
Pause Execution
Click Button 我的
Comment Click Button 确定
点击元素
Open Application http://localhost:4723/wd/hub alias=tudouapp platformName=Android platformVersion=4.4 deviceName=‘Android Simulator‘ appActivity=com.tudou.ui.activity.WelcomeActivity
... appPackage=com.tudou.android unicodeKeyboard=${True} resetKeyboard=${True}
Pause Execution
Click Element name=我的
Click Element name=马上登录
Click Element id=com.tudou.android:id/title_right_text
点击坐标
Open Application http://localhost:4723/wd/hub alias=tudouapp platformName=Android platformVersion=4.4 deviceName=‘Android Simulator‘ appActivity=com.tudou.ui.activity.WelcomeActivity
... appPackage=com.tudou.android unicodeKeyboard=${True} resetKeyboard=${True}
Pause Execution
Click A Point 300 200
tap
Open Application http://localhost:4723/wd/hub alias=tudouapp platformName=Android platformVersion=4.4 deviceName=‘Android Simulator‘ appActivity=com.tudou.ui.activity.WelcomeActivity
... appPackage=com.tudou.android unicodeKeyboard=${True} resetKeyboard=${True}
Pause Execution
Tap name=我的
Tap name=马上登录
Tap id=com.tudou.android:id/title_right_text
Landscape
Open Application http://localhost:4723/wd/hub alias=tudouapp platformName=Android platformVersion=4.4 deviceName=‘Android Simulator‘ browserName=Chrome
... unicodeKeyboard=${True} resetKeyboard=${True}
Pause Execution
Landscape
隐藏键盘
Open Application http://localhost:4723/wd/hub alias=tudouapp platformName=Android platformVersion=4.4 deviceName=‘Android Simulator‘ appActivity=com.tudou.ui.activity.WelcomeActivity
... appPackage=com.tudou.android unicodeKeyboard=${True} resetKeyboard=${True}
Pause Execution
Hide Keyboard
摇一摇
Open Application http://localhost:4723/wd/hub alias=tudouapp platformName=Android platformVersion=4.4 deviceName=‘Android Simulator‘ appActivity=com.tudou.ui.activity.WelcomeActivity
... appPackage=com.tudou.android unicodeKeyboard=${True} resetKeyboard=${True}
Pause Execution
Shake
network
Open Application http://localhost:4723/wd/hub alias=tudouapp platformName=Android platformVersion=4.4 deviceName=‘Android Simulator‘ appActivity=com.tudou.ui.activity.WelcomeActivity
... appPackage=com.tudou.android unicodeKeyboard=${True} resetKeyboard=${True}
Pause Execution
${a} Get Network Connection Status
Set Network Connection Status 1
滑动
Open Application http://localhost:4723/wd/hub alias=tudouapp platformName=Android platformVersion=4.4 deviceName=‘Android Simulator‘ appActivity=com.tudou.ui.activity.WelcomeActivity
... appPackage=com.tudou.android unicodeKeyboard=${True} resetKeyboard=${True}
Pause Execution
Swipe 500 500 100 500 500
sleep 2s
Swipe 500 500 100 500 500
scroll
Open Application http://localhost:4723/wd/hub alias=tudouapp platformName=Android platformVersion=4.4 deviceName=‘Android Simulator‘ appActivity=com.tudou.ui.activity.WelcomeActivity
... appPackage=com.tudou.android unicodeKeyboard=${True} resetKeyboard=${True}
Pause Execution
Comment Scroll name=牛男网 name=畅所欲言秀
Scroll To id=com.tudou.android:id/channel_subclass
zoom
Open Application http://localhost:4723/wd/hub alias=tudouapp platformName=Android platformVersion=4.4 deviceName=‘Android Simulator‘ appActivity=com.baidu.baidumaps.WelcomeScreen
... appPackage=com.baidu.BaiduMap unicodeKeyboard=${True} resetKeyboard=${True}
Pause Execution
Pinch id=com.tudou.android:id/channel_subclass 200% 50
get
Open Application http://localhost:4723/wd/hub alias=tudouapp platformName=Android platformVersion=4.4 deviceName=‘Android Simulator‘ appActivity=com.tudou.ui.activity.WelcomeActivity
... appPackage=com.tudou.android unicodeKeyboard=${True} resetKeyboard=${True}
Pause Execution
Comment Get Element Attribute
Comment Get Element Location
Comment Get Element Size
Comment Get Elements
Comment Get Source
Comment Log Source
shoudl
Element Attribute Should Match
Element Name Should Be
Element Should Be Disabled
Element Should Be Enabled
Element Value Should Be
Page Should Contain Element
Page Should Contain Text
Page Should Not Contain Element
Page Should Not Contain Text
webview
Open Application http://localhost:4723/wd/hub alias=tudouapp platformName=Android platformVersion=4.4 deviceName=‘Android Simulator‘ appActivity=com.tudou.ui.activity.WelcomeActivity
... appPackage=com.tudou.android unicodeKeyboard=${True} resetKeyboard=${True}
Pause Execution
${a} Get Contexts
${b} Get Current Context
Switch To Context ${a[1]}
Log Source
Comment Click Element xpath=//a[text()=‘开挂!那些牛逼闪闪的牛人们‘]
Go To Url http://www.w3school.com.cn/tiy/t.asp?f=jsref_dialog_create
Pause Execution
Sleep 2s
Select Frame name=i
Click Element //button[text()=‘试一下‘]
Sleep 2s
Unselect Frame
Click Element //input[@value=‘提交代码‘]
${url} Get Element Attribute xpath=//*[@id="footer"]/p/a href
webview2
Open Application http://localhost:4723/wd/hub alias=tudouapp platformName=Android platformVersion=4.4 deviceName=‘Android Simulator‘ appActivity=com.tudou.ui.activity.WelcomeActivity
... appPackage=com.tudou.android
Pause Execution
${a} Get Contexts
${b} Get Current Context
Switch To Context ${a[1]}
Go To Url http://www.w3school.com.cn/tiy/loadtext.asp?f=html_dropdownbox
Pause Execution
Wait Until Page Contains Element name=cars
Select From List name=cars Fiat
Comment Click Element name=cars
Comment Switch To Context ${a[0]}
Comment Click Element name=Audi
Comment Switch To Context ${a[1]}
Get Element Attribute 图片位置 src
webview3
Open Application http://localhost:4723/wd/hub alias=tudouapp platformName=Android platformVersion=4.4 deviceName=‘Android Simulator‘ appActivity=com.tudou.ui.activity.WelcomeActivity
... appPackage=com.tudou.android
Pause Execution
${contexts} Get Contexts
Switch To Context ${contexts[1]}
Click Element //a[text()=‘测试‘]
以上是关于appium的主要内容,如果未能解决你的问题,请参考以下文章