【问题标题】:Django with lettuce and splinter, opens the browser but doesn't show anything带有生菜和碎片的 Django,打开浏览器但不显示任何内容
【发布时间】:2011-09-14 10:02:15
【问题描述】:

我正在尝试生菜的碎片。我有一个配置良好的 django 应用程序,没有问题。当我尝试运行生菜时,使用“应该”访问浏览器中的 url 的步骤,它不会返回任何错误,但不会显示页面。

这是我的 .feature 文件:

Feature: A test 
Scenario: User enters email, ajax will check if it exists
    When I go to the "/home/login/" URL 
    Then I fill in "#id_email" with "abc@def.gih"

这是我的步骤.py

from lettuce import *
from lettuce.django import django_url
from lxml import html
from django.test.client import Client
from nose.tools import assert_equals
from splinter.browser import Browser
from django.test.utils import setup_test_environment, teardown_test_environment
from django.core.management import call_command
from django.db import connection
from django.conf import settings

@before.all
def set_browser():
    setup_test_environment()
    world.browser = Browser('firefox')

@step(u'I go to the "(.*)" URL')
def i_go_to_the_url(step, url):
    world.response = world.browser.visit(django_url(url))

@step(u'I fill in "(.*)" with "(.*)"')
def i_fill_in(step, field, value):
    world.browser.fill(field, value)

它打开浏览器,浏览器没有显示任何内容,但测试成功,第二种情况失败并出现以下错误:

Feature: A test        # candidate/feature/index.feature:1

  Scenario: User enters email, ajax will check if it exists # candidate/feature/index.feature:3
    When I go to the "/home/login/" URL             # home/feature/index-steps.py:29
    Then I fill in "email" with "dsfdf@safsdfsd"       # home/feature/index-steps.py:39
    Traceback (most recent call last):
      File "/usr/local/lib/python2.6/dist-packages/lettuce/core.py", line 117, in __call__
        ret = self.function(self.step, *args, **kw)
      File "********/candidate/feature/index-steps.py", line 40, in i_fill_in
        world.browser.fill(field, value)
      File "/usr/local/lib/python2.6/dist-packages/splinter/driver/webdriver/__init__.py", line 240, in fill
        field.value = value
      File "/usr/local/lib/python2.6/dist-packages/splinter/driver/webdriver/__init__.py", line 306, in _set_value
        self._element.clear()
    AttributeError: 'NoneType' object has no attribute 'clear'

1 feature (0 passed)
1 scenario (0 passed)
2 steps (1 failed, 1 passed)
(finished within 15 seconds)

请任何人都可以帮助我吗?

【问题讨论】:

    标签: python django lettuce


    【解决方案1】:

    你解释的不多,但不妨试试下面的

        world.browser.find_by_id(field).fill(value)
    

    【讨论】:

    • 如果它帮助别人,你传入一个ID,所以你需要find_by_id。如果你想使用你原来的填充方法,你需要传入字段名。
    【解决方案2】:

    我也遇到过同样的问题。写:

    When I go to the "http://0.0.0.0:8000/home/login/" URL
    

    安装

    When I go to the "/home/login/" URL
    

    一切都会好起来的!

    【讨论】:

    • django_url(...) 正在这样做 - 你不应该硬编码完整的 url,以防测试服务器在不同的端口上启动
    猜你喜欢
    • 2013-07-24
    • 2017-02-07
    • 2016-02-23
    • 2014-10-29
    • 2018-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-19
    相关资源
    最近更新 更多