• function

branch FuncUnit.branch

 

branch(check1, success1, check2, success2)

Uses 2 checker methods to see which success function to call. This is a way to conditionally run one method if you're unsure about the conditions of your page, without causing a test failure. For example, this is useful for login steps, if you're not sure whether the app is logged in.

  S.branch(function(){
       return (S("#exists").size() > 0);
   }, function(){
       ok(true, "found exists")
   }, function(){
       return (S("#notexists").size() > 0);
   }, function(){
       ok(false, "found notexists")
   });

Parameters

  1. check1 {function()}

    a checker function that, if it returns true, causes success1 to be called

  2. success1 {function()}

    a function that runs when check1 returns true

  3. check2 {function()}

    a checker function that, if it returns true, causes success2 to be called

  4. success2 {function()}

    a function that runs when check2 returns true

  5. timeout {Number}

    if neither checker returns true before this timeout, the test fails