Robot Framework+Appium案例分享二: Camera测试

来源:互联网 发布:苹果mac破解软件下载 编辑:程序博客网 时间:2024/05/26 02:54

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


本文分享2个测试suit, 一个是测试后置Camera; 另外一个是测试前置Camera.


Test Suit 3, 后置Camera测试, 完成拍照20次, 录像20s

测试步骤如下,

1. 打开Camera App;

2.1 Test Case 1: 拍照20次;

2.2 Test Case 2: 打开录像功能, 录像20s.

示例代码如下,

*** Settings ***Suite Setup       Open Camera AppSuite Teardown    Close ApplicationLibrary           AppiumLibrary*** Variables ***${IMAGE_CAPTURE_TIMES}    20${VIDEO_RECORDING_DURATION}    20s*** Test Cases ***Test Case 1: Capture Image Test    [Tags]    Rear Camera    Switch to photo    : FOR    ${i}    IN RANGE    ${IMAGE_CAPTURE_TIMES}    \    Log    Capture image ${i} times    \    Click Element    xpath=//*[contains(@resource-id, 'id/shutter_button')]    \    Sleep    2sTest Case 2: Video Recording Test    [Tags]    Rear Camera    Switch to video    Click Element    xpath=//*[contains(@resource-id, 'id/shutter_button')]    Sleep    ${VIDEO_RECORDING_DURATION}    Click Element    xpath=//*[contains(@resource-id, 'id/shutter_button')]*** Keywords ***Open Camera App    Open Application    http://localhost:4723/wd/hub    platformName=Android    platformVersion=6.0.1    deviceName=dev_name    appPackage=org.codeaurora.snapcam    appActivity=com.android.camera.CameraLauncherSwitch to photo    Sleep    1s    Click Element    xpath=//*[contains(@resource-id, 'id/camera_switcher')]    Sleep    1s    Click Element    xpath=//*[contains(@content-desc, 'Switch to photo')]    Sleep    1sSwitch to video    Sleep    1s    Click Element    xpath=//*[contains(@resource-id, 'id/camera_switcher')]    Sleep    1s    Click Element    xpath=//*[contains(@content-desc, 'Switch to video')]    Sleep    1s

Test Suit 4, 前置Camera测试

测试步骤如下,

1. 打开Camera App;

2. 切换到前置Camera;

2.1 Test Case 1: 拍照20次;

2.2 Test Case 2: 打开录像功能, 录像20s.

示例代码如下,

*** Settings ***Suite Setup       Open Camera AppSuite Teardown    Close ApplicationTest Setup        Switch to front cameraLibrary           AppiumLibrary*** Variables ***${IMAGE_CAPTURE_TIMES}    20${VIDEO_RECORDING_DURATION}    20s*** Test Cases ***Test Case 1: Capture Image Test    [Tags]    Front Camera    Switch to photo    : FOR    ${i}    IN RANGE    ${IMAGE_CAPTURE_TIMES}    \    Log    Capture image ${i} times    \    Click Element    xpath=//*[contains(@resource-id, 'id/shutter_button')]    \    Sleep    2sTest Case 2: Video Recording Test    [Tags]    Front Camera    Switch to video    Click Element    xpath=//*[contains(@resource-id, 'id/shutter_button')]    Sleep    ${VIDEO_RECORDING_DURATION}    Click Element    xpath=//*[contains(@resource-id, 'id/shutter_button')]*** Keywords ***Open Camera App    Open Application    http://localhost:4723/wd/hub    platformName=Android    platformVersion=6.0.1    deviceName=dev_name    appPackage=org.codeaurora.snapcam    appActivity=com.android.camera.CameraLauncherSwitch to photo    Sleep    1s    Click Element    xpath=//*[contains(@resource-id, 'id/camera_switcher')]    Sleep    1s    Click Element    xpath=//*[contains(@content-desc, 'Switch to photo')]    Sleep    1sSwitch to video    Sleep    1s    Click Element    xpath=//*[contains(@resource-id, 'id/camera_switcher')]    Sleep    1s    Click Element    xpath=//*[contains(@content-desc, 'Switch to video')]    Sleep    1sSwitch to front camera    Sleep    1s    # The "filter mode switcher" won't exit in the front camera UI, so use it to check if current UI is front or rear camera    ${count}    Get Matching Xpath Count    xpath=//*[contains(@resource-id, 'id/filter_mode_switcher')]    Run Keyword If    ${count}>0    Click Element    xpath=//*[contains(@resource-id, 'id/front_back_switcher')]

文末列出最近整理的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 用户关键字


原创粉丝点击