python for selenium 数据驱动测试
# -*- coding:utf-8 -*-
"""
数据驱动测试,从 csv 文件中读取数据
"""
from selenium import webdriver
import csv, sys test_executed = 0
test_passed = 0
test_failed = 0
test_status = True try:
driver = webdriver.Firefox()
driver.get('C:\BMICalculator.html') datafile = open(r'c:\data.csv', 'rb')
reader = csv.reader(datafile) test_executed = 0 for row in reader:
test_executed += 1
print 'Test' + str(test_executed) heightField = driver.find_element_by_name('heightCMS')
heightField.clear()
heightField.send_keys(row[0]) weightField = driver.find_element_by_name('weightKg')
weightField.clear()
weightField.send_keys(row[1]) calculateButton = driver.find_element_by_id('Calculate')
calculateButton.click() bmiLabel = driver.find_element_by_name('bmi')
bmiCategoryLabel = driver.find_element_by_name('bmi_category') if bmiLabel.get_attribute('value') == row[2]:
print "PASS, expected value for BMI <" + row[2] + "> actual <" + bmiLabel.get_attribute('value') + ">"
else:
print "FAIL, expected value for BMI <" + row[2] + "> actual <" + bmiLabel.get_attribute('value') + ">"
test_status = False if bmiCategoryLabel.get_attribute('value') == row[3]:
print "PASS, expected value for BMI Category <" + row[3] + "> actual <" + bmiCategoryLabel.get_attribute('value') + ">"
else:
print "Fail, expected value for BMI Category <" + row[3] + "> actual <" + bmiCategoryLabel.get_attribute('value') + ">"
test_status = False if test_status == True:
test_passed = test_passed + 1
else:
test_failed = test_failed + 1 except :
print "Unexpected error: ", sys.exc_info()[0]
raise finally:
print "---------------------------------------------------------------"
print "Total (" + str(test_executed) + ") Tests Executed"
print "Total (" + str(test_passed) + ") Tests Passed"
print "Total (" + str(test_failed ) + ") Tests Failed"
driver.close()
datafile.close()
python for selenium 数据驱动测试的更多相关文章
- Python&Selenium 数据驱动测试【unittest+ddt+xml】
一.摘要 本博文将介绍Python和Selenium做自动化测试时,基于unittest框架,借助ddt模块,使用xml文件作为测试输入. 二.xml文件 保存路径:D:\\Programs\\Pyt ...
- Selenium数据驱动测试模型和实例
模块驱动的模型虽然解决了脚本的重复问题,但是需要测试不同数据的用例时,模块驱动的方式就不很适合了. 数据驱动就是数据的改变从而驱动自动化测试的执行,最终引起测试结果的改变. 装载数据的方式可以是列表. ...
- Python Selenium 之数据驱动测试
数据驱动模式的测试好处相比普通模式的测试就显而易见了吧!使用数据驱动的模式,可以根据业务分解测试数据,只需定义变量,使用外部或者自定义的数据使其参数化,从而避免了使用之前测试脚本中固定的数据.可以将测 ...
- Python Selenium 之数据驱动测试的实现
数据驱动模式的测试好处相比普通模式的测试就显而易见了吧!使用数据驱动的模式,可以根据业务分解测试数据,只需定义变量,使用外部或者自定义的数据使其参数化,从而避免了使用之前测试脚本中固定的数据.可以将测 ...
- Python+Selenium笔记(十二):数据驱动测试
(一) 前言 通过使用数据驱动测试,实现对输入值和预期结果的参数化.(例如:输入数据和预期结果可以直接读取Excel文档的数据) (二) ddt 使用ddt执行数据驱动测试,ddt库可以将测试 ...
- Selenium(十四):自动化测试模型介绍、模块化驱动测试案例、数据驱动测试案例
1. 自动化测试模型介绍 随着自动化测试技术的发展,演化为了集中模型:线性测试.模块化驱动测试.数据驱动测试和关键字驱动测试. 下面分别介绍这几种自动化测试模型的特点. 1.1 线性测试 通过录制或编 ...
- Python&Selenium 数据驱动【unittest+ddt】
一.摘要 本博文将介绍Python和Selenium做自动化测试的时候,基于unittest框架,借助ddt实现数据驱动 二.测试代码 # encoding = utf-8 ""& ...
- Python&Selenium 数据驱动【unittest+ddt+json】
一.摘要 本博文将介绍Python和Selenium做自动化测试的时候,基于unittest框架,借助ddt模块使用json文件作为数据文件作为测试输入,最后生成html测试报告 二.json文件 [ ...
- 【python驱动】python进行selenium测试时GeckoDriver放在什么地方?
背景:用python进行selenium 关于b/s架构的测试,需要配置驱动否则程序无法执行 情况1:windows下放置GeckoDriver 步骤1:下载驱动 GeckoDriver下载地址fir ...
随机推荐
- javascript实现继承的6种方式
/*1.原型链继承*/ function SuperType() { this.property = true; } SuperType.prototype.getSuperValue = funct ...
- CSS自动控制图片大小的代码
img { max-width: 800px; height: auto; } 代码中的max-width:800px限制图片的最大宽度为800像素,而下面的hight:auto很关键,可以保证图片有 ...
- CI 笔记,使用 json的参考文档(废弃)
Json的处理转换, Json转换步骤, a) 先设置json为空字符串, b) While循环,遍历, While(!!$row = mysql_fetch_arra ...
- SQL Server 索引和视图【转】
Ø 索引 1. 什么是索引 索引就是数据表中数据和相应的存储位置的列表,利用索引可以提高在表或视图中的查找数据的速度. 2. 索引分类 数据库中索引主要分为两类:聚集索引和非聚集索引.SQL Serv ...
- ubuntu亮度无法自动调节终极解决方案
友情链接:IT狂人博客 这个问题纠结了我快两年,主要是自己懒,写了个脚本来调节亮度,不过还是稍显不便.近日兴起折腾了一番,终于找到问题根结了. There are many ways to contr ...
- IOS pop使用代理传值
假如oneViewController页面push到OtherViewController页面,然后你想从OtherViewController页面pop到oneViewController页面的时候 ...
- Windows Phone 之播放视频
在Windows Phone 7中播放视频有两种方式, (1)使用MediaElement 控件来播放:用MediaElement 控件来播放视频比较灵活,你需要自己去实现播放暂停进度条等等的功能,播 ...
- js获取星期几
function getweek(time) { /*显示星期*/ /*time为date格式*/ var str; var d = time.getDay(); switch (d) { case ...
- 大型情感类电视连续剧--Android高德之旅(3)地图交互
总要说两句 前两篇讲到了地图的基础显示和地图类型,今天来记录下高德地图交互相关的设置.地图的绘制分很多层,层级的显示需要根据不同的场景来设置.地图的触摸事件也很丰富,有单击.双击.单指拖拽.双指拖拽. ...
- thinkphp我掉下的一些坑
1.数据库连接,需要连接没有数据表前缀 如下,第二个参数必须为null,我之前写的是'',结果给我默认加了前缀 $User = M('User',Null,'DB_CONFIG2'); 2.AJAX获 ...