最近看了下 robotframework,接着又看到了 robotframework-appiumlibrary,于是玩了下,在这里记录下!

环境准备
1、RIDE,熟悉 robotframework 的同学应该比较清楚,没用过的同学请自行搜索!
2、robotframework-appiumlibrary,下载方式:
(1)、通过 pip 工具下载

pip install robotframework-appiumlibrary

(2)、克隆该项目 (https://github.com/jollychang/robotframework-appiumlibrary.git), 执行 setup.py 脚本进行安装

git clone https://github.com/jollychang/robotframework-appiumlibrary.git
cd robotframework-appiumlibrary
python setup.py install

(3)、Example APPhttps://github.com/appium/sample-code/blob/master/sample-code/apps/ContactManager/ContactManager.apk),其实就是准备使用官方例子。

开始写 Case
1、打开 RIDE,New Project>>New Suite,格式我采用的是txt,导入AppiumLibrary这个库。
2、设置变量,主要是设置desired_caps

def open_application(self, remote_url, alias=None,  **kwargs):
        """Opens a new application to given Appium server.
        Capabilities of appium server, Android and iOS, 
        Please check http://appium.io/slate/en/master/?python#appium-server-capabilities
        | *Option*            | *Man.* | *Description*     |
        | remote_url          | Yes    | Appium server url |
        | alias               | no     | alias             |

        Examples:
        比较长,这里省略,具体可查看该项目源码
        """
        desired_caps = kwargs
        application = webdriver.Remote(str(remote_url), desired_caps)
        self._debug('Opened application with session id %s' % application.session_id)

        return self._cache.register(application, alias)

参考上面 open_application 方法接收的参数,所以需要设置remote_url**kwargs,直接在 RIDE 的 Text Edit 中编辑:

*** Variables ***
${REMOTE_URL}     http://localhost:4723/wd/hub
${PLATFORM_NAME}    Android
${PLATFORM_VERSION}    4.4
${DEVICE_NAME}    Android Emulator
${APP}            E:\\ContactManager.apk
${APP_PACKAGE_NAME}    com.example.android.contactmanager
${APP_ACTIVITY}    .ContactManager

3、接着New User Keyword

*** Keywords ***
add new contact
    [Arguments]    ${contact_name}    ${contact_phone}    ${contact_email}
    Open Application    ${REMOTE_URL}    platformName=${PLATFORM_NAME}    platformVersion=${PLATFORM_VERSION}    deviceName=${DEVICE_NAME}    app=${APP}    appPackage=${APP_PACKAGE_NAME}
    ...    appActivity=${APP_ACTIVITY}
    Click Element    accessibility_id=Add Contact
    Input Text    id=com.example.android.contactmanager:id/contactNameEditText    ${contact_name}
    Input Text    id=com.example.android.contactmanager:id/contactPhoneEditText    ${contact_phone}
    Input Text    id=com.example.android.contactmanager:id/contactEmailEditText    ${contact_email}
    Click Element    accessibility_id=Save
    Click Element    accessibility_id=Show Invisible Contacts (Only)

关于Keyword的文档,请查看http://jollychang.github.io/robotframework-appiumlibrary/doc/AppimuLibrary.html

4、然后New Test Case

*** Test Cases ***
add_contact
    add new contact    Appium User    123456789    test@test.com
    Page Should Contain Text    Appium User

5、运行 Case

最后还是觉得写代码更方便。。。


↙↙↙阅读原文可查看相关链接,并与作者交流