lettuce
Cucumber-ish BDD for python
nutshell — Lettuce 0.2.20 (kryptonite release) documentation
I have a template in which I placed, let's say 5 forms, but all disabled to be posted except for the first one. The next form can only be filled if I click a button that enables it first.
I'm looking for a way to implement a Django-like forloop.last templatetag variable in a for loop inside an acceptance test to decide whether to execute a method that enables the next form or not.
Basically what I need to do is something like:
for form_data in step.hashes:
# get and fill the current form with data in form_data
if not forloop.last:
# click the button that enables the next form
# submit all filled forms
Source: (StackOverflow)
Can someone with experience using both Lettuce and Pyccuracy describe their differences both in terms of features and uses?
From the Lettuce Overview documentation:
Lettuce is a very simple BDD tool based on Cucumber, which currently has many more features than Lettuce.
Lettuce aims the most common tasks on BDD and it focus specially on those that make BDD so fun :)
Provide to the developers the ability of describing features in a natural language, by creating one or more scenarios.
From the Pyccuracy github page:
Pyccuracy is a Behaviour-Driven-Development-style tool written in Python that aims to make it easier to write automated acceptance tests. It improves the readability of those tests by using a structured natural language – and a simple mechanism to extend this language – so that both developers and customers can collaborate and understand what the tests do.
Source: (StackOverflow)
What does redis.publish();
method do in the following module.
redis.publish("WordCountTopology", exclamatedWord.toString() + "|" + Long.toString(count));
public void execute(Tuple tuple)
{
String word = tuple.getString(0);
StringBuilder exclamatedWord = new StringBuilder();
exclamatedWord.append(word).append("!!!");
_collector.emit(tuple, new Values(exclamatedWord.toString()));
long count = 30;
redis.publish("WordCountTopology", exclamatedWord.toString() + "|" + Long.toString(count));
}
Source: (StackOverflow)
how to specify which lettuce scenario to run?
in using python lettuce test framework, I ran frequently into this case, one scenario failed and then I want to zoom in to this scenario to fix this scenario
can we specify which lettuce scenario to run in the feature file ?
Source: (StackOverflow)
Just tried integrating Lettuce into my django installation and getting the following error:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/var/www/abc/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/var/www/abc/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/var/www/abc/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 272, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/var/www/abc/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 75, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/var/www/abc/local/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/var/www/abc/local/lib/python2.7/site-packages/lettuce/django/__init__.py", line 19, in <module>
from lettuce.django.server import Server
File "/var/www/abc/local/lib/python2.7/site-packages/lettuce/django/server.py", line 33, in <module>
from django.core.servers.basehttp import WSGIServerException
ImportError: cannot import name WSGIServerException
I heard that WSGIServerException was removed from django, so how do I get around this?
Source: (StackOverflow)
I have a Django-based web application that is required to send a confirmation email to the user on an attempt to change the registered email address. The functionality has been implemented, but the lettuce test intended to verify the contents of the email is failing.
To verify the operation, my plan was to use the file backend (EMAIL_BACKEND = 'django.core.mail.backends.filebased.EmailBackend') then verify the contents of the file within my lettuce step.
When running "normally" (e.g. via manage.py runserver), the email file is created as expected. When run via lettuce (manage.py harvest), the web site appears to be getting driven correctly (I'm using Selenium to drive it) but no email file is generated.
What have I missed? Is there some setting (e.g. in the terrain.py file) I need to use so the file backend is also used during the test process?
Source: (StackOverflow)
I am trying to add Lettuce to an existing Django project. With a very simple features directory configured I keep getting django.contrib.admin.sites.AlreadyRegistered
: The model Family is already registered. I checked for differing imports (e.g. import .models
vs import reg.models
), duplicate imports, and errant applications that might be re-importing my admin.py to no avail. The error seems to be coming from lettuce trying to reload a module. I'm not sure why it would want to do that. Traceback is below.
(dwcoop)s001 cro-mbp[126]% DJANGO_SETTINGS_MODULE=settings.testing django-admin.py harvest reg
Creating test database for alias 'default'...
Django's builtin server is running at 0.0.0.0:8000
Traceback (most recent call last):
File "/Users/cro/src/ve/dwcoop/lib/python2.7/site- packages/lettuce/django/management/commands/harvest.py", line 167, in handle
result = runner.run()
File "/Users/cro/src/ve/dwcoop/lib/python2.7/site-packages/lettuce/__init__.py", line 137, in run
self.loader.find_and_load_step_definitions()
File "/Users/cro/src/ve/dwcoop/lib/python2.7/site-packages/lettuce/fs.py", line 60, in find_and_load_step_definitions
reload(module) # always take fresh meat :)
File "/Users/cro/src/ve/dwcoop/web/web/reg/admin.py", line 60, in <module>
admin.site.register(Family, FamilyAdmin)
File "/Users/cro/src/ve/dwcoop/lib/python2.7/site-packages/django/contrib/admin/sites.py", line 83, in register
raise AlreadyRegistered('The model %s is already registered' % model.__name__)
AlreadyRegistered: The model Family is already registered
Destroying test database for alias 'default'...
Source: (StackOverflow)
I have about 130 lettuce tests which runs fine locally, but when travis runs them it hangs after a few tests.
Here the tests fails at the 8th scenario: https://travis-ci.org/h3/django-editlive/jobs/3945466
And when I remove the last scenario it passes: https://travis-ci.org/h3/django-editlive/builds/3945648
I tried splitting my tests in separate features files, same problem.
It's doesn't seem to be caused by a specific scenario, but rather by the number of scenario ran.
According to Travis' docs:
- Waiting for keyboard input or other kind of human interaction
- Concurrency issues (deadlocks, livelocks and so on)
- Installation of native extensions that take very long time to compile
The only possibility I could see is a concurrency issue .. but how can I debug it ?
My project is open source so the entire source code is available here:
Source: (StackOverflow)
I'm following the Django Tutorial for Django v1.6, and running it inside eclipse with PyDev. I got to the page on testing and I thought I'd mix it up (read: Run before I can walk) and learn Lettuce as well.
From what I've read online lettuce should be bundled with PyDev by default. which makes sense as the line from lettuce import *
does not error in my steps.py, but the rest of the code does:
from lettuce import *
@step('Given my poll is (\d+) days in the future')
def have_future_poll(step, number):
world.number = int(number)
The error for the @step
is:
Undefined variable: step
step Found at: polls.tests.features.steps
step
And for world is:
Undefined variable: world
So I don't think it's importing properly.
How should I use Lettuce in eclipse?
Source: (StackOverflow)
All I want is to close a modal dialog, ideally by doing the following:
browser.find_element_by_link_text("OK").click()
Gives NoSuchElementException: Message: u'The element could not be found'
for the OK link text.
Same for the xpath when I do this:
browser.find_element_by_xpath("//*[@id=\"modal\"]/div/div[2]/div/a").click()
I suspect this is because I need to put focus on the dialog. To do so I've tried:
for handle in browser.window_handles:
browser.switch_to_window(handle)
if browser.find_element_by_class_name('popUp123')
browser.find_element_by_link_text("OK").click()
Gives NoSuchElementException: Message: u'The element could not be found'
for the class.
Have also tried browser.switch_to_frame(ID OR NAME)
, but couldn't find it as a frame either.
Please tell me I'm missing something blatantly obvious.
Relevant frame source (summarised):
<body id="modal">
<div class="popUp123">
<div class="button">
<div class="centerbutton">
<a rel='nofollow' href="#" class="close" onclick=parent.close">
<span>OK</span>
Source: (StackOverflow)
I'm trying to test that logged in users can log out on my Django site with Lettuce, Selenium and lettuce_webdriver.
In my terrain.py I have:
@before.all
def setup_browser():
profile = webdriver.FirefoxProfile()
profile.set_preference('network.dns.disableIPv6', True)
world.browser = webdriver.Firefox(profile)
world.client = Client(HTTP_USER_AGENT='Mozilla/5.0')
And then when I 'login':
@step(r'I am logged in as "(\w*)"')
def log_in(step, name):
world.client.login(username=name, password=name)
And I go to my site:
And I go to "localhost:8000"
I find a link called "Logout ?" that goes to "/logout"
@step(r'I find a link called "(.*?)" that goes to "(.*?)"$')
def find_link(step, link_name, link_url):
print(world.browser.page_source)
elem = world.browser.find_element_by_xpath(r'//a[@rel='nofollow' href="%s"]' % link_url)
eq_(elem.text, link_name)
But my page_source shows I am not logged in. This kind of makes sense...in that client
and browser
aren't talking to each other. But is this possible, or do I need to login 'manually' by clicking links with selenium etc?
I'd like to do this:
world.browser.page_source = world.client.get(world.browser.current_url).content
But page_source can't be changed. Can I feed Selenium from django's client some how?
Edit: Following Loius' advice below, my 'I am logged in as ...' step is as below. I added the if/else to just check my suspicions. My client is still setup as above (see setup_browser
step above)
@step(r'I am logged in as "(\w*)"')
def log_in(step, name):
world.client.login(username=name, password=name)
if world.client.cookies:
session_key = world.client.cookies["sessionid"].value
world.browser.add_cookie({'name':'sessionid', 'value':session_key})
world.browser.refresh()
else:
raise Exception("No Cookies!")
All the advice I've seen is to login first. Without my check, I get this:
Scenario: Logged in users can logout # \gantt_charts\features\index.feature:12
Given I am logged in as "elsepeth" # \gantt_charts\features\steps.py:25
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\lettuce\core.py", line 144, in __call__
ret = self.function(self.step, *args, **kw)
File "D:\Django_Projects\gAnttlr\gantt_charts\features\steps.py", line 27, in log_in
session_key = world.client.cookies["sessionid"].value
KeyError: 'sessionid'
Source: (StackOverflow)
I have simple feature:
Feature: Lol and other words
Scenario: Lol printing
Given I like print "lol"
Scenario Outline: Words printing
Given I like print "<word>"
Examples:
| word |
| lol |
| ala |
And implementation:
from lettuce import step
@step('I like print "([^"]+)"')
def step_impl(step, word):
print word
When PyCharm lettuce test runner execute feature its run first scenario without problems but second is never executed (however it knows that there is other scenario) - so it looks like:
How to run Scenario Outline
with this runner?
System:
Windows 8.1, PyCharm 4.0.1 139.556 EAP Professional, lettuce 0.2.20, Python27
Source: (StackOverflow)
How can i write backgrounds in lettuce tests(django), the background is run before each of scenarios,
in cucumber i can write backgrounds like that:
Feature: Multiple site support
As a Mephisto site owner
I want to host blogs for different people
In order to make gigantic piles of money
Background:
Given a global administrator named "Greg"
And a blog named "Greg's anti-tax rants"
And a customer named "Dr. Bill"
And a blog named "Expensive Therapy" owned by "Dr. Bill"
Scenario: Dr. Bill posts to his own blog
Given I am logged in as Dr. Bill
When I try to post to "Expensive Therapy"
Then I should see "Your article was published."
Scenario: Dr. Bill tries to post to somebody else's blog, and fails
Given I am logged in as Dr. Bill
When I try to post to "Greg's anti-tax rants"
Then I should see "Hey! That's not your blog!"
Source: (StackOverflow)
We have 2 fairly large automation projects going, both using BDD. One is in Lettuce for a desktop app, the other is for a website using JBehave (we are just getting started with the web project).
We have tried using Thucydides for reporting for our JBehave project, and started implementing tests using that. However, we ran into Allure and it looks a lot better and lets us use standard JBehave framework without relying on someone's code that has its own unknown-to-us issues. Luckily, we found Allure early enough.
2 questions:
1) We spent 2 days trying to make Allure work with JBehave, but the only example on GitHub isn't working well (all scenarios are reported together without breakdown by individual stories or scenarios). Also, JBehave doesn't have an @AfterStep decorator and it's a requirement for us to save screenshots after each step, successful or not. Thucydides for all its faults took care of that. Does Allure have something similar? If not, then at least is there a working example of how to make it report stories and scenarios correctly when run from JBehave?
2) I haven't tried yet, but doesn't look like there is an adapter for Lettuce (Python). Can someone recommend a way to produce Allure reports from Lettuce?
Thanks a lot!!
Source: (StackOverflow)
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 "abc@def.gih"
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 ?
Source: (StackOverflow)