Appium Remote webdriver调用
remote webdriver的模板
默认开启4723端口接受webdriver请求
默认开启4724用于和android通讯
#coding:utf-8
#Import the common package
import os
import unittest
from appium import webdriver
from time import sleep #设置路径信息
PATH = lambda p: os.path.abspath(
os.path.join(os.path.dirname(__file__), p)
) class LoginAndroidTests(unittest.TestCase):
def setUp(self):
#初始化测试平台
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '4.4.2' #Android版本
desired_caps['deviceName'] = '127.0.0.1:62001' #连接到的设备名称,这个是夜神模拟器的名称
#desired_caps['app'] = 'D:\apk\爱壁纸.apk' #app的路径
desired_caps['appPackage'] = 'com.lovebizhi.wallpaper' #包名
desired_caps['appActivity'] = 'com.lovebizhi.wallpaper.WelcomeActivity' #activity名称
self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps) def tearDown(self):
self.driver.quit() def test(self):
#测试导航页
print("start test...") #判断是否安装爱壁纸APP
wallpaper = self.driver.is_app_installed("com.lovebizhi.wallpaper")
if wallpaper:
#self.driver.remove_app("com.lovebizhi.wallpaper")
sleep(8)
# 点击某一壁纸图片
self.driver.find_elements_by_id("com.lovebizhi.wallpaper:id/image1")[4].click()
sleep(4)
# 点击设置壁纸
self.driver.find_element_by_id("com.lovebizhi.wallpaper:id/btSetup").click()
sleep(5)
else:
self.driver.install_app("D:\apk\爱壁纸.apk")
sleep(30)if __name__ == '__main__':
suite =unittest.TestLoader().loadTestsFromTestCase(LoginAndroidTests)
unittest.TextTestRunner(verbosity=2).run(suite)
如何查看app的appPackage和APPactivity?
1、下载apktool-new的压缩包,并解压

2、双击decode.bat运行

3、将apk拖入decode.bat中回车即可得到对应apk的文件夹


4、用记事本或notepad++等打开apk文件夹中的AndroidManifest.xml即可看到appPackage和APPactivity名称

在romote webdriver初始化的时候
desired_caps['appPackage'] = 'com.lovebizhi.wallpaper'
desired_caps['appActivity'] = 'com.lovebizhi.wallpaper.WelcomeActivity
已经确定了是要测试哪个APP和APP中的哪个界面。直接运行Python脚本时就会跳转到对应的界面,此时在test中就不能操作在本界面中不存在的元素。否则会报错
如:想要在主体部分写卸载该APP或其他APP,就会报错
#coding:utf-8
#Import the common package
import os
import unittest
from appium import webdriver
from time import sleep #设置路径信息
PATH = lambda p: os.path.abspath(
os.path.join(os.path.dirname(__file__), p)
) class LoginAndroidTests(unittest.TestCase):
def setUp(self):
#初始化测试平台
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '4.4.2'
desired_caps['deviceName'] = '127.0.0.1:62001'
#desired_caps['app'] = 'D:\apk\爱壁纸.apk'
desired_caps['appPackage'] = 'com.lovebizhi.wallpaper'
desired_caps['appActivity'] = 'com.lovebizhi.wallpaper.WelcomeActivity'
self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps) def tearDown(self): self.driver.quit() def test_1(self):
#测试导航页
print("start test1...") #判断是否安装爱壁纸APP
wallpaper = self.driver.is_app_installed("com.lovebizhi.wallpaper")
if wallpaper:
self.driver.remove_app("com.lovebizhi.wallpaper")
sleep(8)
else:
self.driver.install_app("D:\apk\爱壁纸.apk")
sleep(30) if __name__ == '__main__':
suite =unittest.TestLoader().loadTestsFromTestCase(LoginAndroidTests)
unittest.TextTestRunner(verbosity=2).run(suite)
报如下错误:


