Pylons / webtest

Wraps any WSGI application and makes it easy to send test requests to that application, without starting up an HTTP server.
https://docs.pylonsproject.org/projects/webtest/en/latest/
Other
336 stars 110 forks source link

HTML5 form support #8

Open domenkozar opened 12 years ago

domenkozar commented 12 years ago

Anonymous:

HTML5 adds a new attribute to input tags, named "form":
( see http://dev.w3.org/html5/spec/single-page.html#form-associated-element ).
If an input has a "form" attribute, webtest breaks when one
accesses response.forms:

TypeError: init() got multiple values for keyword argument 'form'

(this is on line 1563 of app.py in webtest 1.4.0)

The problem is actually on line 1206, which includes a positional arg called
'form'. An attribute named 'form' will now be passed in attrs, causing the
conflict.

def init(self, form, tag, name, pos, value=None, id=None, attrs):

Iwan Vosloo:

I guess supporting form-associated elements is actually a slightly bigger issue
than that conflicting kwarg... WebTest would have to make sure it collects all
the inputs of a particular form - including those that are associated with the
form but located elsewhere.

URL: https://bitbucket.org/ianb/webtest/issue/45/html5-form-associated-inputs-break-webtest

gawel commented 11 years ago

There is no library to do such things so we will wait until one appears. If we want to add that by ourself it will need to much code to maintain. We don't want that.

wichert commented 11 years ago

I"m not convinced any such library will appear by itself since this type of problem seems to be very specific to WebTest-like usage, so WebTest would be the logical source of such a library.

IwanVosloo commented 4 years ago

We've run into this again... and I had a quick look at the code of forms.Form._parse_fields. There's a line for pos, node in enumerate(self.html.findAll(tags)): which searches for elements that are ancestors of the Form, ie, the assumption is made that all form inputs will be descendants of the Form.

I gather that all webtest's elements are elements that originate from the response object passed to them. If that's the case, can't this issue be dealt with by simply doing a self.response.html.findAll(tags) and then ALSO filtering for tags that are either descendants of the form or have a form= attribute matching the Form's ID?

Somehow this does not seem like a huge stretch (provided I understand the code correctly)?

septatrix commented 3 years ago

A first step beside the form attribute would be to support formaction and formmethod when calling click on a button. This would already cover use cases like #175