博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python webdriver 测试框架-数据驱动txt文件驱动,带报告的例子
阅读量:4502 次
发布时间:2019-06-08

本文共 1460 字,大约阅读时间需要 4 分钟。

数据驱动txt文件驱动的方式,带报告

data.txt:

gloryroad test||光荣之路

摔跤爸爸||阿米尔

超人||电影

 

data_driven_by_txt_file.py:

#encoding=utf-8

from selenium import webdriver

import time

with open(u"e:\\数据驱动\\data.txt") as fp:

    data=fp.readlines()

 

driver=webdriver.Ie(executable_path="e:\\IEDriverServer")

test_result=[]

for i in range(len(data)):

    try:

        driver.get("http://www.baidu.com")

        driver.find_element_by_id("kw").send_keys(\

        data[i].split("||")[0].strip().decode("gbk"))

        driver.find_element_by_id("su").click()

        time.sleep(3)

        assert data[i].split('||')[1].strip().decode('gbk')\

        in driver.page_source

        test_result.append(data[i].strip()+u"||成功\n".encode("gbk"))

        print data[i].split('||')[0].strip().decode('gbk')+u"搜索测试执行成功"

    except AssertionError,e:

        print data[i].split('||')[1].strip().decode('gbk')+u"测试断言失败"

        test_result.append(data[i].strip()+u"||断言失败\n".encode("gbk"))

    except Exception,e:

        print data[i].split('||')[1].strip().decode('gbk')+u"测试执行失败"

        test_result.append(data[i].strip()+u"||异常失败\n".encode("gbk"))

 

with open(u"e:\\数据驱动\\result.txt","w") as fp:

            fp.writelines(test_result)

driver.quit()

 

结果:

D:\test>python test.py

gloryroad test搜索测试执行成功

摔跤爸爸搜索测试执行成功

超人搜索测试执行成功

 

 

Result.txt:

gloryroad test||光荣之路||成功

摔跤爸爸||阿米尔||成功

超人||电影||成功

 

修改data.txt使断言失败的结果:

data.txt:

gloryroad test||光荣之路1

摔跤爸爸||阿米尔1

超人||电影1

 

D:\test>python test.py

光荣之路1测试断言失败

阿米尔1测试断言失败

电影1测试断言失败

 

Result.txt:

gloryroad test||光荣之路1||异常失败

摔跤爸爸||阿米尔1||异常失败

超人||电影1||异常失败

 

转载于:https://www.cnblogs.com/xiaxiaoxu/p/9231506.html

你可能感兴趣的文章
浅析负载均衡的6种算法,Ngnix的5种算法
查看>>
OpenCV——图像修补
查看>>
自定义 DateTime 格式字符串
查看>>
设计模式--工厂模式Factory
查看>>
五年修炼SEO、一年五万,多嘛?(看时间如何管理?五点论……)
查看>>
Mesos源码分析(16): mesos-docker-executor的运行
查看>>
echarts柱状图点击阴影部分触发事件
查看>>
3771: Triple
查看>>
使用PyPDF2库对pdf文件进行指定页面删除操作
查看>>
Python:yield关键字
查看>>
EasyRTSPClient:基于live555封装的支持重连的RTSP客户端RTSPClient
查看>>
EasyDarwin云存储方案调研:海康萤石云采用的是MPEG-PS打包的方式进行的存储
查看>>
MySQL巡检
查看>>
学习笔记之传说中的圣杯布局
查看>>
oh-my-zsh的使用
查看>>
共享内存的设计
查看>>
deque容器
查看>>
2017-2018-1 20155203 20155204 实验二 固件程序设计
查看>>
三方贸易-drop ship
查看>>
Android RenderScript 使用 Struct 及其下标的赋值
查看>>