Skip to content

Commit 4b18c8e

Browse files
authored
Merge pull request #48 from ing-bank/bugfix/mobileActions
Bugfix/mobile actions
2 parents 91ee479 + caf5d78 commit 4b18c8e

File tree

113 files changed

+11791
-2006
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+11791
-2006
lines changed

Datalib/src/main/java/com/ing/datalib/component/Project.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ public Boolean rename(String newName) {
211211
}
212212
}
213213
getObjectRepository().getWebOR().setName(newName);
214-
getObjectRepository().getImageOR().setName(newName);
215214
getObjectRepository().getMobileOR().setName(newName);
216215
return true;
217216
}

Datalib/src/main/java/com/ing/datalib/component/TestStep.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,14 @@ public Boolean isBrowserStep() {
310310
public Boolean isFileStep() {
311311
return getObject().equals("File");
312312
}
313+
314+
public Boolean isMessageStep() {
315+
return getObject().equals("Queue") || getObject().equals("Kafka");
316+
}
317+
318+
public Boolean isSetTextStep() {
319+
return (getObject().equals("Queue") && getAction().contains("setText")) || (getObject().equals("Kafka") && getAction().contains("produceMessage"));
320+
}
313321

314322
public Boolean isWebserviceRequestStep() {
315323
String requests[] = new String[]{"get", "delete", "post", "put", "patch"};

Datalib/src/main/java/com/ing/datalib/component/utils/FileUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static void loadFileinTable(File file, JTable table) {
7373
LOGGER.log(Level.SEVERE, null, ex);
7474
}
7575
} else {
76-
LOGGER.log(Level.SEVERE, "File [{0}] doesn''t exist", file.getAbsolutePath());
76+
// LOGGER.log(Level.SEVERE, "File [{0}] doesn''t exist", file.getAbsolutePath());
7777
}
7878
}
7979

@@ -88,7 +88,7 @@ public static List<CSVRecord> getRecords(File file) {
8888
LOGGER.log(Level.SEVERE, null, ex);
8989
}
9090
} else {
91-
LOGGER.log(Level.SEVERE, "File [{0}] doesn''t exist", file.getAbsolutePath());
91+
// LOGGER.log(Level.SEVERE, "File [{0}] doesn''t exist", file.getAbsolutePath());
9292
}
9393
return new ArrayList<>();
9494
}
@@ -104,7 +104,7 @@ public static CSVHParser getCSVHParser(File file) {
104104
LOGGER.log(Level.SEVERE, null, ex);
105105
}
106106
} else {
107-
LOGGER.log(Level.SEVERE, "File [{0}] doesn''t exist", file.getAbsolutePath());
107+
//LOGGER.log(Level.SEVERE, "File [{0}] doesn''t exist", file.getAbsolutePath());
108108
}
109109
return null;
110110
}

