在使用ddt和python的unittest时遇到了一个问题,我尝试使用Internet上的以前的教程,但是在再次重用代码后总是会再次出现错误。
import unittest
from selenium import webdriver
from ddt import ddt, data, unpack
@ddt
class BrowserCasedTestLogin(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome()
self.driver.maximize_window()
self.driver.get('https://www.testing.com')
self.driver.implicitly_wait(10)
@data(('testing@testing.com', 'testing'))
@unpack
def test_login_page(self, username, password):
self.driver.set_script_timeout(30)
self.assertEqual(self.driver.current_url, 'https://www.testing.com/')
self.driver.find_element_by_id('login__username').send_keys(username)
self.driver.find_element_by_id('login__password').send_keys(password)
self.driver.find_elements_by_xpath('/html/body/div/div/div/div[2]/div/form/div[4]/button')[0].click()
self.driver.implicitly_wait(30)
self.assertEqual(self.driver.current_url, 'https://www.testing.com/login')
错误:
AttributeError: type object 'ChromeBrowserCasedTestLogin' has no attribute 'test_login_page'