selenium+python笔记4

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@desc:       使用unittest组织用例
"""
from selenium import webdriver
import unittest
import time


class TestSearch(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Firefox()
        self.driver.maximize_window()
        self.driver.implicitly_wait(10)
        self.base_url = "http://www.baidu.com"

    def test_baidu(self):
        driver = self.driver
        driver.get(self.base_url + "/")

        driver.find_element_by_id("kw").clear()
        driver.find_element_by_id("kw").send_keys("unittest")
        driver.find_element_by_id("su").click()

        time.sleep(2)
        title = driver.title
        self.assertEqual(title, u"unittest_百度搜索")

    def tearDown(self):
        self.driver.quit()


if __name__ == "__main__":
    unittest.main()

 

posted @ 2016-05-19 20:35  七月的尾巴_葵花  阅读(225)  评论(0编辑  收藏  举报