#!/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的更多相关文章

  1. selenium+python笔记11

    #!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: search in mail box "&qu ...

  2. selenium+python笔记10

    #!/usr/bin/env python # -*- coding: utf-8 -*- """ 我们多添加一些测试场景,比如:删除邮件,查找邮件,发送邮件等等 &qu ...

  3. selenium+python笔记9

    #!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: delete mail 我们多添加一些测试场景,比如:删 ...

  4. selenium+python笔记8

    #!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: 定制浏览器 """ imp ...

  5. selenium+python笔记7

    #!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: 测试126邮箱的登陆功能 1.使用公共方法public. ...

  6. selenium+python笔记5

    #!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: 登陆126邮箱 """ f ...

  7. selenium+python笔记4

    #!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: 使用unittest组织用例 ""& ...

  8. selenium+python笔记3

    #!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc:学习unittest的用法 注意setUp/setUpCl ...

  9. selenium+python笔记2

    #!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: 操作浏览器 """ fro ...

随机推荐

  1. UVA 10254 十八 The Priest Mathematician

    The Priest Mathematician Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu ...

  2. left join 等连接查询遇到同名字段覆盖问题

    可以在查询时给字段赋别名,但是需要注意以下:*的位置要在最前面,放在其他地方都会出错.这种写法同名覆盖的字段还在,然后在*的后面加上别名字段,已经可以满足所有需求了 SELECT *,r.id as ...

  3. V-rep学习笔记:转动关节1

    V-REP(Virtual Robot Experimentation Platform),是全球领先的机器人及模拟自动化软件平台.V-REP让使用者可以模拟整个机器人系统或其子系统(如感测器或机械结 ...

  4. Timeout expired超时时间已到. 达到了最大池大小 错误及Max Pool Size设置

    此文章非原创,仅为分享.学习!!! 参考数据库链接串: <add key="data" value="server=192.168.1.123; port=3306 ...

  5. CUBRID学习笔记 21 查看主键外键索引

    命令 show create table game; game是表名 在web管理中,请在sql标签中查,不要在query中执行. show create table game; === <Re ...

  6. sqlserver2008创建数据库 报 Cannot read property is filestream 此属性不可用于sql server 7.0 解决

    在创建数据库的时候,报整个错误 Cannot read property is filestream 此属性不可用于sql server 7.0 按照网上的方法  (http://blog.csdn. ...

  7. POJ 3461 Oulipo(乌力波)

    POJ 3461 Oulipo(乌力波) Time Limit: 1000MS   Memory Limit: 65536K [Description] [题目描述] The French autho ...

  8. domion Designer 管理员ID过期

    上班没几天,刚接触lotus domion 有一个服务器上打开相应的数据库提示 你的证书已经过期,网上找到的解决方案: ---------------------------------------- ...

  9. 自定义表单input

    我想实现下面这个效果?应该怎么写最方便呢?最有效,兼容性最好呢 我使用<p>标签套lable,加input的组合,p标签绝对定位,input标签铺满,用padding填充. 主要css . ...

  10. 利用[后台]->[类别管理]为文章前后台添加类别名称【转】

    原网址:http://blog.csdn.net/yanhui_wei/article/details/7943176 1.给专题添加文章时,可以选择类别: 2.给文章模型.图片模型.下载模型的栏目下 ...