pythonselenium多个测试用例

我在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实例执行。

回答:

在以下位置初始化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()

以上是 pythonselenium多个测试用例 的全部内容, 来源链接: utcz.com/qa/397663.html

回到顶部