自动化测试--环境搭建python+pytest+selenium

一.进入python官网下载相应版本
https://www.python.org/downloads/windows/
安装:
1。勾选 Add python to PATH 添加路径
2。安装界面点击Customize installation 自定义安装   
验证:python -V
 
注意:若忘记 勾选 Add python to PATH 
手动添加环境变量:
1)在计算机----属性---高级系统设置---环境变量按钮。
2)在系统变量里新建一个你喜欢的名字变量PythonRoot,在变量值里输入你安装的路径,在找到变量名Path,Path的变量值里输入PythonRoot。
 
二.安装pycharm
1.快速格式化代码的快捷键是Alt+Ctrl+L
 2.修改快捷键:File -->Settings -->Kepmap -->main menu -->Code
 
三.安装需要的库
pip install requests
pip install selenium
pip install pytest
pip install pyyaml
注:
1。批量安装命令为:pip install -r requirements.txt
       从一个机器的python程序中将所有导入的库名及版本导入requirements.txt指令为:
       pip freeze >requirements.txt
2。安装allure报告
      1)如果直接用Jenkins上的插件,并不需要下载安装
     下载后,解压,并添加路径到path
     2)与pytest集成命令:pip install allure-pytest
 
四.selenium使用chrome浏览器测试
1。从http://chromedriver.storage.googleapis.com/index.html网址中下载与本机chrome浏览器对应的驱动程序,驱动程序名为chromedriver,如:
 
找到对应的版本下载
2。下载后把文件解压,然后放到本机python安装路径中,如:D:softwarepythonchromedriver.exe (避免python运行时找不到driver,不需要再别加路径到path中)
原文地址:https://www.cnblogs.com/ybbybb/p/14262933.html