随笔分类 - python
摘要:a =dict(one=1,two=2,three=3) b = {'one':1,'two':2,'three':3} c = dict(zip(['one','two','three'],[1,2,3])) d = dict([('one', 1), ('two', 2), ('three',
阅读全文
摘要:bisect模块提供的功能: 一共包含四个函数 insort_right(a, x, lo=0, hi=None) bisect_right(a, x, lo=0, hi=None) insort_left(a, x, lo=0, hi=None) bisect_left(a, x, lo=0, h
阅读全文
摘要:有时候我们需要初始化一个嵌套着几个列表的列表,这种情况下推荐使用列表推导式 代码1: def test01(): l = [["_"] * 3 for i in range(3)] print(l) l[1][2] = "x" print(l) if __name__ == '__main__':
阅读全文
摘要:import collections from random import choice Card = collections.namedtuple('Card',['rank','suit']) class FrenchDeck: ranks = [str(n) for n in range(2,
阅读全文
摘要:1、指定范围的浮点数:random.uniform(1, 100) 2、指定小数位数进行四舍五入:random.uniform(1, 100), 7 3、string中的随机字符串: 4、由指定集合中的元素生成指定位数不重复的列表:random.sample(string.hexdigits, +4
阅读全文
摘要:测试代码如下 from timeit import Timer def fun1(): a = [] for i in range(10000): li = [i] a = a + li def fun2(): a = [i for i in range(10000)] def fun3(): a
阅读全文
摘要:两种方式: 一、appium inspector 1、启动appium服务后,打开appium inspector: 2、配置会话信息 3、启动会话后可进行元素定位、脚本录制等操作 二、SDK自带uiautomatorviewer的定位工具 运行改工具: 即可同步模拟器上的app运行页面,然后就可以
阅读全文
摘要:pytest框架默认的测试用例识别规则,参考https://www.cnblogs.com/Xiaojiangzi/p/13497432.html 如果想要改变默认的识别规则,可以通过pytest.ini文件来定义: 目录结构: #pytest.ini [pytest] python_files =
阅读全文
摘要:一、不同文件的执行顺序 按照目录文件名顺序执行,目录结构如下: 用例执行顺序: 二、同一文件下的执行顺序 按照用例顺序从上到下执行,示例代码: import pytest class TestF(): def testz(self): print('testz') def test3(self):
阅读全文
摘要:环境:wind7 64位,python3.8 在执行pip install lxml的时候,报错Could not find function xmlCheckVersion in library libxml2 解决方法: 在https://www.lfd.uci.edu/~gohlke/pyth
阅读全文
摘要:一、命令行终端执行 1、测试用例的识别 1)、测试文件 test_*.py *_test.py 2)、用例识别 Test*类包含的所有test_*的方法(测试类不能包含构造方法__init__) 不在类中的所有test_*方法 3)、pytest可以执行unittest框架写的用例和方法 2、常用命
阅读全文
摘要:使用步骤: 1、将Chrome浏览器安装路径添加到系统环境变量中(或者进入安装目录),执行 chrome --remote-debugging-port=9222 2、在步骤1打开的浏览器中登录要操作的网站; 3、python代码如下,这样就可以免登录,直接操作已经登录的页面了: from time
阅读全文
摘要:大多数的时间控件都加上了readonly属性,不能直接修改,只能通过控件选择 在自动化测试过程中,可以通过js脚本直接输入对应的时间,省去操作控件悬浮框 思路: 1、获取掉时间输入框后,去掉readonly属性; 2、通过js脚本赋值 下面以12306首页出发日期为例实践一下: js执行过程: 转换
阅读全文
摘要:这种方式只能对简单的验证码起作用,复杂的就获取不到了。 验证码识别思路: 1、获取整个屏幕截图 2、获取验证码图片的坐标 3、抠图获取验证码图片 4、使用pytesseract识别验证码 示例代码 import os from time import sleep import pytesseract
阅读全文
摘要:四个截图的方法: self.driver.save_screenshot(fielname) self.driver.get_screenshot_as_base64() self.driver.get_screenshot_as_file(fielname) self.driver.get_scr
阅读全文
摘要:一、通过执行js脚本触发点击事件 页面元素结构如下图所示: 通过如下方式获取该元素后直接点击会报错: selenium.common.exceptions.WebDriverException: Message: element click intercepted: Element <span ro
阅读全文
摘要:用法: 1、先导入Select类 from selenium.webdriver.support.select import Select 2、实例化,通过源码可知初始化对象的时候需要传入下拉框元素对象: 3、示例代码 #form2.html<!DOCTYPE html> <html lang="e
阅读全文
摘要:下面直接通过示例代码说明 本地写一个简单的form表单: #form1.html<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <form actio
阅读全文
摘要:区别: driver.quit():关闭整个浏览器 driver.close():关闭当前所在的句柄窗口 示例代码: from selenium import webdriver from time import sleep class Demo1(): def __init__(self): se
阅读全文
摘要:参考文章:https://mp.weixin.qq.com/s/__Z7NDQ3Haj4ClEPc9SPDQ 一、基本使用 项目地址:https://github.com/joke2k/faker 安装:pip install Faker 下面是构造随机数据并保存到excel的示例代码: impor
阅读全文

浙公网安备 33010602011771号