selenium自动化登录模块HTMLTestRunner测试报告

1.下载HTMLTestRunner.py放到python的Lib目录下,python3之后的,文件要修改以下内容:

第94行,将import StringIO修改成import io

第539行,将self.outputBuffer = StringIO.StringIO()修改成self.outputBuffer = io.StringIO()

第642行,将if not rmap.has_key(cls):修改成if not cls in rmap:

第766行,将uo = o.decode('latin-1')修改成uo = e

第772行,将ue = e.decode('latin-1')修改成ue = e(网络上很多这句是没写的,遗漏了。这句不改会有提示错误且测试报告无法生成)

第774行,将ue = e.decode('latin-1')修改成ue = e(网络上写的是775行是错误的,应该为774行)

第631行,将print >> sys.stderr, '\nTime Elapsed: %s' % (self.stopTime-self.startTime)修改成print(sys.stderr, '\nTime Elapsed: %s' % (self.stopTime-self.startTime))

2.登录模块代码CSDNlogin.py

复制代码
import time
import unittest

from selenium.webdriver.common.by import By

import CSDNconf
class CSDNlogin(unittest.TestCase):
    def testLogin(self):

        CSDNconf.driver.get("https://passport.csdn.net/")
        CSDNconf.driver.maximize_window()
        #点击密码登录
        CSDNconf.driver.find_element(By.XPATH,"/html/body/div[2]/div/div[2]/div[2]/div[2]/div/div[1]/span[4]").click()
        #输入用户名
        CSDNconf.driver.find_element(By.XPATH,"/html/body/div[2]/div/div[2]/div[2]/div[2]/div/div[2]/div/div[1]/div/input").send_keys("627168856@qq.com")
        #输入密码
        CSDNconf.driver.find_element(By.XPATH,"/html/body/div[2]/div/div[2]/div[2]/div[2]/div/div[2]/div/div[2]/div/input").send_keys("zhangaihua@315717")
        # 勾选我已阅读并同意 服务条款 和 隐私协议
        CSDNconf.driver.find_element(By.XPATH,"/html/body/div[2]/div/div[2]/div[2]/div[2]/div/div[2]/p/div/i").click()
        #点击登录按钮
        CSDNconf.driver.find_element(By.XPATH,"/html/body/div[2]/div/div[2]/div[2]/div[2]/div/div[2]/div/div[4]/button").click()
        time.sleep(5)
        CSDNconf.driver.quit()

3.main.py

复制代码
# This is a sample Python script.
import unittest
import HTMLTestRunner
import HTMLReport
from CSDNlogin import CSDNlogin


# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.


def print_hi(name):
    # Use a breakpoint in the code line below to debug your script.
    print(f'Hi, {name}')  # Press Ctrl+F8 to toggle the breakpoint.


# Press the green button in the gutter to run the script.
if __name__ == '__main__':
   testunit = unittest.TestSuite()
   # 添加测试用例到测试套件中
   testunit.addTest(CSDNlogin("testLogin"))#CSDNlogin是类名testLogin是函数名
   print(testunit)
   # 定义个报告存放路径
   filename = 'D:\\Pythonproject\\CSDNUItest\\report\\result.html'
   fp = open(filename, 'wb')
   # 定义测试报告
   runner = HTMLTestRunner.HTMLTestRunner(stream=fp, title=u'测试报告', description=u'用例执行情况:')
   # 运行测试用例
   runner.run(testunit)
   # 关闭报告文件
   fp.close()


# See PyCharm help at https://www.jetbrains.com/help/pycharm/

4.输出报告:

相关推荐
醉颜凉6 小时前
数据仓库实战:自动化数据质量检测全流程——精准提升数据准确性与完整性
大数据·数据仓库·自动化
HBYKKJ8 小时前
格雷希尔GFL浮动组件:大范围浮动补偿赋能自动化产线高效柔性对接,兼容大部分对正场景,适配市面常见的机器人末端执行器与工装安装板
人工智能·机器人·自动化
天远Date Lab9 小时前
零信任架构实战:基于天远行驶证核查构建自动化车队准入网关
运维·人工智能·架构·自动化
St_rive13 小时前
webUI自动化实现及封装
运维·自动化
qq_5137280413 小时前
浏览器配置 + 文件上传 + 截图
python·selenium·测试工具·计算机外设
QYR_1113 小时前
2032年气相分解设备市场规模达2.25亿美元:VPD向高灵敏度、自动化晶圆污染检测升级
运维·自动化
Είναι η κοπέλα14 小时前
游戏窗口自动化点击与防误点设计:模板匹配 + 区域限制 + 强制置顶
运维·游戏·自动化
深念Y14 小时前
AI Agent 时代运维安全:rm 防误删方案对比
linux·运维·人工智能·安全·自动化·agent
TELL52115 小时前
启动后端服务跑第一个用例成功,重新跑第二个用例chromedriver死活不成功,猜测是chromedriver本身的问题
selenium·webdriver
环境栈笔记17 小时前
指纹浏览器怎么用:从 Profile、代理到环境检测的完整上手流程
前端·人工智能·后端·自动化