jac*_*007 4 python testing firefox selenium
我在python中有以下代码
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from unittestzero import Assert
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import ElementNotVisibleException
import unittest, time, re
class HomePageTest(unittest.TestCase):
expected_title=" some title here "
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "https://somewebsite.com"
self.verificationErrors = []
def test_home_page(self):
driver=self.driver
driver.get(self.base_url)
print "test some things here"
def test_whatever(self):
print "test some more things here"
def tearDown(self):
self.driver.quit()
if __name__ == "__main__":
unittest.main()
Run Code Online (Sandbox Code Playgroud)
我的问题是在函数test_home_page之后,firefox实例关闭并再次为下一个test_whatever函数打开.我怎么能这样做所有测试用例都是从同一个firefox实例执行的.
通常,您希望浏览器在测试之间关闭,以便您使用干净缓存,localStorage,历史数据库等启动每个测试.在测试之间关闭浏览器确实会减慢测试速度,但它会节省调试时间,因为测试不会与浏览器缓存和先前测试的历史记录交互.
初始化 Firefox 驱动程序__init__:
class HomePageTest(unittest.TestCase):
def __init__(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "https://somewebsite.com"
self.verificationErrors = []
...
def tearDown(self):
self.driver.quit()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8342 次 |
| 最近记录: |