selenium 自动化测试之百度搜索(两种方法对比)
from selenium import webdriverimport unittest
class Baidu(unittest.TestCase):
def setUp(self):
self.browser = webdriver.Firefox()
self.base_url = "http://www.baidu.com"
self.browser.implicitly_wait(10)
def tearDown(self):
self.browser.close()
def test_o1(self):
d = self.browser
d.get(self.base_url)
d.find_element_by_id("kw").send_keys("seleniumhq")
d.find_element_by_id("su").click()
if __name__ =="__main__":
unittest.main()
from selenium import webdriver
import unittest
class Baidu(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.browser = webdriver.Firefox()
cls.base_url = "http://www.baidu.com"
cls.browser.implicitly_wait(10)
def test_01(cls):
d = cls.browser
d.get(cls.base_url)
d.find_element_by_id("kw").send_keys("seleniumhq")
d.find_element_by_id("su").click()
@classmethod
def tearDown(cls):
cls.browser.quit()
if __name__ == "__main__":
unittest.main()
赞一个 :D :lol :lol 赞 66666 对比有啥不同?
页:
[1]