51Testing软件测试论坛
标题:
调试的时候好好的,运行的时候就不行了
[打印本页]
作者:
春来
时间:
2016-2-29 17:18
标题:
调试的时候好好的,运行的时候就不行了
这是源码:
# 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)
[attach]100185[/attach][attach]100186[/attach]
作者:
春来
时间:
2016-2-29 17:23
请大神们帮忙看看
作者:
prettyfool
时间:
2016-2-29 19:32
xpath用绝对路径不稳定,最好换成相对路径
作者:
春来
时间:
2016-3-2 09:19
prettyfool 发表于 2016-2-29 19:32
xpath用绝对路径不稳定,最好换成相对路径
谢谢啦
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2