Skip to content

Commit

Permalink
Merge pull request #25 from ing-bank/fix/globalvarfunction
Browse files Browse the repository at this point in the history
Fixed string function addition to Global Var
  • Loading branch information
ghoshasish99 authored Sep 10, 2024
2 parents a42122f + 893c84f commit 3821e19
Showing 1 changed file with 58 additions and 14 deletions.
72 changes: 58 additions & 14 deletions Engine/src/main/java/com/ing/engine/commands/Basic.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,21 @@ public void setDefaultTimeout() {

@Action(object = ObjectType.BROWSER, desc = "Add a variable to access within testcase", input = InputType.YES, condition = InputType.YES)
public void AddVar() {
if (Input.startsWith("=Replace(")) {
replaceFunction();
} else if (Input.startsWith("=Split(")) {
splitFunction();
} else if (Input.startsWith("=Substring(")) {
subStringFunction();
} else {
addVar(Condition, Data);
String stringOpration = Input.split("\\(", 2)[0].replace("=", "").trim();
switch (stringOpration) {
case "Replace":
replaceFunction();
break;
case "Split":
splitFunction();
break;
case "Substring":
subStringFunction();
break;
default:
addVar(Condition, Data);
break;
}

if (getVar(Condition) != null) {
Report.updateTestLog("addVar", "Variable " + Condition + " added with value " + Data, Status.DONE);
} else {
Expand All @@ -173,7 +178,22 @@ public void AddVar() {

@Action(object = ObjectType.BROWSER, desc = "Add a Global variable to access across test set", input = InputType.YES, condition = InputType.YES)
public void AddGlobalVar() {
addGlobalVar(Condition, Data);
//Added for Replace, Split and Substring functions to work with AddGlobalVar
String stringOpration = Input.split("\\(", 2)[0].replace("=", "").trim();
switch (stringOpration) {
case "Replace":
replaceFunction();
break;
case "Split":
splitFunction();
break;
case "Substring":
subStringFunction();
break;
default:
addGlobalVar(Condition, Data);
break;
}
if (getVar(Condition) != null) {
Report.updateTestLog(Action, "Variable " + Condition + " added with value " + Data, Status.DONE);
} else {
Expand Down Expand Up @@ -483,7 +503,14 @@ public void replaceFunction() {
} catch (Exception ex) {
ex.printStackTrace();
}
addVar(Condition, op);
switch (Action) {
case "AddGlobalVar":
addGlobalVar(Condition, op);
break;
case "AddVar":
addVar(Condition, op);
break;
}
}

public void splitFunction() {
Expand All @@ -503,7 +530,6 @@ public void splitFunction() {
args2 = args1.substring(0, args1.length() - 1).split(",'");
}
regex = args2[1].split("',")[0];
// int arrayLength = args2.length;
Pattern pattern = Pattern.compile("%.*%");
Matcher matcher = pattern.matcher(args2[0]);
if (matcher.find()) {
Expand All @@ -520,7 +546,16 @@ public void splitFunction() {
stringSplit = original.split(regex, Integer.parseInt(splitLength));
}
op = stringSplit[Integer.parseInt(stringIndex)];
addVar(Condition, op);

switch (Action) {
case "AddGlobalVar":
addGlobalVar(Condition, op);
break;
case "AddVar":
addVar(Condition, op);
break;
}

} catch (Exception e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -564,7 +599,16 @@ public void subStringFunction() {
} else {
op = original.substring(Integer.parseInt(startIndex), Integer.parseInt(endIndex));
}
addVar(Condition, op);

switch (Action) {
case "AddGlobalVar":
addGlobalVar(Condition, op);
break;
case "AddVar":
addVar(Condition, op);
break;
}

} catch (Exception e) {
e.printStackTrace();
}
Expand Down

0 comments on commit 3821e19

Please sign in to comment.