webdriver_test_tools.pageobject.form module¶
-
class
webdriver_test_tools.pageobject.form.InputObject(driver, input_dict)[source]¶ Bases:
webdriver_test_tools.pageobject.base.BasePagePage object prototype for input elements
-
class
Type[source]¶ Bases:
objectSet of supported input types
-
CHECKBOX= 'checkbox'¶
-
EMAIL= 'email'¶
-
FILE= 'file'¶
-
NUMBER= 'number'¶
-
PASSWORD= 'password'¶
-
RADIO= 'radio'¶
-
SEARCH= 'search'¶
-
TEXT= 'text'¶
-
URL= 'url'¶
-
SELECT= 'select'¶
-
TEXTAREA= 'textarea'¶
-
SUPPORTS_OPTIONS= ['select', 'radio', 'checkbox']¶ Input types that support the ‘options’ key
-
SUPPORTS_MULTIPLE= ['select', 'checkbox']¶ Input types that support the ‘multiple’ key
-
-
find_input_element()[source]¶ Returns the
WebElementobject located byself.locatorShorthand for
self.find_element(self.locator)- Returns
WebElementobject for the input
-
find_input_elements()[source]¶ Returns the list of
WebElementobjects located byself.locator. Used for input types that can have multiple elements corresponding to it (e.g. radios)Shorthand for
self.find_elements(self.locator)- Returns
List of
WebElementobjects for the inputs
-
set_value(value, **kwargs)[source]¶ Set the value of the input
- Parameters
value –
The value to set it to
For radio elements, this should be the value attribute of the radio to select.
For checkbox elements, this value should be a boolean (True=checked, False=unchecked).
For checkbox groups, this value should be a dictionary mapping checkbox input’s
valueattribute to the desired checked state (True = check, False = uncheck).For single select elements, this value should be the value of the option to select.
For multiple select elements, this value should be a list of values of the options to select.
For file inputs, this value should be a filepath to the desired file.
For other input types (text, number, etc) this should be a string representation of the values to enter into it.
Additionally accepts keyword arguments based on the type of input this
InputObjectrepresents. See the above_setmethods for type-specific optional arguments
-
class
-
class
webdriver_test_tools.pageobject.form.FormObject(driver)[source]¶ Bases:
webdriver_test_tools.pageobject.yaml.YAMLParsingPageObjectPage object prototype for forms
Subclasses should set the following attributes:
- Variables
FormObject.YAML_FILE – Path to a YAML file representing the form object. This file is parsed during initialization using
parse_yaml()and is used to determineFORM_LOCATORandSUBMIT_LOCATORand createInputObjectinstances for each input, which are stored ininputsFormObject.SUBMIT_SUCCESS_CLASS – (Optional) Page object of modal/webpage/etc that should appear on successful form submission. If subclass set to a subclass of
BasePage,click_submit()will return an instance of this object.
The following attributes are determined based on the contents of
YAML_FILE(or should be set in subclasses ifYAML_FILEisNone):- Variables
FormObject.FORM_LOCATOR – Locator for the form element
FormObject.SUBMIT_LOCATOR – Locator for the submit button
The following attribute is set based on the ‘inputs’ key parsed from
YAML_FILE(or parsed fromINPUT_DICTS, which should be set in subclasses ifYAML_FILEisNone):- Variables
FormObject.inputs – A dictionary mapping input names to the corresponding
InputObjectinstances. The keys correspond with thenamekeys in the YAML representation of the form (or the ‘name’ keys inINPUT_DICTSifYAML_FILEisNone)
If
YAML_FILEisNone, subclasses must set the following attribute:- Variables
FormObject.INPUT_DICTS – List of input dictionaries. These are used to initialize the
InputObjectinstances ininputsat runtime. These dictionaries use the same syntax as YAML inputs
-
SUBMIT_SUCCESS_CLASS= None¶
-
FORM_LOCATOR= None¶
-
SUBMIT_LOCATOR= None¶
-
INPUT_DICTS= []¶
-
inputs= {}¶
-
parse_yaml(file_path)[source]¶ Parse a YAML representation of the form object and set attributes accordingly
See YAML FormObjects doc for details on syntax.
- Parameters
file_path – Full path to the YAML file
-
no_yaml_init()[source]¶ Initialize
self.inputsusing values inINPUT_DICTS
-
fill_inputs(input_map, strict=False)[source]¶ Fill form inputs
- Parameters
input_map – Dictionary mapping input name key to the values to set them to. See
InputObject.set_value()for value formats for different input typesstrict – (Default = False) If True, throw an exception if a key in
input_mapis not a valid key inself.inputs. Otherwise throw a warning and continue
-
get_input_values(name_list=None)[source]¶ Get the current values of form inputs
- Parameters
name_list – (Optional) List of input names to get values for. If unspecified, will get values for all inputs
- Returns
Dictionary mapping names to the value of each input
-
submit_is_enabled()[source]¶ Short hand function for checking if the submit button is enabled. Useful for forms with JavaScript input validation
- Returns
True if submit is enabled, False if it’s disabled
-
click_submit()[source]¶ Shorthand function for scrolling to the submit button and clicking it.
If
self.SUBMIT_SUCCESS_CLASSis set to a subclass ofBasePage, an instance of that object will be returned