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 ...
随机推荐
- SQL SERVER将某一列字段中的某个值替换为其他的值 分类: MSSQL 2014-11-05 13:11 67人阅读 评论(0) 收藏
SQL SERVER将某一列字段中的某个值替换为其他的值 UPDATE 表名 SET 列名 = REPLACE(列名 ,'贷','袋') SQL SERVER"函数 replace 的参数 ...
- js 的执行过程
step 1. 读入第一个代码块. step 2. 做语法分析,有错则报语法错误(比如括号不匹配等),并跳转到step5. step 3. 对var变量和function定义做"预编译 ...
- css - div垂直方向滚动
只要设置 OVERFLOW-Y:auto;OVERFLOW-X:hidden即可.
- LATEX学习笔记1
LATEX源文件的结构分三大部分,依次为:文档类声明.序言(可选).正文. 文档结构 \documentclass{article} \usepackage{amsmath} \usepackage{ ...
- STUN/TURN/ICE协议在P2P SIP中的应用(二)
1 说明 2 打洞和穿越的概念... 1 3 P2P中的打洞和穿越... 2 4 使用STUN系列 协议穿越的特点... 2 5 STUN/ ...
- ARM开发板系统移植-----kernel的编译
前面一篇文章http://www.cnblogs.com/linzizhang/p/4817336.html介绍了开发板上系统软件的第一部分--bootloader的编译方法. 背景:把bootloa ...
- PHP表单常用正则表达式(URL、HTTP、手机、邮箱等)
<?php /** * @description: 正则表达式匹配 */ class Regex { /** * @手机号 */ public static function Phone($su ...
- Android Activity 管理
- memcached在linux安装
服务器端主要是安装memcache服务器端.下载:http://www.danga.com/memcached/dist/memcached-1.2.2.tar.gz另外,Memcache用到了lib ...
- 编程思想—依赖注入(DI)并非实现控制反转(IOC)的最佳方法
以构造函数注入为例: public class TestClass(IClassA a,IClassB b, IClassC C,IClassD d) { public void Method1() ...