selenium+python笔记6
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@desc: 将登陆动作封装成function
"""
import unittest
import sys
import os
from selenium import webdriver
from selenium.webdriver.common.keys import Keys # 单独运行这个py文件时,需要加入下面的代码,用以将项目的目录加载到系统变量中。
# 使用all_test运行所有用例时,可以注释掉
cur_dir = os.getcwd()
sys.path.append(cur_dir.split(r'\test_case')[0]) from public import login class TestLogin(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://www.126.com/"
self.verificationErrors = []
# self.accept_next_alert = True def test_login(self):
driver = self.driver
driver.get(self.base_url) # 实际项目测试时,很多用例执行前都需要先登录账户,
# 我们可以将这些常用的动作抽出来,组成一个function(/public/login.py)
login.login(self, 'xxxxx', 'xxxxx') # 输入你的邮箱账号和密码 # 获取断言信息进行断言
text = driver.find_element_by_id("spnUid").text
self.assertEqual(text, "xxxxx@126.com")
# 退出
login.logout(self) # 搜索邮件
def test_search_mail(self):
driver = self.driver
driver.get(self.base_url)
# 调用登录模块
login.login(self, 'xxxxx', 'xxxxx')
# 搜索邮件
driver.find_element_by_xpath("//input[@class='nui-ipt-input' and @type='text']").send_keys(u'小明')
driver.find_element_by_xpath("//input[@class='nui-ipt-input' and @type='text']").send_keys(Keys.ENTER)
# 断言搜索邮件标签页面
text = driver.find_element_by_xpath("//div[@id='dvMultiTab']/ul/li[5]/div[3]").text
self.assertEqual(text, u'搜索邮件')
# 调用退出
login.logout(self) def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors) if __name__ == "__main__":
# unittest.main()
import os
print os.getcwd()
selenium+python笔记6的更多相关文章
- selenium+python笔记11
#!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: search in mail box "&qu ...
- selenium+python笔记10
#!/usr/bin/env python # -*- coding: utf-8 -*- """ 我们多添加一些测试场景,比如:删除邮件,查找邮件,发送邮件等等 &qu ...
- selenium+python笔记9
#!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: delete mail 我们多添加一些测试场景,比如:删 ...
- selenium+python笔记8
#!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: 定制浏览器 """ imp ...
- selenium+python笔记7
#!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: 测试126邮箱的登陆功能 1.使用公共方法public. ...
- selenium+python笔记5
#!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: 登陆126邮箱 """ f ...
- selenium+python笔记4
#!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: 使用unittest组织用例 ""& ...
- selenium+python笔记3
#!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc:学习unittest的用法 注意setUp/setUpCl ...
- selenium+python笔记2
#!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: 操作浏览器 """ fro ...
随机推荐
- C语言使用fread和fwrite处理任何文件
1.文件必须以二进制形式打开 FILE* pfile1=fopen("fileone","rb"); FILE* pfile2=fopen("file ...
- git版本控制器
Git 是一个开源的分布式版本控制系统 Google用于android 源代码的管理就是Git, 它支持离线工作, 本地提交可以稍后提交到服务器上. 众多的开源项目都使用 Git 作为版本控制系统 ...
- strtr介绍
strtr — 转换指定字符 string strtr ( string $str , string $from , string $to ) string strtr ( string $str , ...
- .Net操作.exe文件
Process proc = new Process(); proc.StartInfo.FileName = @"D:\Program Files\Foxmail\Foxmail.exe& ...
- BZOJ 2561 最小生成树(最大流)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2561 题意:给定一个边带正权的连通无向图G= (V,E),其中N=|V|,M=|E|,N ...
- ADC驱动器或差分放大器设计指南
作为应用工程师,我们经常遇到各种有关差分输入型高速模数转换器(ADC)的驱动问题.事实上,选择正确的ADC驱动器和配置极具挑战性.为了使鲁棒性ADC电路设计多少容易些,我们汇编了一套通用“路障”及解决 ...
- NSKeyedArchive(存储自定义对象)
在viewController.m中: - (void)viewDidLoad { [super viewDidLoad]; ZWPerson *p = [[ZWPerson alloc] init] ...
- So easy Webservice 5.WSDL 文件说明
WSDL – WebService Description Language – Web服务描述语言 通过XML形式说明服务在什么地方-地址. 通过XML形式说明服务提供什么样的方法 – 如何调用. ...
- 《NoSQL精粹》思维导图读书笔记
<NoSQL精粹>思维导图读书笔记 各主题笔记 这本书短小精悍,虽不能解答所有NoSQL疑问,但在读书过程中会抛给你不少未曾想过的问题,给人以更深入的思考: 这里对每一个主题分别做了笔记: ...
- CSS笔记(四)文本
CSS 文本属性可定义文本的外观.通过文本属性,可以改变文本的颜色.字符间距,对齐文本,装饰文本和对文本进行缩进,等等. 参考:http://www.w3school.com.cn/css/css_t ...