selenium环境配置(Mac&Windows)

目录

一、Mac

Python环境配置

1.下载Python

2.Python成功安装检测

3.Python环境配置

4.编辑器安装

安装依赖包

selenium安装

pytest安装

安装webdriver

1.下载webdriver

2.driver版本选择

安装allure(需要先安装JAVA)

1.下载allure

2.配置allure的环境变量

3.验证是否生效

二、Windows

Python环境配置

1.下载Python

2.进行安装

3.Python成功安装检测

安装依赖包

selenium安装

pytest安装

安装webdriver

1.下载webdriver

2.driver版本选择

安装allure(需要先安装JAVA)

1.下载allure

2.配置allure的环境变量

3.验证是否生效

一、Mac

Python环境配置

1.下载Python

官网:Welcome to Python.org

找到对应的版本,进行下载:

selenium环境配置(Mac&Windows)_第1张图片

下载后单击打开,安装完成。

2.Python成功安装检测

打开终端, 输入:python3 --version,如果出现python的版本号即安装成功;

selenium环境配置(Mac&Windows)_第2张图片

3.Python环境配置

打开终端,输入:which python

4.编辑器安装

推荐pycharm

官网:PyCharm: the Python IDE for Professional Developers by JetBrains

下载安装即可

安装依赖包

selenium安装

pip install selenium

pytest安装

pip install pytest

安装webdriver

1.下载webdriver

Chromedriver

下载地址:http://chromedriver.storage.googleapis.com/index.html

firefox

下载地址:Releases · mozilla/geckodriver · GitHub

2.driver版本选择

查看版本:

Chrome浏览器输入:chrome://version/,查看版本

selenium环境配置(Mac&Windows)_第3张图片

选择与版本号一样的驱动文件(没有同样版本号优先选择大版本号相同的最新版本)

selenium环境配置(Mac&Windows)_第4张图片

选择Mac版本的Chromedriver下载:

selenium环境配置(Mac&Windows)_第5张图片

解压后移动到/usr/local/bin目录下

前往文件夹:/usr/local/bin

selenium环境配置(Mac&Windows)_第6张图片

如果遇到问题:

selenium环境配置(Mac&Windows)_第7张图片

解决方案:

打开系统偏好设置->安全性与隐私->通用->点击允许即可。

代码测试:

from selenium import webdriver  # 导入webdriver

driver = webdriver.Chrome()  # 实例化Chrome浏览器
driver.get("http://www.baidu.com")  # 打开http://www.baidu.com

安装allure(需要先安装JAVA)

1.下载allure

下载地址:Releases · allure-framework/allure2 · GitHub

解压zip包,并获取到bin的路径

例如:

/Users/quanyu/software/allure-2.19.0/bin

2.配置allure的环境变量

1、在终端输入命令

vi ~/.bash_profile

2、添加allure的路径

在文件末尾添加

export PATH=${PATH}:本地allure的bin目录路径

3、保存

4、使环境变量生效

source ~/.bash_profile

3.验证是否生效

在终端输入命令

allure --version

展示版本号则安装成功

二、Windows

Python环境配置

1.下载Python

官网地址:Python Releases for Windows | Python.org

2.进行安装

selenium环境配置(Mac&Windows)_第8张图片

3.Python成功安装检测

打开cmd,输入python --version,输出版本号即为安装成功

安装依赖包

selenium安装

pip install selenium

pytest安装

pip install pytest

安装webdriver

1.下载webdriver

Chromedriver

下载地址:http://chromedriver.storage.googleapis.com/index.html

firefox

下载地址:https://gitHub.com/mozilla/geckodriver/releases

2.driver版本选择

查看版本:

Chrome浏览器输入:chrome://version/,查看版本

selenium环境配置(Mac&Windows)_第9张图片

选择与版本号一样的驱动文件(没有同样版本号优先选择大版本号相同的最新版本)

selenium环境配置(Mac&Windows)_第10张图片

selenium环境配置(Mac&Windows)_第11张图片

解压到chrome的根目录

selenium环境配置(Mac&Windows)_第12张图片

将下载的文件解压到这个文件夹

selenium环境配置(Mac&Windows)_第13张图片

环境变量配置

设置->系统->关于->高级系统设置,将上面的路径添加到Path即可

selenium环境配置(Mac&Windows)_第14张图片

安装allure(需要先安装JAVA)

1.下载allure

下载地址:https://github.com/allure-framework/allure2/releases

解压zip包,并获取到bin的路径

例如:

D:\Software\allure-2.19.0\bin

2.配置allure的环境变量

编辑系统变量Path

selenium环境配置(Mac&Windows)_第15张图片

3.验证是否生效

在终端输入命令

allure --version

展示版本号则安装成功

selenium环境配置(Mac&Windows)_第16张图片

你可能感兴趣的:(selenium,selenium,python)