Robot Framework+Appium案例分享四: Bluetooth测试

本文提供了一个使用Robot Framework结合Appium进行蓝牙测试的测试套件案例,包括蓝牙开启、扫描及连接等关键步骤,并附带了详细的代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在之前的博客“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相关的文章,

1.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 用户关键字


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值