Difference between revisions of "Custom Command's examples"

From GXtest Wiki
Jump to: navigation, search
(New page: Category: GXtest Guides Custom command's examples. Add them directly or use them as a guide. == Compare if a date control has today value == function CustomCommand (paramJS, cur...)
 
Line 16: Line 16:
 
         }   
 
         }   
 
     return result;
 
     return result;
 +
    }
 +
 +
 +
== Check if an image is broken or missing ==
 +
 +
 +
    function CustomCommand (paramJS, currentGXVersion, currentLanguage)
 +
    {
 +
   
 +
      result = "OK";
 +
      for (var i = 0; i < window.document.images.length; i++) {
 +
            if (!(window.document.images[i].complete)) {
 +
              result = "ERROR, image with src:"+window.document.images[i].src+" not found";
 +
            }
 +
   
 +
            if (typeof window.document.images[i].naturalWidth != "undefined" && window.document.images[i].naturalWidth == 0) {
 +
              result = "ERROR, image with src:"+window.document.images[i].src+" not found";
 +
            }
 +
   
 +
      }
 +
   
 +
      /* It must be returned in result variable the value "OK" if the command executed successufuly, or an error description in other case */
 +
      return result;
 
     }
 
     }

Revision as of 17:43, 8 July 2011


Custom command's examples. Add them directly or use them as a guide.

Compare if a date control has today value

   function CustomCommand (paramJS, currentGXVersion, currentLanguage){
       var day=((new Date().getDate()<10) ? "0" : "")+new Date().getDate(); 
       var month=(new Date().getMonth()+1<10) ? "0" +(new Date().getMonth()+1): new Date().getMonth()+1;
       var year=(((new Date().getFullYear())%100<10) ? "0":"") +(new Date().getFullYear())%100;
       var date_var =month.concat("/".concat(day.concat("/".concat(year))));
       if((paramJS==date_var)){
           result = "OK";
       }else{
           result = "Error, is not today";
       }  
   return result;
   }


Check if an image is broken or missing

   function CustomCommand (paramJS, currentGXVersion, currentLanguage)
   {
   
      result = "OK";
      for (var i = 0; i < window.document.images.length; i++) {
           if (!(window.document.images[i].complete)) {
              result = "ERROR, image with src:"+window.document.images[i].src+" not found";
           }
   
           if (typeof window.document.images[i].naturalWidth != "undefined" && window.document.images[i].naturalWidth == 0) {
              result = "ERROR, image with src:"+window.document.images[i].src+" not found";
           }
   
      }
   
      /* It must be returned in result variable the value "OK" if the command executed successufuly, or an error description in other case */
      return result;
   }