python selenium 多个测试用例

标签 python firefox testing 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()

我的问题是在函数 test_home_page 之后,firefox 实例关闭并为下一个 test_whatever 函数再次打开。我该怎么做才能让所有测试用例都从同一个 Firefox 实例执行。

最佳答案

通常您希望浏览器在测试之间关闭,以便您使用干净的缓存、localStorage、历史数据库等开始每个测试。在测试之间关闭浏览器确实会减慢测试速度,但它可以节省调试时间,因为测试不与先前测试的浏览器缓存和历史记录交互。

关于python selenium 多个测试用例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11049505/

相关文章:

python - pandas.DataFrame.merge 中的错误?

android - 为什么使用 cfx 在移动设备上测试我的 Firefox Addon 时没有调试输出?

javascript - 用 enzyme 和 Jest 测试 React : Invariant Violation: Target container is not a DOM element

testing - Robot Framework - 使用相对路径从不同的目录变体运行测试

testing - 将所有邮件保存到文件夹的 SMTP 服务器?

python - 为什么Python(3.7)不断覆盖 key :value pairs in my nested dictionary?

python - multiprocessing.Queue 的工作示例

python - 正则表达式:在复杂的正则表达式中平衡 "{}"(python)

google-app-engine - 有什么方法可以将 .appspot.com 列入白名单,以便我可以在 Firefox 6 中的该域上设置 cookie?

javascript - 菜单栏不显示在 window.open for Mozilla Firefox