Robot Framework+Appium案例分享三: WiFi测试

来源:互联网 发布:哪个电视直播软件好 编辑:程序博客网 时间:2024/06/08 01:52

在之前的博客“Robot Framework + Appium测试Android设备”,我们已经介绍了如何使用Robot Framework和Appium测试Android设备,如果对这部分还不熟悉的童鞋,可以参考本人之前的博客。

本文分享一个Test Suit, WiFi测试, 测试WiFi打开以及连接功能.

Test Suit  5: WiFi Test, 打开并连接特点的WiFi.

测试步骤如下,

1. 打开Setting App;

2. 点击进入Wi-Fi页面;

2.1 Test Case 1: 打开WiFi;

2.2 Test Case 2: 连接WiFi;

测试代码如下,

*** Settings ***Suite Setup       Open Settings AppSuite Teardown    Close ApplicationLibrary           AppiumLibrary*** Variables ***${SSID_NAME}      Honor 6X${PASSWORD}       guangwei*** Test Cases ***Test Case 1: Turn On WiFi    [Tags]    WiFi Test    Turn On WiFiTest Case 2: Connect WiFi    [Tags]    WiFi Test    Connect WiFi    ${SSID_NAME}    ${PASSWORD}*** 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 WiFi Setting PageOpen WiFi Setting Page    Log    Click the "Wi-Fi" Label    Wait Until Page Contains Element    xpath=//*[contains(@text, 'Wi‑Fi')]    10    Can NOT find "Wi-Fi" label    Click Element    xpath=//*[contains(@text, 'Wi‑Fi')]Turn On WiFi    Wait Until Page Contains Element    xpath=//*[contains(@resource-id, 'id/switch_widget')]    ${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')]Connect WiFi    [Arguments]    ${ssid_name}    ${password}    Log    Step 1: Click the SSID-Name ${ssid_name}    Wait Until Page Contains Element    xpath=//*[contains(@text, '${ssid_name}')]    10    Can NOT find ${ssid_name}    Click Element    xpath=//*[contains(@text, '${ssid_name}')]    Sleep    2s    Log    Step 2: Check if the AP ${ssid_name} already connected, if connected then disconnect    ${count}    Get Matching Xpath Count    xpath=//*[contains(@text, 'Forget')]    Run Keyword If    ${count} > 0    Log    WiFi already connected, forget it then re-connect    Run Keyword If    ${count} > 0    Click Element    xpath=//*[contains(@text, 'Forget')]    Run Keyword If    ${count} > 0    Sleep    2s    Run Keyword If    ${count} > 0    Click Element    xpath=//*[contains(@text, '${ssid_name}')]    Run Keyword If    ${count} > 0    Sleep    2s    Log    Step 3: Input the password then connect.    Wait Until Page Contains Element    xpath=//*[contains(@resource-id, 'id/password')]    10    Can NOT find "password" text    Input Value    xpath=//*[contains(@resource-id, 'id/password')]    ${password}    Sleep    1s    Click Element    xpath=//*[contains(@text, 'Connect')]    Log    Step 4: Check if the WiFi connected sucesfully or not.    Wait Until Page Contains    Connected    10    The device does NOT connect to the Access Point ${ssid_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 用户关键字