代码:

# coding=utf-8

from appium import webdriver
import time
import unittest
import os
import HTMLTestRunner class LoginTestLizi(unittest.TestCase):
def setUp(self):
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['deviceName'] = 'Android Emulator'
desired_caps['platformVersion'] = '6.0'
desired_caps['appPackage'] = 'com.netease.cloudmusic'
desired_caps['appActivity'] = '.activity.LoadingActivity'
self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)
def startAPP(self):
wd = self.driver
wd.find_element_by_id("com.netease.cloudmusic:id/arc").click()
wd.find_element_by_id("com.netease.cloudmusic:id/bw4").click()
wd.find_element_by_id("com.android.packageinstaller:id/permission_allow_button").click()
wd.find_element_by_id("com.android.packageinstaller:id/permission_allow_button").click()
time.sleep(10) # 睡眠10S等APP启动完成 def test_login(self):
driver = self.driver
# 进入首页后点击‘我的’按钮
driver.find_element_by_id("com.netease.cloudmusic:id/arc").click()
time.sleep(2)
# 点击登录头像按钮,进行登录,跳转到登录界面
driver.find_element_by_id('com.netease.cloudmusic:id/pt').click()
time.sleep(2)
# 输入手机号
driver.find_element_by_id('com.netease.cloudmusic:id/j5').send_keys('16688886666')
#点击next
driver.find_element_by_id('com.netease.cloudmusic:id/an5').click()
time.sleep(2)
# 输入验证码
driver.find_element_by_id('com.netease.cloudmusic:id/an_').send_keys('1234')
time.sleep(3)
# 点击确认登录按钮
driver.find_element_by_id('com.lizi.app:id/login_button').click() time.sleep(3)
# 登录成功,页面下滑,不然点击不到设置按钮
driver.swipe(500, 200, 500, 800, 0)
time.sleep(2)
# 获取登录后的昵称
name = driver.find_element_by_id('com.lizi.app:id/login_username_tv').text # 添加断言,若昵称不正确,则打印错误信息
try:
assert 'No_matter' in name
print('loginUser is right')
except AssertionError as e:
print('loginUser is Error') # 点击设置按钮,进入设置页面
driver.find_element_by_id('com.lizi.app:id/setting_imageView').click()
# 点击退出按钮
driver.find_element_by_id('com.lizi.app:id/exit_button').click() def tearDown(self):
self.driver.quit() if __name__ == '__main__':
suite = unittest.TestSuite()
suite.addTest(LoginTestLizi('startAPP'))
suite.addTest(LoginTestLizi('test_login'))
filename = 'd:\\app.html'
fb = open(filename, 'wb')
runner = HTMLTestRunner.HTMLTestRunner(stream=fb, title='liziapptestreport', description='liziapp')
runner.run(suite)
fb.close()

Appium+unittest+python登录app的更多相关文章

  1. Appium(Python)测试混血App

    Hybrid App(混合模式移动应用)是指介于web-app.native-app这两者之间的app兼具Native App良好用户交互体验的优势和Web App跨平台开发的优势 HybridApp ...

  2. appium+Python 启动app(二)

    我们上步操作基本完成,下面介绍编写Python脚本启动app 打开我们pycharm新建.py文件 第一步:输入Python脚本代码: #coding=utf-8 from appium import ...

  3. appium+Python 启动app(一)

    当我们appium和Python环境都配置好了,如何启动我们第一个app呢?下面介绍appium+Python启动app的操作步骤,为了能够详细查看,我们这里使用夜游神模拟器进行示范. 测试项目:QQ ...

  4. 自动化测试 Appium之Python运行环境搭建 Part2

    Appium之Python运行环境搭建 Part2 by:授客 QQ:1033553122 实践环境 参见 Appium之Python运行环境搭建 Part1 环境部署 1.安装Android SDK ...

  5. Appium使用Python运行appium测试的实例

    Appium使用Python运行appium测试的实例 一.  Appium之介绍 https://testerhome.com/topics/8038 详情参考--https://testerhom ...

  6. 基于Appium、Python的自动化测试

    基于Appium.Python的自动化测试环境部署和实践   第一章 导言 1.1 编制目的 该文档为选用Appium作为移动设备原生(Native).混合(Hybrid).移动Web(Mobile ...

  7. Appium和Python实现蚂蚁森林自动化收取能量

    准备环境 Window10系统 Appium1.21.0 AndroidSDK r24.1.1 Python3.7.5 支付宝apk文件 查看支付宝apk包信息 使用android sdk aapt命 ...

  8. MacOS无法登录App Store修复

    MacOS无法登录App Store修复 2017-03-10 21:13:39  by:SemiconductorKING 先上图: 惨红色的提示信息,把你拒之App Store门外,但是对之放弃. ...

  9. 利用python开发app实战

    你说,我们的未来 被装进棺材,染不上尘埃 *** 我很早之前就想开发一款app玩玩,无奈对java不够熟悉,之前也没有开发app的经验,因此一直耽搁了.最近想到尝试用python开发一款app,goo ...

随机推荐

  1. js new call apply bind 的 原理

    new new 做了什么事?1. 以 Object.protoype 为原型创建一个新对象 2. 以新对象为 this,执行函数的 [[call]] 3. 如果 [[call]] 的返回值是对象,那么 ...

  2. ubuntu ukylin wineqq 登录时提示:您的号码暂时不能使用低版本的qq

    ubuntu ukylin wineqq 登录时提示:您的号码暂时不能使用低版本的qq,而有的qq号登录没有问题. 优麒麟官网上下载的qqwine安装包,解压后安装三个deb包. 郁闷了一下午,都想装 ...

  3. 遇到bug如何处理

    issue中查询是否有相似bug assert / try-except / IDE单步调式 框架可以查询源码或者查询官方文档

  4. 3、Web server 之httpd2.2 配置说明

    http协议实现的程序 静态(httpd, nginx, lighttpd) 动态 (IIS, tomcat,  jetty,  jboss,  resin,  websphere, weblogic ...

  5. 说自己熟悉 Spring Cloud 这些面试题你会吗

    问题一:什么是Spring Cloud? Spring cloud流应用程序启动器是基于Spring Boot的Spring集成应用程序,提供与外部系统的集成.Spring cloud Task,一个 ...

  6. Arts打卡第9周

    Algorithm.主要是为了编程训练和学习. 每周至少做一个 leetcode 的算法题(先从Easy开始,然后再Medium,最后才Hard). 进行编程训练,如果不训练你看再多的算法书,你依然不 ...

  7. IDEA启动Tomcat服务器时某些端口(如1099端口)被占用的解决办法

    启动Tomcat服务器时,出现1099端口被其它进程占用了解决办法: 1.找出占用1099端口的进程,进入windows命令,查看什么进程占用了1099端口,使用命令:netstat -aon|fin ...

  8. CodeForces - 1183E Subsequences (easy version) (字符串bfs)

    The only difference between the easy and the hard versions is constraints. A subsequence is a string ...

  9. 唯品会HDFS性能挑战和优化实践

    唯品会HDFS性能挑战和优化实践 原创: 大数据平台 唯技术 4月1日 https://mp.weixin.qq.com/s/LMa99ubgACI4eaDV3G-6gw  

  10. Ubuntu18.04修改主机名和网卡地址

    date: 2019-06-26 09:56:04 author :headsen chen notice :个人原创 1,Ubuntu18.04 设置固定IP: 2,Ubuntu 18.04 设置主 ...