Controller: Basics - convio/watirmark GitHub Wiki
Controllers are the main vehicle to drive the UI. You instantiate a controller and pass in a model. Then you call an action on the controller like #create or #edit.
In the simplest case, you just need to wire the controller to a model and a view
class Contact < Watirmark::WebPage::Controller
@model = ContactModel
@view = ContactView
end
You can then exercise the UI, like creating a new ob
Contact.new.create
In the simplest case, that's ALL you need. Most of the information needed to populate fields should be contained in your View.
If you want to pass in a model to the class and not use the default model, you can use
Contact.new(model).create
Actions
Actions are the commands you send to the controller. Watirmark bundles in some default actions for you and makes the assumption that you've handled the navigation in a well-formed way.
Each action will call a method in the view of the same name and possible call populate_data or verify_data. for example, this is what the create method does: '''ruby def create @view.create @model populate_data end end '''
The #populate_data method goes through the keywords in the view and for every keyword that has a value set in the model, it will populate that value. The #verify_data method will verify the current value of the element on the web page matches what you provided in the model.
create, edit, verify
The most common set of actions are #create, #edit, #verify and #delete. Each of these delegates to the view for navigation and then will complete the action as described above
Other methods
The following methods will only delegate to the view and are provided as convenience methods: #delete, #copy, #restore, #archive, #activate, #deactivate, #publish, #unpublish