Appium+python实现App自动化登录

Appium+python实现App自动化登录

以下是个人用Appium + python写的第一个App自动化案例,仅做单页面,比较简单,后续将涉及到主功能模块化,需使用到功能时调用即可。

  1. 获取设备及应用信息
desired_caps = {}
desired_caps['platformName'] = 'Android'  # 设备系统
desired_caps['platformVersion'] = '5.1.1'  # 设备系统版本
desired_caps['deviceName'] = 'REDmi 3'  #  设备名称
desired_caps['appPackage'] = 'com.formax.life'
desired_caps['appActivity'] = 'formax.life.main.BootProxyActivity'

2.获取Appium client端口值

driver = webdriver.Remote("http://localhost:4723/wd/hub", desired_caps)

3.根据UIautomater定位元素

time.sleep(5)
driver.find_element_by_name('我的').click()
time.sleep(5)
driver.find_element_by_name('登录/注册').click()
time.sleep(5)
driver.find_element_by_name('手机号').send_keys('13112341237')
time.sleep(3)
driver.find_element_by_id('pwd_edit').send_keys('ss123456')
time.sleep(3)

driver.find_element_by_name('登录').click()
time.sleep(5)

4.原始代码

# -*- coding:utf-8 -*-
import os, time, unittest
from selenium import webdriver

desired_caps = {}
desired_caps['platformName'] = 'Android'  # 设备系统
desired_caps['platformVersion'] = '5.1.1'  # 设备系统版本
desired_caps['deviceName'] = 'REDmi 3'  #  设备名称
desired_caps['appPackage'] = 'com.formax.life'
desired_caps['appActivity'] = 'formax.life.main.BootProxyActivity'


driver = webdriver.Remote("http://localhost:4723/wd/hub", desired_caps)
time.sleep(5)
driver.find_element_by_name('我的').click()
time.sleep(5)
driver.find_element_by_name('登录/注册').click()
time.sleep(5)
driver.find_element_by_name('手机号').send_keys('13112341237')
time.sleep(3)
driver.find_element_by_id('pwd_edit').send_keys('ss123456')
time.sleep(3)

driver.find_element_by_name('登录').click()
time.sleep(5)

driver.quit()

你可能感兴趣的:(Appium,appium自动化测试)