码迷,mamicode.com
首页 > 其他好文 > 详细

selenium笔记6

时间:2016-05-20 01:00:53      阅读:267      评论:0      收藏:0      [点我收藏+]

标签:

#!/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笔记6

标签:

原文地址:http://www.cnblogs.com/kuihua/p/5510694.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!