Form Handlers
Form handlers allow you to fill or check if an element is filled with a certain type of data.
For example, you can fill select out of the box just by providing element and option.
Using the form handlers is very straightforward. By providing element, option and type of field for example:
When I fill the "form" form with:
| nameInput | Mike Ross | text |
| descriptionTextarea | He is a lawyer | text |
or with automatic field detection for example:
When I fill the "form" form with:
| descriptionTextarea | g:personalData:email |
also, you can use form handlers to check if the correct value is set:
Then the "form" form is filled with:
| descriptionTextarea | v:storedTextareaValue |
Kakunin comes with a set of built-in form handlers:
Text handler
text
- fills input
File Handler
file
- adds the file, by providing a file name (file must be in the data folder)
CKEditor Handler
CKEditor
- fills CKEditor field, with text
Radio Handler
radio
- clicks desired radio option
Select Handler
select
- pick the desired option from select
Checkbox Handler
checkbox
- clicks desired checkbox option
Uploaded File Handler
uploadedFile
- this allows you to check if the file is uploaded (this handler is only for checking)
Custom Handlers
We allow you to write your own handler, just by following form handlers interface
Methods:
isSatisfiedBy(element, elementName)
- this method is used to check if fill form step should use this strategy to for example to fill or select proper option
handleFill(page, elementName, desiredValue)
- this method should contain a way of filling desired field e.g select a proper option from custom Angular select
handleCheck(page, elementName, desiredValue)
- this method should contain a way of checking field e.g is field filled with the provided text
getPriority()
- this method is used in automatioc field detection, higher value means isSatisifedBy method will be later
Example:
const { handlers } = require('kakunin');
class CustomHandler {
constructor() {
this.type = 'custom-handler-type';
}
isSatisfiedBy(element, elementName) {
}
handleFill(page, elementName, desiredValue) {
}
handleCheck(page, elementName, desiredValue) {
}
getPriority() {
return 998;
}
}
handlers.addHandler(new CustomHandler());