Datalib/src/main/java/com/ing/datalib/or/ObjectRepository.java

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.ing.datalib.component.Project;
55
import com.ing.datalib.or.common.ORPageInf;
66
import com.ing.datalib.or.common.ObjectGroup;
7-
import com.ing.datalib.or.image.ImageOR;
87
import com.ing.datalib.or.mobile.MobileOR;
98
import com.ing.datalib.or.web.WebOR;
109
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
@@ -25,7 +24,6 @@ public class ObjectRepository {
2524

2625
private WebOR webOR;
2726
private MobileOR mobileOR;
28-
private ImageOR imageOR;
2927

3028
public ObjectRepository(Project sProject) {
3129
this.sProject = sProject;
@@ -46,16 +44,11 @@ private void init() {
4644
} else {
4745
mobileOR = new MobileOR(sProject.getName());
4846
}
49-
if (new File(getIORLocation()).exists()) {
50-
imageOR = XML_MAPPER.readValue(new File(getIORLocation()), ImageOR.class);
51-
imageOR.setName(sProject.getName());
52-
} else {
53-
imageOR = new ImageOR(sProject.getName());
54-
}
47+
5548
webOR.setObjectRepository(this);
5649
webOR.setSaved(true);
5750
mobileOR.setObjectRepository(this);
58-
imageOR.setObjectRepository(this);
51+
5952
} catch (IOException ex) {
6053
Logger.getLogger(ObjectRepository.class.getName()).log(Level.SEVERE, null, ex);
6154
}
@@ -97,16 +90,13 @@ public MobileOR getMobileOR() {
9790
return mobileOR;
9891
}
9992

100-
public ImageOR getImageOR() {
101-
return imageOR;
102-
}
93+
10394

10495
public void save() {
10596
try {
10697
if (!webOR.isSaved()) {
10798
XML_MAPPER.writerWithDefaultPrettyPrinter().writeValue(new File(getORLocation()), webOR);
10899
}
109-
XML_MAPPER.writerWithDefaultPrettyPrinter().writeValue(new File(getIORLocation()), imageOR);
110100
XML_MAPPER.writerWithDefaultPrettyPrinter().writeValue(new File(getMORLocation()), mobileOR);
111101
} catch (IOException ex) {
112102
Logger.getLogger(ObjectRepository.class.getName()).log(Level.SEVERE, null, ex);
@@ -118,11 +108,6 @@ public Boolean isObjectPresent(String pageName, String objectName) {
118108
if (webOR.getPageByName(pageName) != null) {
119109
present = webOR.getPageByName(pageName).getObjectGroupByName(objectName) != null;
120110
}
121-
if (!present) {
122-
if (imageOR.getPageByName(pageName) != null) {
123-
present = imageOR.getPageByName(pageName).getObjectGroupByName(objectName) != null;
124-
}
125-
}
126111
if (!present) {
127112
if (mobileOR.getPageByName(pageName) != null) {
128113
present = mobileOR.getPageByName(pageName).getObjectGroupByName(objectName) != null;

Datalib/src/main/java/com/ing/datalib/settings/Capabilities.java

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
21
package com.ing.datalib.settings;
32

43
import com.ing.datalib.util.data.LinkedProperties;
4+
55
import java.io.File;
6+
import java.io.FileOutputStream;
7+
import java.io.IOException;
68
import java.util.HashMap;
79
import java.util.Map;
810
import java.util.Properties;
911

1012
/**
1113
*
12-
*
1314
*/
1415
public class Capabilities {
1516

@@ -19,6 +20,7 @@ public class Capabilities {
1920

2021
public Capabilities(String location) {
2122
this.location = location;
23+
createCapsFolder();
2224
load();
2325
}
2426

@@ -47,10 +49,11 @@ public void addCapability(String browserName) {
4749

4850
public void addCapability(String browserName, LinkedProperties props) {
4951
browserCapabilties.put(browserName, props);
52+
save();
5053
}
5154

5255
public void updateCapabiltyFor(String browserName, String key, String newvalue) {
53-
browserCapabilties.get(browserName).update(key,newvalue);
56+
browserCapabilties.get(browserName).update(key, newvalue);
5457
}
5558

5659
public void addDefaultAppiumCapability(String browserName) {
@@ -73,7 +76,7 @@ public void addDefaultAppiumCapability(String browserName, String udid, String a
7376
}
7477

7578
public void save() {
76-
createCapsFolder();
79+
// createCapsFolder();
7780
for (Map.Entry<String, LinkedProperties> entry : browserCapabilties.entrySet()) {
7881
String capName = entry.getKey();
7982
Properties capProp = entry.getValue();
@@ -82,7 +85,7 @@ public void save() {
8285
}
8386

8487
public void save(String capsName) {
85-
createCapsFolder();
88+
//createCapsFolder();
8689
if (browserCapabilties.containsKey(capsName)) {
8790
PropUtils.save(browserCapabilties.get(capsName), getCapLocation(capsName));
8891
}
@@ -129,7 +132,45 @@ private void createCapsFolder() {
129132
File caps = new File(getLocation());
130133
if (!caps.exists()) {
131134
caps.mkdirs();
135+
createDefaultFile(getLocation());
136+
}
137+
}
138+
139+
private void createDefaultFile(String location) {
140+
String chromiumFile = location + File.separator + "Chromium.properties";
141+
String webkitFile = location + File.separator + "WebKit.properties";
142+
String firefoxFile = location + File.separator + "Firefox.properties";
143+
createFile(chromiumFile);
144+
createFile(webkitFile);
145+
createFile(firefoxFile);
146+
}
147+
148+
private void createFile(String fileName) {
149+
File propertiesFile = new File(fileName);
150+
if (!propertiesFile.exists()) {
151+
try (FileOutputStream fos = new FileOutputStream(propertiesFile)) {
152+
Properties prop = new Properties();
153+
// Add default key-value pairs
154+
prop.setProperty("setHeadless", "false");
155+
prop.setProperty("setSlowMo", "");
156+
prop.setProperty("startMaximized", "");
157+
prop.setProperty("setDevtools", "");
158+
prop.setProperty("setDownloadsPath", "");
159+
prop.setProperty("setExecutablePath", "");
160+
prop.setProperty("setTimeout", "30000");
161+
prop.setProperty("setProxy", "");
162+
if (fileName.contains("Chromium")) {
163+
prop.setProperty("setChannel", "");
164+
prop.setProperty("setChromiumSandbox", "");
165+
}
166+
// Write properties to the file
167+
prop.store(fos, null);
168+
} catch (IOException e) {
169+
System.err.println("Error writing to Chromium.properties file: " + e.getMessage());
170+
}
171+
} else {
172+
System.out.println(fileName + " properties file already exists: " + location);
132173
}
133174
}
134175

135-
}
176+
}
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
package com.ing.datalib.settings;
2+
3+
4+
import java.io.File;
5+
import java.io.FileOutputStream;
6+
import java.io.IOException;
7+
import java.util.*;
8+
9+
/**
10+
*
11+
*/
12+
public class ContextOptions {
13+
14+
private static ArrayList<String> contextList = new ArrayList<>();
15+
private static String location;
16+
private final Map<String, Properties> contextOptions = new HashMap<>();
17+
18+
public ContextOptions(String location) {
19+
this.location = location;
20+
createContextDirectory();
21+
load();
22+
}
23+
24+
public static String getLocation() {
25+
return location + File.separator + "BrowserContexts";
26+
}
27+
28+
public void setLocation(String location) {
29+
this.location = location;
30+
}
31+
32+
public Map<String, Properties> getContextOptions() {
33+
return contextOptions;
34+
}
35+
36+
public ArrayList<String> getContextList() {
37+
load();
38+
return contextList;
39+
}
40+
41+
public Properties getContextOptionsFor(String contextName) {
42+
return contextOptions.get(contextName);
43+
}
44+
45+
private void load() {
46+
contextList.clear();
47+
File contextFile = new File(getLocation());
48+
if (contextFile.exists()) {
49+
for (File contextfile : contextFile.listFiles()) {
50+
if (contextfile.getName().endsWith(".properties")) {
51+
String contextAlias = contextfile.getName().replace(".properties", "");
52+
if (!contextList.contains(contextAlias)) {
53+
contextList.add(contextAlias);
54+
contextOptions.put(contextfile.getName().replace(".properties", ""), PropUtils.load(contextfile));
55+
}
56+
}
57+
}
58+
}
59+
}
60+
61+
public void addContextName(String contextName) {
62+
contextList.add(contextName);
63+
}
64+
65+
public void addContext(String contextName, Properties prop) {
66+
contextOptions.put(contextName, prop);
67+
save();
68+
}
69+
70+
public void addContextOptions(String contextName) {
71+
Properties prop = new Properties();
72+
prop = setBrowserContextOptions(prop, false);
73+
addContext(contextName, prop);
74+
75+
}
76+
77+
public void save() {
78+
for (Map.Entry<String, Properties> entry : contextOptions.entrySet()) {
79+
String contextName = entry.getKey();
80+
Properties contextProp = entry.getValue();
81+
if (!contextName.isBlank()) {
82+
PropUtils.save(contextProp, getContextLocation(contextName));
83+
}
84+
}
85+
}
86+
87+
public void save(String contextName) {
88+
if (contextOptions.containsKey(contextName)) {
89+
PropUtils.save(contextOptions.get(contextName), getContextLocation(contextName));
90+
}
91+
}
92+
93+
public void delete(String contextName) {
94+
if (contextOptions.containsKey(contextName)) {
95+
File context = new File(getContextLocation(contextName));
96+
if (context.exists()) {
97+
context.delete();
98+
}
99+
contextOptions.remove(contextName);
100+
contextList.remove(contextName);
101+
}
102+
}
103+
104+
public String getContextLocation(String contextName) {
105+
return getLocation() + File.separator + contextName + ".properties";
106+
}
107+
108+
private void createContextDirectory() {
109+
File contexts = new File(getLocation());
110+
if (!contexts.exists()) {
111+
contexts.mkdirs();
112+
createDefaultContext(getLocation());
113+
}
114+
}
115+
116+
private void createDefaultContext(String location) {
117+
String fileName = location + File.separator + "default.properties";
118+
File propertiesFile = new File(fileName);
119+
if (!propertiesFile.exists()) {
120+
try (FileOutputStream fos = new FileOutputStream(propertiesFile)) {
121+
Properties prop = new Properties();
122+
prop = setBrowserContextOptions(prop, false);
123+
prop.store(fos, null);
124+
} catch (IOException e) {
125+
System.err.println("Error writing to default.properties file: " + e.getMessage());
126+
}
127+
} else {
128+
System.out.println("default.properties file already exists: " + location);
129+
}
130+
}
131+
132+
private Properties setBrowserContextOptions(Properties prop, Boolean isAuthenticated) {
133+
prop.setProperty("isAuthenticated", String.valueOf(isAuthenticated));
134+
prop.setProperty("userID", "");
135+
prop.setProperty("password", "");
136+
prop.setProperty("useStorageState", "");
137+
prop.setProperty("storageStatePath", "");
138+
prop.setProperty("setGeolocation", "");
139+
prop.setProperty("setViewportSize", "");
140+
prop.setProperty("setDeviceScaleFactor", "");
141+
prop.setProperty("setHasTouch", "");
142+
prop.setProperty("setIsMobile", "");
143+
prop.setProperty("setScreenSize", "");
144+
prop.setProperty("setRecordVideoSize", "");
145+
prop.setProperty("setUserAgent", "");
146+
prop.setProperty("setLocale", "");
147+
prop.setProperty("setTimezoneId", "");
148+
prop.setProperty("setOffline", "");
149+
prop.setProperty("setRecordVideoDir", "");
150+
prop.setProperty("pageTimeout", "30000");
151+
return prop;
152+
153+
}
154+
155+
}

0 commit comments

Comments
 (0)