所以在初始化之后就不要使用卸载或安装程序了
Appium Remote webdriver调用的更多相关文章
- from appium import webdriver 使用python爬虫,批量爬取抖音app视频(requests+Fiddler+appium)
使用python爬虫,批量爬取抖音app视频(requests+Fiddler+appium) - 北平吴彦祖 - 博客园 https://www.cnblogs.com/stevenshushu/p ...
- 区分:AndroidDriver, iOSDriver, AppiumDriver and Remote WebDriver
区分:AndroidDriver, iOSDriver, AppiumDriver and Remote WebDriver 原文地址:https://discuss.appium.io/t/what ...
- appium---【已解决】【Mac】from appium import webdriver报错提示“Unresolved import webdriver”
报错提示: from appium import webdriver提示Unresolved import webdriver 报错原因:没有安装Appium_Python_Client 解决办法: ...
- 在eclipse中,Python项目遇到:…… from appium import webdriver ImportError: No module named appium
1) Traceback (most recent call last): File "D:\python workspace\src\p_test01\__init__.py" ...
- webDriver API——第11部分Remote WebDriver
The WebDriver implementation. class selenium.webdriver.remote.webdriver.WebDriver(command_executor=' ...
- from appium import webdriver 报错
from appium import webdriver 报错 看看你的文件是不是就叫appium
- appium ,selenium ,webdriver 运行原理与机制
做测试开发的童鞋都知道,UI自动化你绕不开selenium, webdrvier, appium框架,那么这三者之间有什么关联,它们的原理是什么呢? 简单来说就是: Selenium2 将浏览器原生 ...
- 关于IIS权限问题(Selenium WebDriver调用出错记录)
本地VS调试过程中用Selenium WebDriver打开FF浏览器可以正常工作,项目部署至IIS后请求调用浏览器一直提示超时,异常如下: 因为本地调试可以成功,首先排除组件版本问题和浏览器兼容问题 ...
- appium的webdriver执行swipe
# convenience method added to Appium (NOT Selenium 3) def swipe(self, start_x, start_y, end_x, end_y ...
随机推荐
- 【Beginning Python】抽象(未完)
[懒惰即是美德] 抽象意味着良好的可读性:说明你在努力做什么,而不是给出你正在如何做的细节. [抽象和结构] 程序应该是非常抽象的,就像“下载网页.计算频率.打印每个单词的频率”一样易懂.翻译成程序就 ...
- DevOps实践之持续集成Jenkins(最新版本测试)
一.安装Jenkins (1)下载并安装配置Java Development Kit 8 [root@localhost ~]# rpm -ivh jdk-8u161-linux-x64.rpm Pr ...
- 如何禁止ping
PING命令是个危险的命令,用它可以知道你的操作系统,IP等,为了安全禁PING是个很好的方法,也是防DDOS攻击的.应该是有外部网络试图连接你的UDP的1434端口,不知道你打了补丁没有. 黑客入侵 ...
- DATETIME与TIMESTAMP
DATETIME与TIMESTAMP都能表达一个完整的日期格式:YYYY-MM-DD HH:MM:SS[.fraction] eg: mysql> create table test(id in ...
- 先记录一下吧 开始的程序 hello!java!
起床后就跟着老师的教学,也稍微学了一些,刚开始用java. 一堆大小写字母注意不过来,很尴尬. 虽然只是成功了一个"hello java "的简单的不能再简单的小程序,不过还是有点 ...
- 入手sm961
测速: 发现这个测速软件不同版本测试还不一样 下面是我的intel750的,用最新版本测试软件测的 淘宝买了一个散热片
- An Example for Javascript Function Scoping and Closure
1. An Real World Example In the patron detail page of the CRM system I'm working with, there’re larg ...
- Windows Server 2008驱动安装全攻略
安装设备驱动程序原本是一件非常简单的事情,很多驱动程序在安装的时候我们只要不停单击“下一步”按钮,就能让驱动程序顺利地在对应计算机系统“落户”;不过,当身边的计算机系统升级为Windows Serve ...
- 将应用注册为Linux的服务
主流的Linux大多使用init.d或systemd来注册服务.下面以centos6.6演示init.d注册服务:以centos7.1演示systemd注册服务. 1. 基于Linux的init.d部 ...
- P4Lang Repository: Switch
Github Switch Introduction Structure: +-----+ +-----+ +-----+ +-----+ |App a| |App j| |App n| |App z ...