目录: 一、环境安装,含网盘地址(该自动化使用的是:Python+PyCharm+Selenium+ie(或者谷歌)+unittest(或pytest)+HTMLTestRunner+jenkins+录制工具(selenium ide) 二、使用HTMLTestRunner生成测试报告,自行下载“HTMLTestRunner.py”文件,将该文件复制到Python安装目录下的Lib文件夹中,在python中import HTMLTestRunner,没有报错,则导入成功,通过HTMLTestRunner.HTMLTestRunner来生成测试报告 三、持续集成jenkins 报错No module named 'email.mime':一开始将文件名命名为email.py,运行的时候报错ModuleNotFoundError: No module named 'email.mime'; 'email' is not a package,将文件名改成emailUtil.py(或其他)就可以了。主要是因为和Python内置的email模块 四、电子邮件(含代码) 见:自动化测试教程 在自动化测试领域,Python语言因其简洁性和丰富的库支持而被广泛应用。本教程主要涉及使用Python 3.6、PyCharm 2018、Selenium、unittest和pytest框架进行自动化测试,同时利用HTMLTestRunner生成测试报告,并通过Jenkins实现持续集成。以下是详细的知识点解析: 1. **环境搭建**: - **Python 3.6**:Python是一种解释型、面向对象的编程语言,3.6版本是其稳定的一个版本。安装时需自定义路径并设置环境变量。 - **PyCharm 2018**:这是一个强大的Python IDE,提供了代码编辑、调试、版本控制等多方面支持,便于编写和管理自动化测试脚本。 - **Selenium**:Selenium 是一个用于Web应用程序测试的工具,允许模拟真实用户对浏览器的操作,如点击、输入等。 - **IE或Chrome浏览器驱动**:Selenium需要对应浏览器的驱动程序来控制浏览器,如iedriver.exe或chromedriver.exe。 - **unittest和pytest**:unittest是Python内置的单元测试框架,而pytest是更高级、功能更丰富的测试框架,两者都可以用于编写自动化测试用例。 - **HTMLTestRunner**:这是一个Python模块,可以生成HTML格式的测试报告,使测试结果更直观。 - **Jenkins**:这是一个开源持续集成工具,可自动化构建、测试和部署任务,包括自动化测试的执行和报告生成。 - **Selenium IDE**:这是一个浏览器插件,用于录制和回放测试操作,简化测试脚本的创建。 2. **HTMLTestRunner使用**: - 下载`HTMLTestRunner.py`文件,并将其放在Python安装目录下的`Lib`文件夹中。 - 在Python脚本中导入`HTMLTestRunner`,如果没有报错,表示导入成功。 - 使用`HTMLTestRunner.HTMLTestRunner`创建测试报告实例,指定报告标题、描述和输出文件。 3. **持续集成Jenkins**: - 配置Jenkins环境,安装必要的插件,如Python插件、Publish Over Email插件等。 - 创建新的Jenkins Job,添加构建步骤,如运行Python测试脚本。 - 当遇到`No module named 'email.mime'`错误时,应避免与Python内置模块名冲突,例如将文件名改为`emailUtil.py`。 4. **发送电子邮件**: - 可以使用Python内置的`email`模块,结合`smtplib`模块,编写代码发送包含测试报告的电子邮件。 示例代码展示了如何使用unittest和HTMLTestRunner生成测试报告: ```python import unittest from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.ui import Select from selenium.common.exceptions import NoSuchElementException import time, re import HTMLTestRunner class Baidu(unittest.TestCase): # setUp方法在每个测试用例前执行 def setUp(self): self.driver = webdriver.Firefox() self.driver.implicitly_wait(30) self.base_url = "http://www.baidu.com/" self.verificationErrors = [] self.accept_next_alert = True # 测试用例 def test_baidu_search(self): driver = self.driver driver.get(self.base_url + "/") driver.find_element_by_id("kw").send_keys("selenium webdriver") driver.find_element_by_id("su").click() time.sleep(2) driver.close() # tearDown方法在每个测试用例后执行 def tearDown(self): self.driver.quit() self.assertEqual([], self.verificationErrors) if __name__ == "__main__": # 创建测试套件 testunit = unittest.TestSuite() testunit.addTest(Baidu("test_baidu_search")) # 指定报告文件 filename = "E:\\result1.html" fp = open(filename, 'wb') # 创建HTMLTestRunner实例并运行测试 runner = HTMLTestRunner.HTMLTestRunner( stream=fp, title='百度搜索测试报告', description='用例执行情况:' ) runner.run(testunit) ``` 以上代码创建了一个简单的Selenium测试用例,模拟在百度上搜索“selenium webdriver”,并使用HTMLTestRunner生成测试报告。
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/release/download_crawler_static/85236217/bg1.jpg)
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
- TomLong.Chen2024-01-12感谢大佬分享的资源,对我启发很大,给了我新的灵感。
- alice33332024-06-03资源内容总结的很到位,内容详实,很受用,学到了~
![avatar](https://profile-avatar.csdnimg.cn/default.jpg!1)
- 粉丝: 63
- 资源: 15
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
最新资源
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)