在使用Selenium进行UI自动化测试时,如果需要连接MySQL数据库进行数据校验,可以通过以下步骤实现:
1. 安装必要的库
首先,确保你已经安装了以下Python库:
你可以使用以下命令安装这些库:
pip install selenium mysql-connector-python
2. 连接MySQL数据库
使用mysql-connector-python
或pymysql
库连接MySQL数据库。以下是一个使用mysql-connector-python
的示例:
import mysql.connector# 数据库连接配置 config = {'user': 'your_username','password