Skip to content

Commit caf5d78

Browse files
AshishAshish
authored andcommitted
Mobile Actions refactored
1 parent c73c7d9 commit caf5d78

38 files changed

+1738
-535
lines changed

Engine/src/main/java/com/ing/engine/commands/browser/Assertions.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public void assertElementContainsText() {
3838
LocatorAssertions.ContainsTextOptions options = new LocatorAssertions.ContainsTextOptions();
3939
options.setTimeout(getTimeoutValue());
4040
assertThat(Locator).containsText(Data, options);
41-
text = Locator.textContent();
41+
text = Locator.innerHTML();
4242
highlightElement();
4343
Report.updateTestLog(Action, "Element [" + ObjectName + "] contains text '" + Data + "'", Status.PASS);
4444
removeHighlightFromElement();
@@ -57,7 +57,7 @@ public void assertElementContainsTextIgnoreCase() {
5757
options.setTimeout(getTimeoutValue());
5858
options.setIgnoreCase(true);
5959
assertThat(Locator).containsText(Data, options);
60-
text = Locator.textContent();
60+
text = Locator.innerHTML();
6161
highlightElement();
6262
Report.updateTestLog(Action, "Element [" + ObjectName + "] contains text '" + Data + "'", Status.PASS);
6363
removeHighlightFromElement();
@@ -75,14 +75,14 @@ public void assertElementNotContainsText() {
7575
LocatorAssertions.ContainsTextOptions options = new LocatorAssertions.ContainsTextOptions();
7676
options.setTimeout(getTimeoutValue());
7777
assertThat(Locator).not().containsText(Data, options);
78-
text = Locator.textContent();
78+
text = Locator.innerHTML();
7979
highlightElement();
8080
Report.updateTestLog(Action, "Element [" + ObjectName + "] dos not contain text '" + Data + "'. Actual text is '" + text + "'", Status.PASS);
8181
removeHighlightFromElement();
8282
} catch (PlaywrightException e) {
8383
PlaywrightExceptionLogging(e);
8484
} catch (AssertionFailedError err) {
85-
assertionLogging(err, "[" + ObjectName + "] does not contain text '" + Data + "'");
85+
assertionLogging(err, "[" + ObjectName + "] contains text '" + Data + "'");
8686
}
8787
}
8888

@@ -407,7 +407,7 @@ public void assertElementTextMatches() {
407407
LocatorAssertions.HasTextOptions options = new LocatorAssertions.HasTextOptions();
408408
options.setTimeout(getTimeoutValue());
409409
assertThat(Locator).hasText(Pattern.compile(Data), options);
410-
text = Locator.textContent();
410+
text = Locator.innerHTML();
411411
highlightElement();
412412
Report.updateTestLog(Action, "[" + ObjectName + "] has text '" + Data + "'", Status.PASS);
413413
removeHighlightFromElement();
@@ -425,7 +425,7 @@ public void assertElementTextNotMatches() {
425425
LocatorAssertions.HasTextOptions options = new LocatorAssertions.HasTextOptions();
426426
options.setTimeout(getTimeoutValue());
427427
assertThat(Locator).not().hasText(Pattern.compile(Data), options);
428-
text = Locator.textContent();
428+
text = Locator.innerHTML();
429429
highlightElement();
430430
Report.updateTestLog(Action, "[" + ObjectName + "] does not have text '" + Data + "'. Actual text is '" + text + "'", Status.PASS);
431431
removeHighlightFromElement();

Engine/src/main/java/com/ing/engine/commands/browser/Basic.java

Lines changed: 0 additions & 232 deletions
Original file line numberDiff line numberDiff line change
@@ -156,54 +156,6 @@ public void setDefaultTimeout() {
156156
}
157157
}
158158

159-
@Action(object = ObjectType.BROWSER, desc = "Add a variable to access within testcase", input = InputType.YES, condition = InputType.YES)
160-
public void AddVar() {
161-
String stringOpration = Input.split("\\(", 2)[0].replace("=", "").trim();
162-
switch (stringOpration) {
163-
case "Replace":
164-
replaceFunction();
165-
break;
166-
case "Split":
167-
splitFunction();
168-
break;
169-
case "Substring":
170-
subStringFunction();
171-
break;
172-
default:
173-
addVar(Condition, Data);
174-
break;
175-
}
176-
if (getVar(Condition) != null) {
177-
Report.updateTestLog("addVar", "Variable " + Condition + " added with value " + Data, Status.DONE);
178-
} else {
179-
Report.updateTestLog("addVar", "Variable " + Condition + " not added ", Status.DEBUG);
180-
}
181-
}
182-
183-
@Action(object = ObjectType.BROWSER, desc = "Add a Global variable to access across test set", input = InputType.YES, condition = InputType.YES)
184-
public void AddGlobalVar() {
185-
//Added for Replace, Split and Substring functions to work with AddGlobalVar
186-
String stringOpration = Input.split("\\(", 2)[0].replace("=", "").trim();
187-
switch (stringOpration) {
188-
case "Replace":
189-
replaceFunction();
190-
break;
191-
case "Split":
192-
splitFunction();
193-
break;
194-
case "Substring":
195-
subStringFunction();
196-
break;
197-
default:
198-
addGlobalVar(Condition, Data);
199-
break;
200-
}
201-
if (getVar(Condition) != null) {
202-
Report.updateTestLog(Action, "Variable " + Condition + " added with value " + Data, Status.DONE);
203-
} else {
204-
Report.updateTestLog(Action, "Variable " + Condition + " not added ", Status.DEBUG);
205-
}
206-
}
207159

208160
@Action(object = ObjectType.BROWSER, desc = "Changes the browser size into [<Data>]", input = InputType.YES)
209161
public void setViewPortSize() {
@@ -437,35 +389,6 @@ public void storeElementCSSValueinVariable() {
437389
}
438390
}
439391

440-
@Action(object = ObjectType.BROWSER, desc = "store variable value [<Condition>] in data sheet[<Data>]", input = InputType.YES, condition = InputType.YES)
441-
public void storeVariableInDataSheet() {
442-
if (Input != null && Condition != null) {
443-
if (!getVar(Condition).isEmpty()) {
444-
System.out.println(Condition);
445-
String[] sheetDetail = Input.split(":");
446-
String sheetName = sheetDetail[0];
447-
String columnName = sheetDetail[1];
448-
userData.putData(sheetName, columnName, getVar(Condition));
449-
Report.updateTestLog(Action,
450-
"Value of variable " + Condition + " has been stored into " + "the data sheet", Status.DONE);
451-
} else {
452-
Report.updateTestLog(Action, "The variable " + Condition + " does not contain any value", Status.FAIL);
453-
}
454-
} else {
455-
Report.updateTestLog(Action, "Incorrect input format", Status.DEBUG);
456-
System.out.println("Incorrect input format " + Condition);
457-
}
458-
}
459-
460-
@Action(object = ObjectType.BROWSER, desc = "store value [<Data>] in Variable [<Condition>]", input = InputType.YES, condition = InputType.YES)
461-
public void storeVariable() {
462-
if (Condition.startsWith("%") && Condition.endsWith("%")) {
463-
addVar(Condition, Data);
464-
Report.updateTestLog(Action, "Value" + Data + "' is stored in Variable '" + Condition + "'", Status.DONE);
465-
} else {
466-
Report.updateTestLog(Action, "Variable format is not correct", Status.DEBUG);
467-
}
468-
}
469392

470393
private void PlaywrightExceptionLogging(PlaywrightException e) {
471394
Report.updateTestLog(Action, "Unique Element [" + ObjectName + "] not found on Page. Error :" + e.getMessage(),
@@ -474,159 +397,4 @@ private void PlaywrightExceptionLogging(PlaywrightException e) {
474397
throw new ActionException(e);
475398
}
476399

477-
public void replaceFunction() {
478-
String op = "";
479-
String original = "";
480-
String targetString = "";
481-
String replaceString = "";
482-
String occurance = "";
483-
String[] args2 = null;
484-
String args1 = Input.split("Replace\\(")[1];
485-
if (args1.substring(args1.length() - 1).equals(":")) {
486-
args2 = args1.substring(0, args1.length() - 2).split(",'");
487-
} else {
488-
args2 = args1.substring(0, args1.length() - 1).split(",'");
489-
}
490-
targetString = args2[1].substring(0, args2[1].length() - 1);
491-
replaceString = args2[2].split("',")[0];
492-
occurance = args2[2].split("',")[1];
493-
Pattern pattern = Pattern.compile("%.*%");
494-
Matcher matcher = pattern.matcher(args2[0]);
495-
if (matcher.find()) {
496-
original = getVar(args2[0]);
497-
} else {
498-
original = args2[0].substring(1, args2[0].length() - 1);
499-
}
500-
try {
501-
if (args2.length > 0) {
502-
if (occurance.toLowerCase().equals("first")) {
503-
System.out.println("original " + original);
504-
System.out.println("targetString " + targetString);
505-
System.out.println("replaceString " + replaceString);
506-
System.out.println("occurance " + occurance);
507-
508-
op = original.replaceFirst(targetString, replaceString);
509-
} else {
510-
System.out.println("original " + original);
511-
System.out.println("targetString " + targetString);
512-
System.out.println("replaceString " + replaceString);
513-
System.out.println("occurance " + occurance);
514-
op = original.replace(targetString, replaceString);
515-
}
516-
}
517-
518-
} catch (Exception ex) {
519-
ex.printStackTrace();
520-
}
521-
switch (Action) {
522-
case "AddGlobalVar":
523-
addGlobalVar(Condition, op);
524-
break;
525-
case "AddVar":
526-
addVar(Condition, op);
527-
break;
528-
}
529-
}
530-
531-
public void splitFunction() {
532-
try {
533-
String op = "";
534-
String original = "";
535-
String regex = "";
536-
String stringIndex = "";
537-
String splitLength = "";
538-
String[] args2 = null;
539-
String[] stringSplit = null;
540-
String args1 = Input.split("Split\\(")[1];
541-
542-
if (args1.substring(args1.length() - 1).equals(":")) {
543-
args2 = args1.substring(0, args1.length() - 2).split(",'");
544-
} else {
545-
args2 = args1.substring(0, args1.length() - 1).split(",'");
546-
}
547-
regex = args2[1].split("',")[0];
548-
Pattern pattern = Pattern.compile("%.*%");
549-
Matcher matcher = pattern.matcher(args2[0]);
550-
if (matcher.find()) {
551-
original = getVar(args2[0]);
552-
} else {
553-
original = args2[0].substring(1, args2[0].length() - 1);
554-
}
555-
if (!(args2[1].split("',")[1]).contains(",")) {
556-
stringIndex = args2[1].split("',")[1];
557-
stringSplit = original.split(regex);
558-
} else {
559-
stringIndex = args2[1].split("',")[1].split(",")[1];
560-
splitLength = args2[1].split("',")[1].split(",")[0];
561-
stringSplit = original.split(regex, Integer.parseInt(splitLength));
562-
}
563-
op = stringSplit[Integer.parseInt(stringIndex)];
564-
565-
switch (Action) {
566-
case "AddGlobalVar":
567-
addGlobalVar(Condition, op);
568-
break;
569-
case "AddVar":
570-
addVar(Condition, op);
571-
break;
572-
}
573-
574-
} catch (Exception e) {
575-
e.printStackTrace();
576-
}
577-
}
578-
579-
public void subStringFunction() {
580-
try {
581-
String op = "";
582-
String original = "";
583-
String startIndex = "";
584-
String endIndex = "";
585-
String[] args2 = null;
586-
String args1 = Input.split("Substring\\(")[1];
587-
588-
if (args1.substring(args1.length() - 1).equals(":")) {
589-
args2 = args1.substring(0, args1.length() - 2).split(",");
590-
} else {
591-
args2 = args1.substring(0, args1.length() - 1).split(",");
592-
}
593-
Pattern pattern = Pattern.compile("%.*%");
594-
Matcher matcher = pattern.matcher(args2[0]);
595-
if (matcher.find()) {
596-
original = getVar(args2[0]);
597-
startIndex = args2[1];
598-
if (args2.length == 3) {
599-
endIndex = args2[2];
600-
}
601-
} else {
602-
String[] args3 = args1.substring(0, args1.length() - 2).split("',");
603-
original = args3[0].substring(1, args2[0].length() - 1);
604-
if (args3[1].contains(",")) {
605-
startIndex = args3[1].split(",")[0];
606-
endIndex = args3[1].split(",")[1];
607-
} else {
608-
startIndex = args3[1];
609-
}
610-
}
611-
612-
if (endIndex.equals("")) {
613-
op = original.substring(Integer.parseInt(startIndex));
614-
} else {
615-
op = original.substring(Integer.parseInt(startIndex), Integer.parseInt(endIndex));
616-
}
617-
618-
switch (Action) {
619-
case "AddGlobalVar":
620-
addGlobalVar(Condition, op);
621-
break;
622-
case "AddVar":
623-
addVar(Condition, op);
624-
break;
625-
}
626-
627-
} catch (Exception e) {
628-
e.printStackTrace();
629-
}
630-
}
631-
632400
}

Engine/src/main/java/com/ing/engine/commands/browser/Command.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public class Command {
4242
public Playwright Playwright;
4343
public BrowserContext BrowserContext;
4444
public AutomationObject AObject;
45+
public MobileObject MObject;
4546
public PlaywrightDriverCreation Driver;
4647
public String Data;
4748
public String ObjectName;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
package com.ing.engine.commands.galenCommands;
3+
4+
import com.ing.engine.core.CommandControl;
5+
import com.ing.engine.galenWrapper.SpecValidation.SpecReader;
6+
import com.ing.engine.support.methodInf.Action;
7+
import com.ing.engine.support.methodInf.InputType;
8+
import com.ing.engine.support.methodInf.ObjectType;
9+
import com.galenframework.specs.SpecHorizontally;
10+
import com.galenframework.specs.SpecVertically;
11+
12+
/**
13+
*
14+
*
15+
*/
16+
public class Align extends General {
17+
18+
public Align(CommandControl cc) {
19+
super(cc);
20+
}
21+
/*
22+
@Action(object = ObjectType.APP, desc ="Assert if [<Object>] is aligned horizontally [<Data>] with [<Object2>]", input =InputType.YES, condition = InputType.YES)
23+
public void assertElementAlignedHoriz() {
24+
SpecHorizontally spec = SpecReader.reader().getSpecHorizontally(Condition, Data);
25+
spec.setOriginalText(getMessage("Horizontally", spec.getErrorRate()));
26+
validate(spec);
27+
}
28+
29+
@Action(object = ObjectType.APP, desc ="Assert if [<Object>] is aligned vertically [<Data>] with [<Object2>]", input =InputType.YES, condition = InputType.YES)
30+
public void assertElementAlignedVert() {
31+
SpecVertically spec = SpecReader.reader().getSpecVertically(Condition, Data);
32+
spec.setOriginalText(getMessage("Vertically", spec.getErrorRate()));
33+
validate(spec);
34+
}
35+
36+
private String getMessage(String align, int errorRate) {
37+
String message = String.format("%s is aligned %s with %s", ObjectName, align, Condition);
38+
if (errorRate != 0) {
39+
message += " With Error rate " + errorRate;
40+
}
41+
return message;
42+
}
43+
*/
44+
}

Engine/src/main/java/com/ing/engine/commands/galenCommands/Centered.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class Centered extends General {
1313
public Centered(CommandControl cc) {
1414
super(cc);
1515
}
16-
16+
/*
1717
private void assertElementCentered(SpecCentered.Alignment alignment, SpecCentered.Location location) {
1818
SpecCentered spec = SpecReader.reader().getSpecCentered(Condition, Data, location, alignment);
1919
spec.setOriginalText(getMessage(alignment, location, spec.getErrorRate()));
@@ -57,5 +57,5 @@ private String getMessage(SpecCentered.Alignment alignment, SpecCentered.Locatio
5757
}
5858
return message;
5959
}
60-
60+
*/
6161
}

Engine/src/main/java/com/ing/engine/commands/galenCommands/ColorScheme.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class ColorScheme extends General {
1717
public ColorScheme(CommandControl cc) {
1818
super(cc);
1919
}
20-
20+
/*
2121
@Action(object = ObjectType.APP, desc ="Assert if [<Object>] color scheme matches [<Data>] ", input =InputType.YES)
2222
public void assertElementColorScheme() {
2323
SpecColorScheme spec = SpecReader.reader().getSpecColorScheme(Data);
@@ -28,5 +28,5 @@ public void assertElementColorScheme() {
2828
private String getMessage() {
2929
return String.format("%s's color scheme matches with %s", ObjectName, Data);
3030
}
31-
31+
*/
3232
}

0 commit comments

Comments
 (0)