python3 操作appium

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# -*- 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()

  

本文作者:公众号python学习开发

本文链接:https://www.cnblogs.com/c-x-a/p/9760420.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   公众号python学习开发  阅读(528)  评论(0编辑  收藏  举报
历史上的今天:
2016-10-09 Dictionary和IDictionary
2016-10-09 System.DateTime.Now的内容
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起