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

Remove Form and form_for() #87

Open
dtognazzini opened this issue Oct 6, 2014 · 0 comments
Open

Remove Form and form_for() #87

dtognazzini opened this issue Oct 6, 2014 · 0 comments

Comments

@dtognazzini
Copy link
Contributor

AePageObjects::Form and the DSL method form_for() are used like so:

form_for :login do
  element :email
  element :password
end

This is similar to using the element DSL method, like so:

element :login do
  element :email
  element :password
end

_The Differences_

Form vs Element
Form does not have a default_locator. When accessing a form instance, the underlying node is the same as the parent's node. This means there doesn't need to be a <form> element on the page at all.

form_for() vs element()
form_for is the same as element except:

  • it does not accept an :is option.
  • it creates delegated accessors on the parent Element for the elements defined on the Form. For example, in the usage above, the following is supported:
# access email explicitly through the form
some_page.login.email

# access email through the delegated accessor
some_page.email

Usually in these cases, the user is not interested in representing a form element in the page object. That's to say that either the user wants elements to be nested under an explicit element (like the login element defined above) or the user wants the elements to be defined on the parent element and using form_for to leverage the structural nesting to get the right default locator for the contained elements.

For example, using Rails, consider the case that the input fields to the login form are named "user[email]" and "user[password]". To achieve this, the user needs to specify "user" as the name of the form element via:

form_for :login, name: "user" do
  element :email
  element :password
end

or:

form_for :user do
  element :email
  element :password
end

The user doesn't care about representing the underlying form element through the page object interface, she is just using form_for to manipulate the name used by the default locator for the nested elements.

_The Proposal_
The features intertwined within Form and form_for should be generally and independently available for the definition of any element.

Non-scoped elements
#88

Enhance element DSL an option to reflect accessors
The element DSL should support an option to create delegates on the parent element to the elements of the element being defined.

Perhaps:

element :login, reflect_elements: true do
  element :email
  element :password
end

Provide mechanism for manipulating default locator
#89

_Deprecation_
Form and form_for could be implemented with the above features.

Exact equivalent:

element :login, name: "user", reflect_elements: true, locator: :parent do
  element :email
  element :password
end

Don't represent form on parent element:

with_name "user" do
  element :email
  element :password
end

Represent form on parent element:

element :login, name: "user",  locator: :parent do
  element :email
  element :password
end
@dtognazzini dtognazzini added this to the 2.0 milestone Oct 6, 2014
@dtognazzini dtognazzini removed this from the 2.0 milestone May 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant