首页 > 编程语言 >python+appium+pytest做app自动化测试

python+appium+pytest做app自动化测试

时间:2024-04-22 17:55:05浏览次数:19  
标签:appium python app driver html caps desired pytest

我在另一篇博客中写了使用unittest做app自动化测试的,包含了前期的环境的环境搭建,请参考如下链接:python+appium+unittest做app自动化测试

这里,我们使用pytest框架再改写一个版本,因为pytest做测试报告看着更加好看,代码改良如下:

from appium import webdriver
import pytest
@pytest.fixture(scope='session')
def driver(request):
    server_url = 'http://localhost:4723/wd/hub'
    desired_caps = {}
    desired_caps['platformName'] = 'Android'
    desired_caps['platformVersion'] = '8.1.0'
    desired_caps['deviceName'] = '2c7c688a'
    desired_caps['appPackage'] = 'com.hhh.aaa.xxx.test'  # 应用的包名
    desired_caps['appActivity'] = 'com.hhh.aaa.xxx.test.MainActivity'  # 应用的主Activity

    driver = webdriver.Remote(server_url, desired_caps)
    def fin():
        driver.quit()
    request.addfinalizer(fin)
    return driver

def test_find_and_click_element(driver):

    button = driver.find_element_by_id('com.hhh.aaa.xxx.test:id/apiCastBtn')
    button.click()

这里需要安装pytest,命令行下执行pip install pytest,如果出现报错,可尝试使用管理员权限打开cmd,执行pip install --ignore-installed pytest,生成测试报告,需要执行pip install pytest-html

上面的python代码保存为文件appiumtest.py,执行:

pytest --html=report.html appiumtest.py

当前路径下生成了report.html文件,内容如下:

 对比unittest,看着还是pytest更加好用点

 

标签:appium,python,app,driver,html,caps,desired,pytest
From: https://www.cnblogs.com/zndxall/p/18151138

相关文章

  • Python Numpy 矩阵运算
    目录1前言2点积与矩阵乘法2.1np.dot()2.2np.matmul()和@2.3np.multiply和*3矩阵的逆4Ref1前言Python中经常涉及到矩阵运算,其借助于Numpy库进行,因此本文记录一些基于Numpy的矩阵运算2点积与矩阵乘法矩阵的点积(dotproduct),又称为内积(innerproduct)$a=(x_1,y_1)......
  • python+appium+unittest做app自动化测试
    1.需要安装一些列的软件:(1)java(2)androidsdk:  https://www.cnblogs.com/chenxiaomeng/p/16544481.html(3)AppiumServerGUI(4)AppiumInspector (3和4老版本是一个)2.打开AppiumServerGUI直接点击startServer即可,使用默认配置 3.打开 AppiumInspectorremot......
  • python监控MongoDB服务进程,故障钉钉告警
     服务器1xx.168.8x.77#!/usr/bin/python#!_*_coding:utf-8_*_importosimportsysimporttimemongo_ip='192.168.xx.77'ports=['x001','x002']defport(ip,port):  response=os.popen("tcping %s%s|grepopen|awk-F'&......
  • 在Python中的for循环
    在Python中的for循环for循环:用于遍历序列(如列表、元组、字典、集合或字符串)或其他可迭代对象。pythonforiinrange(10):#这将循环10次,i的值从0到9print(i)while循环:当给定条件为真时,重复执行代码块。pythoni=0whilei<10:#这将循环10次print(i)i......
  • python 多并发
    多并发实现1#!/usr/bin/python2#-*-coding:utf-8-*-34"""5@File:.py6@Description:7@Time:2024/04/2210:00:008@Author:9@Version:1.010@Contact:[email protected]"""1213impor......
  • Python实现下载文件的三种方法
    下面来看看三种方法是如何来下载zip文件的:方法一: importurllibprint"downloadingwithurllib"url='http://www.jb51.net//test/demo.zip'urllib.urlretrieve(url,"demo.zip") 方法二: importurllib2print"downloadingwithurllib2"u......
  • 使用pyppeteer 下载chromium 报错 python pyppeteer 调用谷歌翻译api
    https://registry.npmmirror.com/binary.html?path=chromium-browser-snapshots/Win_x64/手动下载安装包 修改文件C:\Users\luyan\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyppeteer\chromium_downloader.py #修改这段代码defdownload_chromium()-......
  • Python实现批量下载文件的示例代码
    前言下载文件是我们在日常工作中常常要做的一件事情。当我们需要从互联网上批量下载大量文件时,手动一个一个去下载显然不够高效。为了解决这个问题,我们可以使用Python编写一个批量下载文件的脚本,让它自动帮我们下载文件。同时,为了避免下载过程中被网站禁止访问,我们也可以运用代理......
  • Python数据容器
    1.容器定义:容纳多份数据的数据类型。Python的数据容器可以理解为C++中的数据结构,这些数据结构的方法多为“增删改查”。容器类型:列表、元组、字符串、2.列表list列表可理解为数组,下标从0开始。定义定义代码name_list=['zhangsan','lisi','wangwu']#字......
  • 接口自动化Python+requests踩坑记录
    问题描述同一个接口,传参相同,用postman,jmeter等接口工具都能正常访问,后台也能正常返回数据,但是用requests.post()调用就会返回400jmeter传参以及响应这是一个登录接口,如图所示的传参,是可以正常登录的  postman传参以及响应可以看到,两个工具的传参不一样,但是也是同样可以正......