Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InnerBrowser fillField throws exception if input does not have a name attribute #24

Open
janhenkgerritsen opened this issue May 26, 2016 · 3 comments

Comments

@janhenkgerritsen
Copy link
Contributor

This issue comes from the problem reported in Codeception/Codeception#1221. You will get an exception with the text InvalidArgumentException: Malformed field path "" if you call fillField for a form field without a name attribute or an empty name attribute.

This comes from the fact that the call to matchFormField at https://github.com/Codeception/Codeception/blob/2.1/src/Codeception/Lib/InnerBrowser.php#L789 uses the value of the name attribute to access the fields in a \Symfony\Component\DomCrawler\Form object.

However, this Form object will not store form fields that do not have a value for their name attribute, see this line of code: https://github.com/symfony/dom-crawler/blob/master/Form.php#L452.

I don't see an easy workaround for this problem, but maybe someone else does, maybe @Naktibalda or @DavertMik? I am not really familiar with this part of the Codeception codebase :)

@Naktibalda
Copy link
Member

I don't see a point of filling a nameless input field in a client which does not support javascript.
It can't be submitted by submitForm.

@Naktibalda
Copy link
Member

How about throwing exception with clearer message?

if (empty($name)) {
    throw new Exception("Can't fill a field because it has no name attribute");
}

@janhenkgerritsen
Copy link
Contributor Author

An exception with a better error message is a good idea, at least that way users have an idea of what goes wrong.

I also agree with you that there is no point in filling a nameless input field in functional tests. If that poses a problem in your tests you are probably trying to do something you should not do and for which there are better alternatives.

@Naktibalda Naktibalda transferred this issue from Codeception/Codeception Jan 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants