TA的每日心情 | 擦汗 2016-6-29 09:56 |
---|
签到天数: 25 天 连续签到: 1 天 [LV.4]测试营长
|
这是源码:
# coding=utf-8
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
import unittest,time,re
import HTMLTestRunner
class Baidu(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(40)
self.base_url = "http://www.baidu.com/"
self.verificationErrors = []
self.accept_next_alert = True
#百度搜索用例
def test_baidu_search(self):
driver = self.driver
driver.get(self.base_url + '/')
driver.find_element_by_id("kw").send_keys("selenium")
driver.find_element_by_id("su").click()
time.sleep(2)
driver.close()
#白度设置用例
def test_baidu_set(self):
driver = self.driver
driver.get(self.base_url + '/gaoji/preferences.html')
m = driver.find_element_by_name("NR")
m.click()
#time.sleep(2)
t = m.find_element_by_xpath("/html/body/form/table/tbody/tr[3]/td[2]/select/option[3]")
#time.sleep(2)
t.click()
#time.sleep(2)
driver.find_element_by_id("save").click()
#time.sleep(2)
driver.switch_to_alert().accept()
def tearDown(self):
self.driver.quit()
self.assertEqual([],self.verificationErrors)
if __name__ == "__main__":
testunit = unittest.TestSuite()
#testunit.addTest(Baidu("test_baidu_search"))
testunit.addTest(Baidu("test_baidu_set"))
filename = "result.html"
fp = file(filename,'wb')
runner = HTMLTestRunner.HTMLTestRunner(
stream=fp,
title = u"百度搜索测试报告",
description = u'用例执行情况:'
)
runner.run(testunit)
|
|