数据驱动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||异常失败

 

python webdriver 测试框架-数据驱动txt文件驱动,带报告的例子的更多相关文章

  1. python webdriver 测试框架-数据驱动json文件驱动的方式

    数据驱动json文件的方式 test_data_list.json: [ "邓肯||蒂姆", "乔丹||迈克尔", "库里||斯蒂芬", & ...

  2. python webdriver 测试框架-数据驱动excel驱动的方式

    简介: 数据驱动excel驱动方式,就是数据配置在excel里面,主程序调用的时候每次用从excel里取出的数据作为参数,进行操作, 需要掌握的地方是对excel的操作,要灵活的找到目标数据 测试数据 ...

  3. python webdriver 测试框架-数据驱动xml驱动方式

    数据驱动xml驱动的方式 存数据的xml文件:TestData.xml: <?xml version="1.0" encoding="utf-8"?> ...

  4. python webdriver 测试框架-数据驱动exce驱动,不用ddt的方式

    data.xlsx: 脚本: #encoding=utf-8from selenium import webdriverimport timeimport datetimefrom openpyxl ...

  5. python webdriver 测试框架-数据驱动DDT的例子

    先在cmd环境 运行 pip install ddt 安装数据驱动ddt模块  脚本: #encoding=utf-8 from selenium import webdriver import un ...

  6. python webdriver 测试框架-行为驱动例子

    安装行为驱动模块lettuce(卷心菜)模块 pip install lettuce Successfully installed argparse-1.4.0 colorama-0.3.9 extr ...

  7. python nose测试框架全面介绍九---各种html报告插件对比

    一直在使用Nose-html-reporting,并输出html报告,但今天在使用时发出有点问题:于时,将python目前可能的html报告插件下载后进行对比,如下 一.Nose-html-repor ...

  8. python nose测试框架全面介绍七--日志相关

    引: 之前使用nose框架时,一直使用--logging-config的log文件来生成日志,具体的log配置可见之前python nose测试框架全面介绍四. 但使用一段时间后,发出一个问题,生成的 ...

  9. python nose测试框架全面介绍十---用例的跳过

    又来写nose了,这次主要介绍nose中的用例跳过应用,之前也有介绍,见python nose测试框架全面介绍四,但介绍的不详细.下面详细解析下 nose自带的SkipTest 先看看nose自带的S ...

随机推荐

  1. RF使用的相关库API

    RF内置库: http://robotframework.org/robotframework/ SSHLibrary:   ---WEB自动化测试 http://robotframework.org ...

  2. VS2015编译GEOS3.5.1源码

    官网下载下来的geos3.5.1,执行CMakeLists.txt,发现会报错:GenerateSourceGroups 去github上搜索geos,然后去\cmake\modules目录下复制一份 ...

  3. linux发布项目

    1.右击项目 export --->war file 上传到linux服务器 2.解压 jiar -xvf xx.war 3.移动到 tomcat webapps文件中 4.启动tomcat 访 ...

  4. Delphi 单元

    单元(unit)是组成Pascal程序的单独的源代码模块,单元有函数和过程组成,这些函数和过程能被主程序调用.一个单元至少要有unit语句,interface,和implementation三部分,也 ...

  5. redis基础----->redis的基本使用(一)

    这里我们就在虚拟机中安装redis,并且使用java和python实现简单的操作.深情是我承担不起的重担,情话只是偶尔兑现的谎言. redis的使用 下载地址:https://redis.io/.安装 ...

  6. LeetCode——Contains Duplicate II

    Description: Given an array of integers and an integer k, find out whether there there are two disti ...

  7. JavaWeb温习之防止表单重复提交

    表单重复提交主要有以下三种情况: 1. 在网络延迟的情况下让用户有时间点击多次submit按钮导致表单重复提交 2. 表单提交后用户点击[刷新]按钮导致表单重复提交 3. 用户提交表单后,点击浏览器的 ...

  8. [SQL]批量 更改字符集脚本,批量查询约束,批量查询索引

    How to change collation of all database objects in SQL Server. Have you encountered a problem where ...

  9. java启动3个线程轮流打印数字

    转自:http://blog.csdn.net/u014011112/article/details/50988769 http://blog.csdn.net/perrywork/article/d ...

  10. oneThink发生错误,获取当前执行的SQL语句!

    echo D('AnswerInfoView')->getLastSql();die();