加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

appium+python+selenium测试配置

发布时间:2020-12-20 10:29:43 所属栏目:Python 来源:网络整理
导读:前提是配置好了adb环境变量,安装了python 1. 安装appium server 下载地址? :? ??http://appium.io/ 2. 安装appium client和selenium 在cmd中输入? ? ?pip?install?selenium? ? ? ? ? ? ? ? ? ? ? ? ? ? ? pip?install?Appium-Python-Client 如果出现retryi

前提是配置好了adb环境变量,安装了python

1. 安装appium server

下载地址? :? ??http://appium.io/

2. 安装appium client和selenium

在cmd中输入? ? ?pip?install?selenium? ?

? ? ? ? ? ? ? ? ? ? ? ? ? pip?install?Appium-Python-Client

如果出现retrying问题, 使用带pip源的命令,如???

pip?install?selenium -i?https://pypi.tuna.tsinghua.edu.cn/simple/

pip?install?Appium-Python-Client -i?https://pypi.mirrors.ustc.edu.cn/simple/

3. 编写脚本,代码中需要包含对appium server的设置, 可以根据实际需要增/删设置项, 如

 
 
# -*- coding: utf-8 -*-
from appium import webdriver
from time import sleep

CAPS = {
    "deviceName": " MEIZU_E3","platformName": "Android","platformVersion": "7.1.1",#‘app‘ = ‘E:/autotestingPro/app/UCliulanqi_701.apk‘  #指向.apk文件,如果设置appPackage和appActivity,那么这项会被忽略
    "appPackage": " com.meizu.flyme.flymebbs","appActivity": ".ui.LoadingActivity",#"noReset": True,
}

driver = webdriver.Remote(http://localhost:4723/wd/hub,CAPS)
sleep(3)

4. 打开appium server, 设置主机为 127.0.0.1,设置端口为 4723, 启动server

5. 连接手机,安装应用,运行脚本。完整测试脚本如下例(用Unittest):

# coding: utf-8
import
unittest 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 desired_caps = {platformName: Android,platformVersion: 5.1.1,deviceName: MEIZU_E3,"appPackage": " com.meizu.flyme.flymebbs",} appium_server = http://localhost:4723/wd/hub class LearnAppiumTest(unittest.TestCase): def setUp(self): self.driver = webdriver.Remote(appium_server,desired_caps) def tearDown(self): self.driver.quit() def test_01(self): text_view = self.driver.find_element_by_id("text_view") assert text_view.text == Hello World! Hello World! # 测试应该不通过 def test_02(self): wait = WebDriverWait(self.driver,6) wait.until(EC.element_to_be_clickable((By.ID,button))) button = self.driver.find_element_by_id("button") button.click() wait = WebDriverWait(self.driver,6) wait.until(EC.presence_of_element_located((By.ID,text_view))) text_view = self.driver.find_element_by_id("text_view") assert text_view.text == 3 # 测试应该通过 if __name__ == __main__: unittest.main()

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读