带有生菜和碎片的 Django,打开浏览器但不显示任何内容

发布于 2024-12-04 15:25:36 字数 2379 浏览 1 评论 0原文

我正在尝试用碎片生菜。我有一个配置良好的 Django 应用程序,没有任何问题。当我尝试运行 Lettuce 时,按照“应该”访问浏览器中的 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 "[email protected]"

这是我的steps.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)

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

I am trying my hands on lettuce with splinter. I have a django app which is well configured, no issues with that. When i try running lettuce, with the step which "should" visit a url in the browser, it doesn't returns any error but it doesn't shows up the page.

Here is my .feature file :

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 "[email protected]"

here is my steps.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)

It opens the browser, the browser doesn't shows up anything but the test succeeds, and the second case fails with the following error :

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)

Please can anyone help me on this ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

瑕疵 2024-12-11 15:25:36

您没有解释太多,但也许可以尝试以下操作

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

you don't explain a lot, but maybe try the following

    world.browser.find_by_id(field).fill(value)
生来就爱笑 2024-12-11 15:25:36

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

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

安装了

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

,一切都会好起来的!

I have had this same problem. Write:

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

insted of

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

and everything will be fine!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文