我正在尝试使用Lettuce从步骤定义中获取一些输出。当我运行测试时,我看到它会闪烁我的输出一秒钟,然后被同样的测试所显示的内容覆盖。但是我可以在输出中看到两次调用的步骤。一个是非常黑(几乎是黑色)着色,另一个是绿色或红色。输出在下面突出显示。
这让我很头疼,因为调试信息显示在正在运行的其他测试中,而不是这个。我很难说明这一点,但我认为屏幕截图有助于说明问题:我应该只看到每一步被调用一次,现在情况并非如此。
对此的任何帮助将不胜感激。
功能
Feature: Navigation
As a persion looking for information on specific machine
In order to view up to date machine inventory
I should be able to navigate to a individual machine
Background:
Given the following users exist:
| username | first_name | last_name | password |
| johndoe | John | Doe | testpass |
And the following machines exist:
| msnbr | machine_name | brand_name | brand_slug | division | product_group | machine_type | price | model | location |
| 111111 | Router | Altendorf | altendorf | All | All | All | 100 | model7 | Zenith |
| 222222 | CNC Router | Belfab | belfab | All | All | All | 200 | model6 | Echo |
| 333333 | Saw | Durst | durst | All | All | All | 300 | model5 | Xalpha |
| 444444 | Another Router | Belfab | belfab | All | All | All | 250 | model4 | Beta |
| 555555 | eh Router | Belfab | belfab | All | All | All | 250 | model4 | Water |
| 666666 | Router 6 | Belfab | belfab | All | All | All | 250 | model2 | River |
| 777777 | Router 8 | Belfab | belfab | All | All | All | 250 | model1 | Snake |
And I am logged in as "johndoe" with password "testpass"
Scenario: As an executive, I can see all brands
Given I see "Brand"
Then I should see "Altendorf"
And I should see "Belfab"
And I should see "Durst"
Then I click "Logout"
Scenario: As an executive, I can navigate into brands
Given I see "Brand"
When I click "Belfab"
Then I should see "5" machines
And the machines should be in the following order:
| model |
| model2 |
| model4 |
| model5 |
| model6 |
| model7 |
步骤(格式化为位)
from lettuce import step, world
from lettuce_webdriver.util import assert_true
from django.contrib.auth.models import User
from website.factories import *
from website.models import *
@step(u'the following machines exist:')
def the_following_machines_exist(step):
for machine_hash in step.hashes:
brand, created = Brand.objects.get_or_create(
name=machine_hash['brand_name'],
slug=machine_hash['brand_slug']
)
division, created = Division.objects.get_or_create(
name=machine_hash['division']
)
product_group, created = ProductGroup.objects.get_or_create(
name=machine_hash['product_group']
)
machine_type, created = MachineType.objects.get_or_create(
name=machine_hash['machine_type']
)
machine = Machine(
machine_year = "2000",
hold_for = "john",
us_destination = "el paso",
voltage = "500",
last_update_on = "January 10",
port_of_entry = "LAX",
msnbr = machine_hash['msnbr'],
description = "Machine description",
location=machine_hash['location'],
model=machine_hash['model'],
age=15,
price=machine_hash['price'],
active=True,
division=division,
product_group=product_group,
machine_type=machine_type,
brand=brand
)
machine.save()
@step(u'I should see "([^"]*)" machines')
def i_should_see_n_machines(step, n):
selector = "#left-main ol li"
elements = world.browser.find_elements_by_css_selector(selector)
if len(elements) != int(n):
raise Exception("Error: Number of machines does not match: %d != %d" % (len(elements), int(n)))
@step(u'the machines should be in the following order:')
def the_machines_should_be_in_the_following_order(step):
selector = "#left-main ol li"
elements = world.browser.find_elements_by_css_selector(selector)
for i in range(0, len(elements)):
el_text = elements[i].find_element_by_css_selector(".name").text
if step.hashes[i]['model'] != el_text:
print "FAIL"
else:
print el_text
print step.hashes[i]['model']
设置
# Django settings for stiles_aml project.
import os.path
root = os.path.dirname(__file__).replace('\\','/')
DEBUG = False
TEMPLATE_DEBUG = DEBUG
ADMINS = ( *** )
MANAGERS = ADMINS
DATABASES = { *** }
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# On Unix systems, a value of None will cause Django to use the same
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'America/Detroit'
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True
# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = root + '/../media/'
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = '/media/'
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = root + '/../static/'
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
root + "/../shared_static",
)
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
# Make this unique, and don't share it with anybody.
SECRET_KEY = '***'
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.request',
'django.core.context_processors.static',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
# 'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.gzip.GZipMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware',
)
ROOT_URLCONF = '***_aml.urls'
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = '***_aml.wsgi.application'
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
root + '/../templates'
)
# Sentry key
SENTRY_DSN = '****'
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',
'django.contrib.humanize',
# 3rd party
'south',
'debug_toolbar',
'tastypie',
'django_extensions',
'shell_plus',
'raven.contrib.django',
'django_nose',
'lettuce.django',
# Authored
'website',
)
# Email settings
EMAIL_HOST = '****'
REQUEST_QUOTE_EMAIL = ['****']