#test_baidu.py
from selenium import webdriver
from time import sleep
import unittest
class TestBaidu(unittest.TestCase):
def setUp(self):
self.driver=webdriver.Firefox()
self.driver.implicitly_wait(30)
self.driver.get("https://www.baidu.com/")
def test_bai(self):
driver=self.driver
driver.find_element_by_id("kw").clear()
driver.find_element_by_id("kw").send_keys("selenium")
driver.find_element_by_id("su").click()
sleep(3)
title=driver.title
self.assertEqual(title,"selenium_百度搜索")
driver.find_element_by_partial_link_text("selenium自动化").click()
sleep(3)
def tearDown(self):
self.driver.quit()
if __name__=="__main__":
unittest.main()
runtest.py
import unittest
test_dir = "./"
deriver = unittest.defaultTestLoader.discover(test_dir,pattern="tset*.py")
if __name__=="__main__":
runner = unittest.TextTestRunner()
runner.run(deriver)
测试结果
Ran 0 tests in 0.000s
OK
本以为电脑问题,更换电脑安装软件后相同代码,结果还是这个,不知问题出在哪里,求解决