【发布时间】:2016-05-22 17:58:57
【问题描述】:
Django 1.9。我想测试输入表单是否正常不可见。只有当用户按下切换菜单按钮时,才会出现登录和密码输入元素。
问题是这都是关于类的方法的。我想确保一种方法先于另一种方法执行。我发现这个解决方案在方法名称中包含 0 和 1。
class FuncTestTablets(TestCase):
@classmethod
def setUpClass(cls):
pass
@classmethod
def tearDownClass(cls):
pass
def test_0_tablets_login_input_form_absent(self):
# At home page with tablet screen size Edith sees no login input element.
## 0 is for stating explicitly that this test goes before the ones with 1 in their name.
self.browser.get('http://localhost:8000')
login_input = self.browser.find_element_by_id('login')
self.assertFalse(login_input.is_displayed(), "Login input element is visible on large devices")
def test_1_tablets_login_input_form_present_when_menu_button_pressed(self):
# At home page Edith presses menu button and login input appears.
## 1 is for stating explicitly that this test goes after the ones with 0 in their name.
menu_button = self.browser.find_element_by_class_name('navbar-toggle')
menu_button.click()
login_input = self.browser.find_element_by_id('login')
self.assertTrue(login_input.is_displayed(), "Login input element is not visible on tablet devices when menu button is pressed.")
这似乎有效。你能告诉我这种情况下是否有一些众所周知的方法。也许是一些最佳实践。
我刚刚开始使用 Django,但我认为我的解决方案并不是最好的。
这就是我决定问你的原因。提前谢谢你。
【问题讨论】:
标签: django-testing