Skip to content

Recipe Class

Nitin Surana edited this page Feb 26, 2016 · 4 revisions

##Recipe class the following properties/methods -

###1. Steps (required)

Every recipe should have an array of selectors known as the steps. These are the steps that will be performed in the order of definition.

For e.g.

var steps = [
{
  selector : '#input-email',
  action: 'input',
  value: 'abc@xyz.com'
},
{
  selector: '#passwd',
  action: 'input',
  value: 'passw@rd'
}
]

###2. start(params) (optional)

should return $.Deferred();

This method will be called before executing an recipe and should return a promise. Make necessary checks in this method to make sure the pre-requisites for the recipe are met and resolve the promise else reject the promise. In case of rejection, if a msg is sent it will be displayed to the user. This method will also be passed params, so necessary correction/modification in the steps should be done in this function.

For e.g.

var myRecipe = window.recipe.Recipe();
myRecipe.start = function(params){
  var defer = $.Deferred();
  if($("#somethingShouldExist").length===0){
    defer.reject('This page does not meet the requirements to run the recipe. Make sure you are on XYZ page');
  }else{
    this.steps[0].value = params.email;
    this.steps[1].value = params.passwd;
    defer.resolve();
  }
return defer.promise();
}

###3. stop (optional) This method will be called after recipe is completed. Do necessary cleanup in this method.

NOTE - This method will not be called for recipes injected in other recipes.

Clone this wiki locally