Skip to content
rahuldantalwal edited this page Apr 27, 2016 · 1 revision

Introduction:

Generic automation framework supports groovy scripts along with the high level behavioural language.

Examples:

1. To check whether Jabong Credit is applied.
@A doCalculation; @D creditsApplied#OUTPUTVALUE=Double.parseDouble("
{$appliedjabongCreditTextOnReviewPage}".replace("- Rs.",""))%%
if(Integer.valueOf((int)OUTPUTVALUE)==Integer.valueOf((int){$jabongCredits}))return "true"%% else return "false"%%;

2. Computation of TotalPrice Before JC (Use of try and catch)
@A calculate; @D totalPriceBeforeJC#try{String price = " {$totalPriceOnCartPage}".replace("R","")%%Float p = Float.parseFloat(price.trim())%%return p%%}catch(Exception e){return Float.parseFloat("0.00")%%};
totalPriceBeforeJC#try{String price = "100.00".replace("R","")%%Float p = Float.parseFloat(price.trim())%%return p%%}catch(Exception e){return Float.parseFloat("0.00")%%}

3. Computation of Shipping Charges(Use of If Else)
@A do calculation; @D shippingChargesOnCart#if("{$shippingChargesOnCart}".equalsIgnoreCase("free")){return 0%%}else{String price= "{$shippingChargesOnCart}".replace("R","")%%return price.trim()%%}; if  @C ShippingApplied; shippingChargesOnCart#if("FREE".equalsIgnoreCase("free")){return 0%%}else{String price= "FREE".replace("R","")%%return price.trim()%%}

Note: Compiler will treat %% as ; while compiling.
Variable can be used as {$ var_name}
The variable in which computed values ll be stored, placed before the # like var_name#groovyScript.
{} used for code blocks(eg. if, else, try, catch etc.)
do calculation and calculation are the two actions to execute groovy scripts.
# works as assignment operator

Usage:

    1. Wherever any kind of computation is required.
    2. Wherever any data manipulation is required on runtime.
    3. Any other runtime programming dependency.