zoukankan      html  css  js  c++  java
  • python3 操作appium

    # -*- coding: utf-8 -*-
    # @Time    : 2018/10/8 11:00
    # @Author  : cxa
    # @File    : test.py
    # @Software: PyCharmctx
    from appium import webdriver
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.common.by import By
    import time
    import base64
    
    
    def start_appium():
        desired_caps = {}
        desired_caps['platformName'] = 'Android'  # 设备系统
        desired_caps['deviceName'] = '127.0.0.1:62001'  # 设备名称
        desired_caps['appPackage'] = 'com.alicom.smartdail'  # 测试app包名
        desired_caps['appActivity'] = 'com.alicom.smartdail.view.enter.SplashActivity'  # 测试appActivity
        desired_caps['platformVersion'] = '4.4.2'  # 设备系统版本
        desired_caps['noReset'] = True  # 启动后结束后不清空应用数据
        desired_caps['unicodeKeyboard'] = True  # 此两行是为了解决字符输入不正确的问题
        desired_caps['resetKeyboard'] = True  # 运行完成后重置软键盘的状态  
        driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)  # 启动app
        wait = WebDriverWait(driver, 60)
        # time.sleep(20)
        try:
            btn_xpath = '//android.widget.Button[@resource-id="com.alicom.smartdail:id/m_nonum_confirm_btn"]'
            btn_node = wait.until(EC.presence_of_element_located((By.XPATH, btn_xpath)))
            # btn_node=driver.find_element_by_xpath(btn_xpath)
            btn_node.click()
        except:
            driver.back()
            btn_xpath = '//android.widget.Button[@resource-id="com.alicom.smartdail:id/m_nonum_confirm_btn"]'
            btn_node = wait.until(EC.presence_of_element_located((By.XPATH, btn_xpath)))
            # btn_node = driver.find_element_by_xpath(btn_xpath)
            btn_node.click()
        # sleep 30s
        # 点击
    
    
    def login_in(driver):
        id_xpath = '//android.widget.EditText[@content-desc="账户名输入框"]'
        id_node = driver.find_element_by_xpath(id_xpath)
        id_node.clear()
        id_node.send_keys("test")
        pwd = str(base64.b64decode("MTIzNHF3ZXI="), 'u8')
        pwd_xpath = '//android.widget.EditText[@content-desc="密码输入框"]'
        pwd_node = driver.find_element_by_xpath(pwd_xpath)
        pwd_node.clear()
        pwd_node.send_keys(pwd)
        submit = "//android.widget.Button[@text='登录']"
        submit_node = driver.find_element_by_xpath(submit)
        submit_node.click()
        time.sleep(10)
    
    
    if __name__ == '__main__':
        start_appium()
    

      

  • 相关阅读:
    ORM数据库框架 SQLite ORMLite MD
    ORM数据库框架 greenDAO SQLite MD
    layer-list shape drawable 层叠背景 MD
    BAT 批处理 特殊符号 总结 [MD]
    集合 enum 枚举 简介 案例 [MD].md
    Gradle 翻译 ProGuard Shrink 混淆和压缩 [MD]
    构建配置 Enable multidex
    构建配置 defaultConfig signingConfigs buildTypes productFlavors dependencies
    Android 资源混淆 AndResGuard MD
    Android 第三方加固方案 对比 打包 [MD]
  • 原文地址:https://www.cnblogs.com/c-x-a/p/9760420.html
Copyright © 2011-2022 走看看