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 ...
随机推荐
- itoa
功能:把int转为字符数组 eg: int a=100: char ch[3]; itoa(a,ch,10)://十进制 ---->ch[0]==1;...
- POJ 2533 Longest Ordered Subsequence 最长递增序列
Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequenc ...
- 四HttpServletResponse常见应用——生成验证码
转载自http://www.cnblogs.com/xdp-gacl/p/3791993.html 一.HttpServletResponse常见应用——生成验证码 1.1.生成随机图片用作验证码 生 ...
- Android 路径大全
1 内部存储路径为/data/data/youPackageName/ 目录结构 //返回cache文件对象 this.getCacheDir(); //返回databases下指定文件 this.g ...
- Cheatsheet: 2013 08.20 ~ 08.31
.NET Protobuf-net: the unofficial manual 5 Common C# Misconceptions What is new in the Mono project ...
- git push 403
1. 在github上新建一个空项目. 2. git clone 到本地仓库. 3. git add [一些文件]. 4. git commit -m "first commit" ...
- [转]What you need to know about transimpedance amplifiers – part 1
Transimpedance amplifiers (TIAs) act as front-end amplifiers for optical sensors such as photodiodes ...
- ,2,liunx命令格式
一.命令基本格式 ~用户的初始登录位置 /root 这个叫root用户的家目录,每个用户都有自己的家 超级用户的家是根目录,普通用户的家是home下的二级目录 :/home/uer1 pwd ...
- 后台输出HTML
在前台定义CSS样式: <style type="text/css"> .style1 { width: 120px; } .style3 { width: 488px ...
- LINQ之路 5:LINQ查询表达式
书写LINQ查询时又两种语法可供选择:方法语法(Fluent Syntax)和查询表达式(Query Expression). LINQ方法语法的本质是通过扩展方法和Lambda表达式来创建查询.C# ...