在之前的博客“Robot Framework + Appium测试Android设备”,我们已经介绍了如何使用Robot Framework和Appium测试Android设备,如果对这部分还不熟悉的童鞋,可以参考本人之前的博客。
本文分享一个Test Suit, Bluetooth测试, 包括蓝牙打开, 扫描, 连接.
Test Suit 6, Bluetooth测试, 包括蓝牙打开, 扫描, 连接.
测试步骤如下,
1. 打开Setting App;
2. 点击进入Bluetooth页面;
2.1 Test Case 1: 打开蓝牙;
2.2 Test Case 2: 蓝牙扫描;
2.3 Test Case 3: 蓝牙连接;
示例代码如下,
*** Settings ***
Suite Setup Open Settings App
Suite Teardown Close Application
Library AppiumLibrary
*** Variables ***
${BT_HEADSET_NAME} BTD110
*** Test Cases ***
Test Case 1: Turn On Bluetooth
[Tags] Bluetooth Test
Turn On Bluetooth
Test Case 2: Refresh Bluetooth
[Tags] Bluetooth Test
Refresh Bluetooth Device List
Test Case 3: Connect Bluetooth
[Tags] Bluetooth Test
Connect Bluetooth Headset ${BT_HEADSET_NAME}
*** Keywords ***
Open Settings App
Open Application http://localhost:4723/wd/hub platformName=Android platformVersion=6.0.1 deviceName=dev_name appPackage=com.android.settings appActivity=.Settings
Sleep 2s
Open Bluetooth Setting Page
Open Bluetooth Setting Page
Log Click the "Bluetooth" Label
Wait Until Page Contains Element xpath=//*[contains(@text, 'Bluetooth')] 10 Can NOT find "Bluetooth" label
Click Element xpath=//*[contains(@text, 'Bluetooth')]
Turn On Bluetooth
Wait Until Page Contains Element xpath=//*[contains(@resource-id, 'id/switch_widget')]
Sleep 1s
${wifi_status} = Get Element Attribute xpath=//*[contains(@resource-id, 'id/switch_widget')] text
Run Keyword If '${wifi_status}' != 'ON' Click Element xpath=//*[contains(@resource-id, 'id/switch_widget')]
Refresh Bluetooth Device List
Click Element xpath=//*[contains(@content-desc, 'More options')]
Sleep 2s
Wait Until Page Contains Element xpath=//*[contains(@text, 'Refresh')] 20 Can NOT find "Refresh"
${count} Get Matching Xpath Count xpath=//*[contains(@text, 'Refresh')]
Run Keyword If ${count} > 0 Click Element xpath=//*[contains(@text, 'Refresh')]
Connect Bluetooth Headset
[Arguments] ${bluetooth_name}
Log Step 1: Click the headset ${bluetooth_name}
Wait Until Page Contains Element xpath=//*[contains(@text, '${bluetooth_name}')] 10 Can NOT find ${bluetooth_name}
Click Element xpath=//*[contains(@text, '${bluetooth_name}')]
Sleep 2s
${count} Get Matching Xpath Count xpath=//*[contains(@resource-id, 'alertTitle')]
Run Keyword If ${count} > 0 Click Element xpath=//*[contains(@text, 'OK')]
Sleep 2s
Run Keyword If ${count} > 0 Click Element xpath=//*[contains(@text, '${bluetooth_name}')]
Log Check if the Bluetooth connected sucesfully or not.
Wait Until Page Contains Connected 10 The device does NOT connect to the Access Point ${bluetooth_name} yet
文末列出最近整理的Robot Framework相关的文章,
2.Robot Framework + Appium测试Android设备
3. Robot Framework如何向Android发送keycode键盘事件
4.Robot Framework如何判断Android屏幕是否含有某个控件
5.Robot Framework如何等待Android屏幕中的某个控件出现
6.Robot Framework如何在Android中实现滚屏
7.Robot Framework如何对Android的控件定位
8.Robot Framework+Appium案例分享一: 验证版本信息
9.Robot Framework+Appium案例分享二: Camera测试
10.Robot Framework+Appium案例分享三: WiFi测试
11.Robot Framework+Appium案例分享四: Bluetooth测试
12.RobotFramework AppiumLibrary 用户关键字