unittest框架学习笔记五之参数化
例子一:
# coding=utf-8
'''created:2018/3/29
author:star
project:lianxi canshuhua'''
from selenium import webdriver
import unittest,os,time
import HTMLTestRunner class baidu002(unittest.TestCase):
def setUp(self):
self.driver=webdriver.Chrome()
self.driver.maximize_window()
self.driver.implicitly_wait(20)
self.baseurl="http://www.baidu.com/?tn=90702711_hao_pg" def login1(self,text):
driver=self.driver
driver.get(self.baseurl)
driver.find_element_by_id("kw").clear()
driver.find_element_by_id("kw").send_keys(text)
driver.find_element_by_id("su").click()
time.sleep(2) def duanyan(self,title1):
driver=self.driver
title=driver.title ###通过titile来判断
self.assertEqual(title,title1) def test001(self):
self.login1("selenium")
self.duanyan(title1=u"selenium_百度搜索") def test002(self):
self.login1("python")
self.duanyan(title1=u"python_百度搜索") def test003(self):
self.login1("java")
self.duanyan(title1=u"java_百度搜索") def tearDown(self):
self.driver.quit() if __name__ == '__main__':
unittest.main() 例子二:
# coding=utf-8
'''created:2018/3/29
author:star
project:canshuhua'''
from selenium import webdriver
import unittest,time,os
import HTMLTestRunner
class lingzhuyun(unittest.TestCase):
def setUp(self):
self.driver=webdriver.Chrome()
self.driver.maximize_window()
self.driver.implicitly_wait(20)
self.baseurl="http://www.*********“
def login(self,username,password):
driver=self.driver
driver.get(self.baseurl)
driver.find_element_by_id("login").clear()
driver.find_element_by_id("login").send_keys(username) ##用户名
driver.find_element_by_id("password").clear()
driver.find_element_by_id("password").send_keys(password) ###密码
time.sleep(2)
driver.find_element_by_xpath("//div[@class='clearfix oe_login_buttons']/button[@class='btn btn-primary']").click() ####登录
time.sleep(3) def duanyan(self):
driver=self.driver
try:
result_text=driver.find_element_by_xpath("//a[@class='oe_menu_toggler']/span[@class='oe_menu_text']").text ####通过文本内容来判断登录是否成功
print (result_text)
return True
except:
return False def test1(self):
self.login(u"大猩猩","134*****")
a=self.duanyan()
self.assertTrue(a) def test2(self):
self.login(u"大猩猩","135*******")
a=self.duanyan()
self.assertTrue(a) def test3(self):
self.login("aaaaaa","134*****")
a=self.duanyan()
self.assertTrue(a) def test4(self):
self.login("aaaaaa","135******")
a=self.duanyan()
self.assertTrue(a) def tearDown(self):
self.driver.quit() if __name__ == '__main__':
unittest.main()
unittest框架学习笔记五之参数化的更多相关文章
- selenium + python自动化测试unittest框架学习(五)webdriver的二次封装
因为webdriver的api方法很长,再加上大多数的定位方式是以xpath方式定位,更加让代码看起来超级长,为了使整体的代码看起来整洁,对webdriver进行封装,学习资料来源于虫师的<se ...
- unittest框架学习笔记四之report
# coding=utf-8'''created:2018/3/29 author:star project:test report'''# import time,os# from selenium ...
- unittest框架学习笔记三之testsuite
# coding=utf-8 '''created :2018/3/29 author:star project: testsuite'''import unittest,time,osfrom ba ...
- unittest框架学习笔记二之discover
coding=utf-8'''Created on 2018/3/29 author:star Project:discover测试用例''' import unittest,time,oslist= ...
- unittest框架学习笔记一之testcase
# coding=utf-8案例一: 2 ''' 3 Created on 2017-7-22 4 @author: Jennifer 5 Project:登录百度测试用例 6 ''' 7 from ...
- go微服务框架kratos学习笔记五(kratos 配置中心 paladin config sdk [断剑重铸之日,骑士归来之时])
目录 go微服务框架kratos学习笔记五(kratos 配置中心 paladin config sdk [断剑重铸之日,骑士归来之时]) 静态配置 flag注入 在线热加载配置 远程配置中心 go微 ...
- JavaSE中Collection集合框架学习笔记(2)——拒绝重复内容的Set和支持队列操作的Queue
前言:俗话说“金三银四铜五”,不知道我要在这段时间找工作会不会很艰难.不管了,工作三年之后就当给自己放个暑假. 面试当中Collection(集合)是基础重点.我在网上看了几篇讲Collection的 ...
- scrapy爬虫框架学习笔记(一)
scrapy爬虫框架学习笔记(一) 1.安装scrapy pip install scrapy 2.新建工程: (1)打开命令行模式 (2)进入要新建工程的目录 (3)运行命令: scrapy sta ...
- selenium + python自动化测试unittest框架学习(一)selenium原理及应用
unittest框架的学习得益于虫师的<selenium+python自动化实践>这一书,该书讲得很详细,大家可以去看下,我也只学到一点点用于工作中,闲暇时记录下自己所学才能更加印象深刻. ...
随机推荐
- postgreSQL执行计划
" class="wiz-editor-body wiz-readonly" contenteditable="false"> explain命 ...
- js判断变量未定义
js判断变量未定义 控制台输出未定义变量a会报错: 我们打印出a的数据类型是: 我们可以看到未定义变量的数据类型是 "undefined" 所以判断js变量是否未定义的方法就是 t ...
- 畜禽免疫系统使用LODOP打印
<div class="btn_box"> <asp:Button ID="btnPrint" Text="预览并打印" ...
- activiti7查询流程定义的相关信息
package com.zcc.activiti02; import org.activiti.engine.ProcessEngine;import org.activiti.engine.Proc ...
- mysql 个人博客应用的建表和相关查询
一.建表 用户表tb_user create table if not exists tb_user( user_id int auto_increment, ) not null, user_pas ...
- JeeSite使用(一)大步跑起来
背景:近期准备换个工作,想对之前自己写的代码进行重构,选择了JeeSite 需求:跑起来才是硬道理 方法:1.官方文档有坑,别信他 2.官方文档有坑,别信他 3.官方文档有坑,别信他 一 ...
- Eclipse国内下载升级方法
Eclipse国内下载升级方法 */--> code {color: #FF0000} pre.src {background-color: #002b36; color: #839496;} ...
- pthread_create()的一个错误示例
//pthread_create()函数的错误示例 //新建线程同时传入线程号.线程号总和和消息 #include <stdio.h> #include <pthread.h> ...
- python 根据余弦定理计算两边的夹角
前面写过C#的. import numpy def GetAngle(sta_point, mid_point, end_point): ma_x = sta_point.X-mid_point.X ...
- Shell内置命令 eval