添加django-bower后,Django测试CI失败

时间:2015-03-09 05:59:44

标签: django selenium continuous-integration bower

我有一个Django项目,我有一些前端依赖项,所以我尝试添加django-bower来帮助我管理它们。

我用bower版本替换了以前的依赖项,一切似乎都运行正常。我正在用Selenium运行我的测试,当我在本地运行它们时,它们正在通过。

但是,当我继续在CI服务器上进行测试时,Selenium测试失败,并显示一条错误消息,指出它无法在页面上找到元素。这是一个表单元素,我相信它就在那里。

我试图弄清楚为什么测试在本地传递但在CI服务器上失败。在添加django-bower之前,所有测试都在CI服务器中传递。

以下是Django设置中相关部分的片段

STATICFILES_FINDERS = (
    "django.contrib.staticfiles.finders.FileSystemFinder",
    "django.contrib.staticfiles.finders.AppDirectoriesFinder",
    # Compressor finder
    "compressor.finders.CompressorFinder",
    # Django bower finder
    "djangobower.finders.BowerFinder",
    )

STATIC_URL = '/static/'

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)

MEDIA_ROOT = os.path.join(BASE_DIR, 'uploads')

MEDIA_URL = '/uploads/'

BOWER_COMPONENTS_ROOT = os.path.join(BASE_DIR, 'static', 'js')

BOWER_INSTALLED_APPS = (
    'fontawesome#4.3.0',
    'jquery-validation#1.13.1',
    'magnific-popup#1.0.0',
    'masonry#3.2.2',
    'materialize#0.95.3',
)

bower组件安装在static/js/bower_components

CI服务器上提供的错误消息是

NoSuchElementException: Message: {"errorMessage":"Unable to find element with id 'message-form'","request":{"headers":{"Accept":"application/json","Accept-Encoding":"identity","Connection":"close","Content-Length":"93","Content-Type":"application/json;charset=UTF-8","Host":"127.0.0.1:60555","User-Agent":"Python-urllib/2.7"},"httpVersion":"1.1","method":"POST","post":"{\"using\": \"id\", \"sessionId\": \"bb17c920-c5dd-11e4-9c9b-e7fbd91dc2da\", \"value\": \"message-form\"}","url":"/element","urlParsed":{"anchor":"","query":"","file":"element","directory":"/","path":"/element","relative":"/element","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/element","queryKey":{},"chunks":["element"]},"urlOriginal":"/session/bb17c920-c5dd-11e4-9c9b-e7fbd91dc2da/element"}}

真的很感激任何帮助。我用Google搜索了我能想到的一切,似乎无法找到解决方案。

2 个答案:

答案 0 :(得分:1)

这仍然是猜测,但我通过调整测试并添加Explicit Wait来解决这些问题。而不只是:

form = driver.find_element_by_id('message-form')

使用:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

form = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "message-form")))

基本上,您正在等待元素在页面上出现10秒,每500毫秒检查一次。如果元素在10秒内不会出现,则会抛出TimeoutException

答案 1 :(得分:0)

我使用Bower和Django项目,但我没有使用django-bower。我单独使用它(通过bower install),让它在static / bower-components中存储前端deps,并在带有{% static %}模板标记的模板中引用该路径。不知道这样做是否会影响你的奇怪测试结果,但值得一试。