我将django 1.3与Django liveserver一起使用,支持1.3。当我从Django LiverserverTestCase文档编写教程时,它工作得很好,但是却使用了django 1.3的导入。它测试"/ admin /"页面,并且没有问题,但是当我尝试测试我的urls时,即使只是“/,它也会转到admin!为什么?我没有在谷歌找到任何线索,也许这个问题只是一个。
也许我忽略了服务器的一些设置。但是localhost:8000/test在runserver命令之后可以正常工作。
如果有人有这类问题的话。
from django_liveserver.testcases import LiveServerTestCase
from selenium.webdriver.firefox.webdriver import WebDriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium import webdriver
class MySeleniumTests(LiveServerTestCase):
fixtures = ['nstein/test-users.json']
@classmethod
def setUpClass(cls):
cls.selenium = WebDriver()
cls.selenium.implicitly_wait(3)
super(MySeleniumTests, cls).setUpClass()
@classmethod
def tearDownClass(cls):
super(MySeleniumTests, cls).tearDownClass()
cls.selenium.quit()
def test_login(self):
self.selenium.get('%s%s' % (self.live_server_url. '/admin/'))
body = self.selenium.find_element_by_tag_name('body')
self.assertIn('Username', body.text)
username_input = self.selenium.find_element_by_id("id_username")
password_input = self.selenium.find_element_by_id("id_password")
password_input.send_keys('123')
username_input.send_keys('admin')
password_input.clear()
self.selenium.find_element_by_xpath('//input[@value="Log in"]').click()
body = self.selenium.find_element_by_tag_name('body')
self.assertIn('Site administration', body.text)
# url is in the urls.py of the app,
#selenium gets response 302 but redirects to /admin/
self.selenium.get('%s%s' % (self.live_server_url. '/test/')) 应用程序的urls.py:
#from cms import sitemaps
from django.conf.urls.defaults import *
from django.conf import settings
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from hitcount.views import update_hit_count_ajax
from django.views.generic.simple import direct_to_template
import dselector
from wcms.furniture_today.views import *
parser = dselector.Parser()
urlpatterns = patterns('',
parser.url(r'^test/$', direct_to_template, {'template': 'index.html'}, 'index'),
)全球网址:
from django.conf.urls.defaults import *
from django.conf import settings
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from wcms.business.views import wcms_admin_redirect
urlpatterns = patterns('',
(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
url(r'^', include('wcms.admin_urls')),
url(r'^', wcms_admin_redirect),
url(r'^', include('cms.urls')),
)
if settings.DEBUG: # assuming dev server
urlpatterns += patterns('', (r'^' + settings.MEDIA_URL.lstrip('/'), include('appmedia.urls')))
urlpatterns += staticfiles_urlpatterns()发布于 2012-09-04 17:36:33
尝试将self.selenium.get('%s%s' % (self.live_server_url. '/test/'))放入一个新函数中
def test_two(self):
self.selenium.get('%s%s' % (self.live_server_url. '/test/')) https://stackoverflow.com/questions/12259615
复制相似问题