use*_*987 13 python sockets selenium
import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
class PythonOrgSearch(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
def test_search_in_python_org(self):
driver = self.driver
driver.get("http://www.python.org")
self.assertIn("Python", driver.title)
elem = driver.find_element_by_name("q")
elem.send_keys("selenium")
elem.send_keys(Keys.RETURN)
self.assertIn("Google", driver.title)
def tearDown(self):
self.driver.close()
if __name__=="__main__":
unittest.main()
Run Code Online (Sandbox Code Playgroud)
嗨,大家得到这个警告,帮助我知道什么是错的
警告(来自警告模块):文件"C:\ Python33\lib\site-packages\selenium-2.37.2-py3.3.egg\selenium\webdriver\firefox\firefox_binary.py",第95行,而不是utils.is_connectable (self.profile.port):ResourceWarning:unclosed
hwj*_*wjp 20
这是一个已知的错误:
http://code.google.com/p/selenium/issues/detail?id=5923
尽管如此,忽略它是安全的.如果您使用的是Python 3,则可以:
unittest.main(warnings='ignore')
Run Code Online (Sandbox Code Playgroud)
在Python 2中,您将使用以下内容:
with warnings.catch_warnings(record=True):
unittest.main()
Run Code Online (Sandbox Code Playgroud)
如果你能原谅无耻的自我推销,有一个在凌晨本书我已经写了,硒其它更多的信息在这里.
我用-W旗子运行我的测试:
python -W ignore -m unittest my_tests
Run Code Online (Sandbox Code Playgroud)
要么
python -W ignore -m unittest my_tests.MyIndividualTest
Run Code Online (Sandbox Code Playgroud)
这会抑制ResourceWarning但仍然允许断言错误报告.
顺便说一句,我发现:
if __name__ == '__main__':
unittest.main(warnings='ignore')
Run Code Online (Sandbox Code Playgroud)
python my_tests.py在每次运行测试时调用时都有效,但是此调用会阻止运行单个测试.
我无法弄清楚如何使用unittest.main(warnings='ignore')而不会遇到错误,我放下了递归包含unittest库.
(selenium==2.44.0下Python 3.4.2)
| 归档时间: |
|
| 查看次数: |
7039 次 |
| 最近记录: |