我喜欢在提交之前运行测试。
我对Selenium很陌生,不知道如何运行测试而不改变数据库。
我的本地数据库中有许多相同的发布问题。
是否有任何方法可以运行这些测试并且在tearDown时不需要将数据库恢复到原始状态?
我的本地数据库中有许多相同的发布问题。
是否有任何方法可以运行这些测试并且在tearDown时不需要将数据库恢复到原始状态?
from selenium import webdriver
from django.utils import unittest
from selenium.webdriver.support.ui import WebDriverWait
class TestAuthentication(unittest.TestCase):
scheme = 'http'
host = 'localhost'
port = '4444'
def setUp(self):
self._driver = webdriver.Firefox()
self._driver.implicitly_wait(5)
def login_as_Bryan(self):
self._driver.get('http://localhost:8000/account/signin/')
user = self._driver.find_element_by_id('id_username')
user.send_keys("Bryan")
password = self._driver.find_element_by_id('id_password')
password.send_keys('***************')
submit = self._driver.find_element_by_id('blogin')
submit.click()
def test_user_should_be_able_to_login_manually(self):
self.login_as_Bryan(self)
message = self._driver.find_element_by_class_name('darkred')
self.assertEqual("Welcome back Bryan, you are now logged in", message.text)
def test_Bryan_can_post_question(self):
self.login_as_Bryan()
self._driver.find_element_by_link_text("ask a question").click()
self._driver.find_element_by_id('id_title').send_keys("Question should succeed")
self._driver.find_element_by_id('editor').send_keys("This is the body text.")
self._driver.find_element_by_id('id_tags').send_keys("test")
self._driver.find_element_by_class_name("submit").click()
self.assertTrue(self._driver.find_element_by_link_text("Question should succeed"))
def tearDown(self):
self._driver.quit()