FormObject`s now support YAML representation of the form and inputs to simplify the page object writing process.
Creating a new form object using the `new page --prototype form` command now creates a `.yml` file in addition to a Python module. Locators for the form and submit button are declared in the file, as well as representations of the inputs in that form including their name, type, and various other attributes.
For documentation on form object YAML syntax, see:
https://connordelacruz.com/webdriver-test-tools/yaml.html
Details
`pageobject.utils.yaml`:
* New module `pageobject.utils.yaml`, which contains methods and exceptions related to parsing YAML files
`pageobject.form`:
* Added `InputObject` class, which represents input elements and handles filling them/retrieving the current values
`FormObject`:
* Added `YAML_FILE` attribute, which is a path to the `.yml` file that should be parsed on `__init()`
* Added `inputs` attribute, which is a dictionary mapping input names to the corresponding `InputObject` instance. Gets populated at runtime after parsing `YAML_FILE`
* Added `parse_yaml()` method, which gets called in `__init__()` if `YAML_FILE` is set and sets `FORM_LOCATOR`, `SUBMIT_LOCATOR`, and `inputs` based on the parsed YAML
* Deprecated `fill_form()` method and `Input` nested class workflow
* Added `fill_inputs()`, which takes an `input_map` similar to the deprecated `fill_form()` and calls the `set_value()` method of the corresponding `InputObject`s
* Added `get_input_values()`, which returns a list mapping input names to their currently set values
`project.templates.templates.page_object`:
* Added `form_object.yml.j2` template
* Updated `form_object.py.j2` template. Added `YAML_FILE` and removed `Input` nested class and `FORM_LOCATOR` and `SUBMIT_LOCATOR` declarations
`project.cmd.new`:
* `module_name` argument is now validated with new method `validate_module_name`, which is essentially the same as `validate_module_filename` but doesn't add '.py' to the return value
`project.new_file`:
* Added support for page object prototypes that render more than 1 template (i.e. for the `.yml` file)
* `new_file()` now returns a list of paths for files created (instead of just one)
`webdriver.actions.form`:
* Added `toggle_checkbox()` helper, which clicks on the specified checkbox element, attempting to handle the case where the checkbox is hidden for styling purposes
* Various fixes, adjustments
* A lot of TODO comments about deprecating old input setter/getter methods in favor of the new `InputObject`
Additional Comments
Currently, `FormObject` is the only page object class that supports YAML representation. Support for other prototype classes will be added in future updates.
Additionally, the old method of filling forms using `fill_form()` is deprecated, and will be replaced with the new `fill_inputs()` workflow.