• appium+python实现手机计算器随机计算


    手机:华为荣耀V9

    # coding:utf-8
    from appium import webdriver
    import time
    import random
    def str_splice(x):
        str1 = "com.android.calculator2:id/" + x
        return str1
    #生成1~5位数的随机数
    def number_element():
        element_list = []
        for i in range(1, random.randint(2, 6)):
            element_list.append(str_splice(number_list[random.randint(0, 10)]))
        for i in range(0, len(element_list)):
            driver.find_element_by_id(element_list[i]).click()
        element_list.clear()
    #运算符号随机选择
    def symbol_element():
        driver.find_element_by_id(str_splice(symbol_list[random.randint(0, 3)])).click()
    #操作顺序:随机数 + 运算符号 + 随机数 + “=” + “清空”
    def formula():
        number_element()
        symbol_element()
        number_element()
        driver.find_element_by_id("com.android.calculator2:id/eq").click()
        driver.find_element_by_id("com.android.calculator2:id/op_clr").click()
    #配置appium驱动
    desired_caps = {}
    desired_caps['platformName'] = 'Android'
    desired_caps['deviceName'] = 'SALDU17303000215'
    desired_caps['platformVersion'] = '9'
    desired_caps['appPackage'] = 'com.android.calculator2'
    desired_caps['appActivity'] = 'com.android.calculator2.Calculator'
    desired_caps['autoGrantPermissions'] = True
    desired_caps['noReset'] = True
    driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
    #设置数字列表
    number_list = ["digit_0", "digit_1", "digit_2", "digit_3",
                   "digit_4", "digit_5", "digit_6", "digit_7",
                   "digit_8", "digit_9", "dec_point"]
    #设置运算符号列表
    symbol_list = ["op_div", "op_mul", "op_sub", "op_add"]
    #测试20次公式
    for i in range(0, 20):
        formula()
    time.sleep(10)
    driver.quit()
    
  • 相关阅读:
    element-ui获取table行数据
    去掉输入框的边框以及在显示获取焦点时的边框+jq日期选择器
    需要ui的小伙伴看过来(这篇博客只有一个链接希望对大家有用)
    vue获取当前对象
    FlashFXP用到的功能
    VS Code做项目的笔记
    单点登陆
    idea中自动生成实体类
    VSCode安装
    数组排序
  • 原文地址:https://www.cnblogs.com/loveniko/p/13262346.html
Copyright © 2020-2023  润新知