django运行硒测试

时间:2012-09-03 06:39:10

标签: django selenium

使用单独的django命令运行selenium测试时遇到问题。默认的“test”命令查看“tests”文件夹并运行unittests确定。问题是,我想制作文件夹“seleniumtests”并放置测试文件以使用命令“test_selenium”运行它们。我希望这个命令和默认的django“test”一样,但是在另一个目录中 带有硒的tests.py:

from django_liveserver.testcases import LiveServerTestCase
from selenium.webdriver.firefox.webdriver import WebDriver


class MySeleniumTests(LiveServerTestCase):
#    fixtures = ['test-data.json']

@classmethod
def setUpClass(cls):
    cls.selenium = WebDriver()
    super(MySeleniumTests, cls).setUpClass()

@classmethod
def tearDownClass(cls):
    super(MySeleniumTests, cls).tearDownClass()
    cls.selenium.quit()

def test_admin(self):
    self.selenium.get(self.live_server_url +'/admin/')
    self.assertIn("Django", self.selenium.title)

1 个答案:

答案 0 :(得分:1)

按照本教程,了解如何将测试放入文件夹:http://www.pioverpi.net/2010/03/10/organizing-django-tests-into-folders/

一般来说:

from [Project Name].[App Name].tests.[filename] import *  
from [Project Name].[App Name].seleniumtests.[selenium] import *  

#starts the test suite  
__test__= {  
           'your_django_tests': [filename],
            'selenium': [selenium],
           }