Python3
-
【iTestCat】分支if…else…(Python3自动化教程)
1)if 如果if语句判断是True,就把缩进的两行print语句执行了,否则,什么也不做。
1234#-*- coding:utf-8 -*-num = input('Please input your number: ')if num == '1':print('itestcat')2)if…else… 如果if判断是False,不要执行if的内容,去把else执行了:
123456#-*- coding:utf-8 -*-num =input('Please input your number: ')if num=='1':print('itestcat')else:print('itestcat.com')3)if…elif…else elif是else…
-
【iTestCat】Python2\Python3输入输出及区别(Python3自动化教程)
1.1输出 python2中输出可以使用空格或者小括号。 示例: print "hello itestcat"或者 print("hello itestcat") python3中输出只能小括号。 示例: print("hello itestcat") 1.2 输入 Python2中,…
-
【iTestCat】错误截图(selenium+python3教程)
在进行UI自动化测试时,你可能需要捕获程序执行错误时的截图,selenium提供获取浏览器截图的方法:
1driver.get_screenshot_as_file(“image.png”)实例:
123456789#捕捉百度输入框异常from selenium import webdriverdriver = webdriver.Chrome()driver.get("http://www.itestcat.com")try:driver.find_element_by_id("kw").send_keys("itestcat")driver.find_element_by_id("su").click()except:driver.get_screenshot_as_file("error_png.png") -
【iTestCat】操作cookie(selenium+python3教程)
在操作cookie前我们需要了解浏览器中是否存在某个cookie 信息,在验证浏览器中cookie是否正确时,有时基于真实cookie的测试是无法通过白盒和集成测试进行的。Webdriver提供了操作Cookie的相关方法,可以读取,添加和删除cookie信息。 webdriver操作cookie()的方法: get_cookies(): 获得所有cooki…
-
【iTestCat】主流浏览器启动控制台(selenium+python3教程)
1、IE浏览器 IE浏览器需要下载IEDriverServer并将driver所在路径配置至环境变量中。 下载地址:http://selenium-release.storage.googleapis.com/3.9/IEDriverServer_x64_3.9.0.zip 启动IE浏览器控制台代码如下:[crayon-67b7bb531a405177214…
-
【iTestCat】windows下安装配置python3、pip
第1步:安装Python 根据下面的地址,直接一键安装,路径选择C:\Python36,方便后面查找。 下载地址:https://www.python.org/ftp/python/3.6.3/python-3.6.3-amd64.exe 然后设置Python的环境变量, Path:“C:\Python36” 1).点击【我的电脑】->【属性】->…
-
【iTestCat】pytest测试框架-main()函数执行测试用例
第一种:默认执行: if __name__ == ‘__main__’: pytest.main() main() 默认执行了当前文件所在的目录下的所有测试文件。 第二种:执行指定测试文件: 运行指定测试文件: if __name__ == ‘__main__’: pytest.main(“-q t…
-
【iTestCat】pytest测试框架-丰富的插件
安装插件,使用pip可以轻松完成: 安装:pip install pytest-名字 卸载:pip uninstall pytest-名字 一些流行的插件 pytest-html:生成html测试报告 pytest-Django:编写测试Django的应用程序,使用pytest整合。 pytest-twisted:编写测试twisted的应用程序。 pyte…
-
【iTestCat】pytest测试框架-一个简单的例子
创建itestcat.py文件
1234def inc(x):? return x + 1def test_answer():? assert inc(3) == 5执行py文件 进入终端输入py.test itestcat.py 运行多个测试 pytest运行当前目录及其子目录中所有文件test _ * .py或* _test.py,这是pytest遵循的规则。
-
【iTestCat】调用javaScript方法(selenium+python3教程)
execute_script(script, *args) 在当前窗口/框架同步执行javaScript script:JavaScript 的执行。 *args:适用任何JavaScript 脚本。 使用:
1driver.execute_script('document.title')