python selenium-5根据unittest组织测试用例
* driver:浏览器driver存放地址
* testcase:测试用例目录
* report:测试结果保存目录
* runtest.py:执行文件
test_search1.py搜索selenium,test_search2搜索jenkins
```#python
import unittest,sys
from selenium import webdriver
from time import sleep
class TestBaidu(unittest.TestCase):
def setUp(self):
driver_path='/'.join(sys.path[0].split('/')[:-2])+"/driver/chromedriver"
self.driver=webdriver.Chrome(executable_path=driver_path)
self.driver.implicitly_wait(30)
self.base_url="http://www.baidu.com"
def test(self):
driver=self.driver
driver.get(self.base_url+"/")
driver.find_element_by_xpath("//input[@id='kw' and @class='s_ipt']").clear()
driver.find_element_by_xpath("//input[@id='kw' and @class='s_ipt']").send_keys("selenium")
driver.find_element_by_xpath("//input[@value='百度一下' and @id='su']").click()
result_text = driver.find_element_by_xpath("//span[@class='nums_text']").text
assert "百度为您找到相关结果约" in result_text
sleep(3)
def tearDown(self):
self.driver.quit()
if __name__=="__main__":
unittest.main()
```
runtest.py
```#python
import unittest
test_dir="./testcase/testsearch"
discover=unittest.defaultTestLoader.discover(test_dir,pattern="test*.py")
if __name__=="__main__":
runner=unittest.TextTestRunner()
runner.run(discover)
```
log.txt