废话不多说,直接来实践(二),本次基于Android手机Settings模块下的search功能进行的自动化测试,代码如下 :
1 *** Settings *** 2 Library AppiumLibrary 3 4 *** Variables *** 5 ${REMOTE_URL} http://localhost:4723/wd/hub 6 ${platformName} Android 7 ${platformVersion} 8.1.0 8 ${deviceName} Kemi's Phone 9 ${appPackage} com.android.settings 10 ${appActivity} .Settings 11 12 *** Test Cases *** 13 case 1 14 [Documentation] Test Settings Search Function # Case说明 15 Open Application ${REMOTE_URL} platformName=${platformName} platformVersion=${platformVersion} deviceName=${deviceName} appPackage=${appPackage} appActivity=${appActivity} # 启动Settings应用 16 Click Element accessibility_id=Search settings # 点击Settings下的搜索框 17 Input Text id=android:id/search_src_text nfc # 模拟输入nfc 18 sleep 1 # 等待1s 19 Element Should Be Visible id=android:id/title # 判断搜索结果存在 20 Click Element xpath=//android.widget.TextView[contains(@text,'NFC')] # 点击搜索结果NFC 21 sleep 1 22 Click Element accessibility_id=Navigate up 23 Click Element accessibility_id=Clear query # 点击搜索框后的清除键 24 Click Element accessibility_id=Navigate up # 点击搜索界面的返回键 25 Press Keycode 4 # 模拟按导航栏返回键(返回手机主屏幕)
一切如代码中注释的一样,手机自动完成一系列测试。