zoukankan      html  css  js  c++  java
  • RobotFramework:App九宫格滑动解锁

    转自:http://blog.csdn.net/codekxx/article/details/50577381

    手势密码在很多手机应用都会运到,手势密码都要求至少连接4个点,但AppiumLibrary并没有提供对应的关键字,本人尝试连续使用Swipe关键字两次解决该问题,为什么要用两次呢?因为Swipe的参数只是起点和终点,如果直接给出手势密码的起点和终点,则会忽略中间的点。

    手机QQ手势密码如下:

    AppiumLibrary它是开源的,就直接去修改其源代码。 
    于是,去到AppiumLibrary安装的文件夹,默认安装路径为:C:Python27Libsite-packagesAppiumLibrarykeywords),再到keywords目录中找到_touch.py文件,就是它了。 
    给这个文件的类_TouchKeywords加上一个方法nine_palace_unlock,具体代码如下:

        def nine_palace_unlock(self, locator):
            """nine palace"""
            driver = self._current_application()
            action = TouchAction(driver)          
            lock_pattern = driver.find_element_by_xpath(locator)
    
            x = lock_pattern.location.get('x')
            y = lock_pattern.location.get('y')
            width = lock_pattern.size.get('width')
            height = lock_pattern.size.get('height')
    
    
            offset = width / 6
            p11 = int(x + width / 6), int(y + height / 6)
            p12 = int(x + width / 2), int(y + height / 6)
            p13 = int(x + width - offset), int(y + height / 6)
            p21 = int(x + width / 6), int(y + height / 2)
            p22 = int(x + width / 2), int(y + height / 2)
            p23 = int(x + width - offset), int(y + height / 2)
            p31 = int(x + width / 6), int(y + height - offset)
            p32 = int(x + width / 2), int(y + height - offset)
            p33 = int(x + width - offset), int(y + height - offset)
    
            print(p11,p12,p13)
            print(p21,p22,p23)
            print(p31,p32,p33)
    
            p2 = p12[0] - p11[0]
            print(p2)
            sleep(3)
    
            action.press(x=p11[0],y=p11[1]).move_to(x=p2,y=0).wait(1000).move_to(x=p2,y=0).wait(1000).
                move_to(x=-p2,y=p2).wait(1000).move_to(x=-p2,y=p2).wait(1000).release().wait(1000).perform()

    代码如下:

    代码如下:

    *** Settings ***
    Suite Setup
    Suite Teardown
    Library           AppiumLibrary
    
    *** Variables ***
    
    *** Test Cases ***
    
    手机QQ
        Open Application    http://localhost:4723/wd/hub    platformName=Android    platformVersion=19    deviceName=127.0.0.1:21503    app=${CURDIR}${/}QQ_794.apk    appPackage=com.tencent.mobileqq
        ...    appActivity=com.tencent.mobileqq.activity.SplashActivity    unicodeKeyboard=True    resetKeyboard=True
        Wait Until Page Contains Element    xpath=//android.widget.LinearLayout[@resource-id="com.tencent.mobileqq:id/name"]/android.view.View[5]    #等待手机QQ打开完成
        Nine Palace Unlock    //android.widget.LinearLayout[@resource-id="com.tencent.mobileqq:id/name"]/android.view.View[5]
        [Teardown]    Close All Applications
    
    *** Keywords ***
  • 相关阅读:
    Jaeger Client Go 链路追踪|入门详解
    Go 中的 gRPC 入门详解
    【五分钟】001-数据结构概论
    【重榜?】.NET 6 Preview 1 开箱上手!带你尝试新版本更新!
    分布式链路追踪框架的基本实现原理
    【网摘】SQL练习题
    【数据库】E-R图向关系模型转换的规则
    6.0 《数据库系统概论》之关系数据库的规范化理论(数据依赖对表的影响[插入-删除-修改-冗余]、1NF-2NF-3NF-BCNF-4NF、函数依赖与多值依赖)
    【数据库】入门基础概念以及部分题目 记录 +答案+个人分析
    5.0 数据库完整性详解(PRIMARY KEY、REFERENCES、CHECK、CONSTRAINT、DOMAIN、TRIGGER)
  • 原文地址:https://www.cnblogs.com/yrxns/p/8478123.html
Copyright © 2011-2022 走看看