【发布时间】:2016-03-21 08:40:56
【问题描述】:
我这里有以下代码:
import unittest
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
class MyTest1(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.driver = webdriver.Firefox()
driver = cls.driver
driver.get("https://somewebsite.com")
print "login the website"
def test_UI_login(self):
driver = self.driver
print "test some things here"
def test_duplicate_client(self):
driver = self.driver
print "test some things here"
def tearDown(cls):
cls.driver.close()
if __name__ == '__main__':
unittest.main()
我面临的问题是, 在第一个函数 test_UI_login 之后,firefox 实例关闭。如何使用 selenium 在 unittest 中从同一个 Firefox 实例执行多个测试用例。
【问题讨论】:
-
如果你也用
@classmethod注释tearDown也许会有所帮助? -
如果我们用@classmethod注解tearDown是不行的