Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/multiple contexts #46

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ public Boolean rename(String newName) {
}
}
getObjectRepository().getWebOR().setName(newName);
getObjectRepository().getImageOR().setName(newName);
getObjectRepository().getMobileOR().setName(newName);
return true;
}
Expand Down
4 changes: 4 additions & 0 deletions Datalib/src/main/java/com/ing/datalib/component/TestStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ public Boolean isBrowserStep() {
public Boolean isFileStep() {
return getObject().equals("File");
}

public Boolean isMessageStep() {
return getObject().equals("Queue") || getObject().equals("Kafka");
}

public Boolean isWebserviceRequestStep() {
String requests[] = new String[]{"get", "delete", "post", "put", "patch"};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static void loadFileinTable(File file, JTable table) {
LOGGER.log(Level.SEVERE, null, ex);
}
} else {
LOGGER.log(Level.SEVERE, "File [{0}] doesn''t exist", file.getAbsolutePath());
// LOGGER.log(Level.SEVERE, "File [{0}] doesn''t exist", file.getAbsolutePath());
}
}

Expand All @@ -88,7 +88,7 @@ public static List<CSVRecord> getRecords(File file) {
LOGGER.log(Level.SEVERE, null, ex);
}
} else {
LOGGER.log(Level.SEVERE, "File [{0}] doesn''t exist", file.getAbsolutePath());
// LOGGER.log(Level.SEVERE, "File [{0}] doesn''t exist", file.getAbsolutePath());
}
return new ArrayList<>();
}
Expand All @@ -104,7 +104,7 @@ public static CSVHParser getCSVHParser(File file) {
LOGGER.log(Level.SEVERE, null, ex);
}
} else {
LOGGER.log(Level.SEVERE, "File [{0}] doesn''t exist", file.getAbsolutePath());
//LOGGER.log(Level.SEVERE, "File [{0}] doesn''t exist", file.getAbsolutePath());
}
return null;
}
Expand Down
21 changes: 3 additions & 18 deletions Datalib/src/main/java/com/ing/datalib/or/ObjectRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.ing.datalib.component.Project;
import com.ing.datalib.or.common.ORPageInf;
import com.ing.datalib.or.common.ObjectGroup;
import com.ing.datalib.or.image.ImageOR;
import com.ing.datalib.or.mobile.MobileOR;
import com.ing.datalib.or.web.WebOR;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
Expand All @@ -25,7 +24,6 @@ public class ObjectRepository {

private WebOR webOR;
private MobileOR mobileOR;
private ImageOR imageOR;

public ObjectRepository(Project sProject) {
this.sProject = sProject;
Expand All @@ -46,16 +44,11 @@ private void init() {
} else {
mobileOR = new MobileOR(sProject.getName());
}
if (new File(getIORLocation()).exists()) {
imageOR = XML_MAPPER.readValue(new File(getIORLocation()), ImageOR.class);
imageOR.setName(sProject.getName());
} else {
imageOR = new ImageOR(sProject.getName());
}

webOR.setObjectRepository(this);
webOR.setSaved(true);
mobileOR.setObjectRepository(this);
imageOR.setObjectRepository(this);

} catch (IOException ex) {
Logger.getLogger(ObjectRepository.class.getName()).log(Level.SEVERE, null, ex);
}
Expand Down Expand Up @@ -97,16 +90,13 @@ public MobileOR getMobileOR() {
return mobileOR;
}

public ImageOR getImageOR() {
return imageOR;
}


public void save() {
try {
if (!webOR.isSaved()) {
XML_MAPPER.writerWithDefaultPrettyPrinter().writeValue(new File(getORLocation()), webOR);
}
XML_MAPPER.writerWithDefaultPrettyPrinter().writeValue(new File(getIORLocation()), imageOR);
XML_MAPPER.writerWithDefaultPrettyPrinter().writeValue(new File(getMORLocation()), mobileOR);
} catch (IOException ex) {
Logger.getLogger(ObjectRepository.class.getName()).log(Level.SEVERE, null, ex);
Expand All @@ -118,11 +108,6 @@ public Boolean isObjectPresent(String pageName, String objectName) {
if (webOR.getPageByName(pageName) != null) {
present = webOR.getPageByName(pageName).getObjectGroupByName(objectName) != null;
}
if (!present) {
if (imageOR.getPageByName(pageName) != null) {
present = imageOR.getPageByName(pageName).getObjectGroupByName(objectName) != null;
}
}
if (!present) {
if (mobileOR.getPageByName(pageName) != null) {
present = mobileOR.getPageByName(pageName).getObjectGroupByName(objectName) != null;
Expand Down
53 changes: 47 additions & 6 deletions Datalib/src/main/java/com/ing/datalib/settings/Capabilities.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@

package com.ing.datalib.settings;

import com.ing.datalib.util.data.LinkedProperties;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
*
*
*/
public class Capabilities {

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

public Capabilities(String location) {
this.location = location;
createCapsFolder();
load();
}

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

public void addCapability(String browserName, LinkedProperties props) {
browserCapabilties.put(browserName, props);
save();
}

public void updateCapabiltyFor(String browserName, String key, String newvalue) {
browserCapabilties.get(browserName).update(key,newvalue);
browserCapabilties.get(browserName).update(key, newvalue);
}

public void addDefaultAppiumCapability(String browserName) {
Expand All @@ -73,7 +76,7 @@ public void addDefaultAppiumCapability(String browserName, String udid, String a
}

public void save() {
createCapsFolder();
// createCapsFolder();
for (Map.Entry<String, LinkedProperties> entry : browserCapabilties.entrySet()) {
String capName = entry.getKey();
Properties capProp = entry.getValue();
Expand All @@ -82,7 +85,7 @@ public void save() {
}

public void save(String capsName) {
createCapsFolder();
//createCapsFolder();
if (browserCapabilties.containsKey(capsName)) {
PropUtils.save(browserCapabilties.get(capsName), getCapLocation(capsName));
}
Expand Down Expand Up @@ -129,7 +132,45 @@ private void createCapsFolder() {
File caps = new File(getLocation());
if (!caps.exists()) {
caps.mkdirs();
createDefaultFile(getLocation());
}
}

private void createDefaultFile(String location) {
String chromiumFile = location + File.separator + "Chromium.properties";
String webkitFile = location + File.separator + "WebKit.properties";
String firefoxFile = location + File.separator + "Firefox.properties";
createFile(chromiumFile);
createFile(webkitFile);
createFile(firefoxFile);
}

private void createFile(String fileName) {
File propertiesFile = new File(fileName);
if (!propertiesFile.exists()) {
try (FileOutputStream fos = new FileOutputStream(propertiesFile)) {
Properties prop = new Properties();
// Add default key-value pairs
prop.setProperty("setHeadless", "false");
prop.setProperty("setSlowMo", "");
prop.setProperty("startMaximized", "");
prop.setProperty("setDevtools", "");
prop.setProperty("setDownloadsPath", "");
prop.setProperty("setExecutablePath", "");
prop.setProperty("setTimeout", "30000");
prop.setProperty("setProxy", "");
if (fileName.contains("Chromium")) {
prop.setProperty("setChannel", "");
prop.setProperty("setChromiumSandbox", "");
}
// Write properties to the file
prop.store(fos, null);
} catch (IOException e) {
System.err.println("Error writing to Chromium.properties file: " + e.getMessage());
}
} else {
System.out.println(fileName + " properties file already exists: " + location);
}
}

}
}
155 changes: 155 additions & 0 deletions Datalib/src/main/java/com/ing/datalib/settings/ContextOptions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
package com.ing.datalib.settings;


import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.*;

/**
*
*/
public class ContextOptions {

private static ArrayList<String> contextList = new ArrayList<>();
private static String location;
private final Map<String, Properties> contextOptions = new HashMap<>();

public ContextOptions(String location) {
this.location = location;
createContextDirectory();
load();
}

public static String getLocation() {
return location + File.separator + "BrowserContexts";
}

public void setLocation(String location) {
this.location = location;
}

public Map<String, Properties> getContextOptions() {
return contextOptions;
}

public ArrayList<String> getContextList() {
load();
return contextList;
}

public Properties getContextOptionsFor(String contextName) {
return contextOptions.get(contextName);
}

private void load() {
contextList.clear();
File contextFile = new File(getLocation());
if (contextFile.exists()) {
for (File contextfile : contextFile.listFiles()) {
if (contextfile.getName().endsWith(".properties")) {
String contextAlias = contextfile.getName().replace(".properties", "");
if (!contextList.contains(contextAlias)) {
contextList.add(contextAlias);
contextOptions.put(contextfile.getName().replace(".properties", ""), PropUtils.load(contextfile));
}
}
}
}
}

public void addContextName(String contextName) {
contextList.add(contextName);
}

public void addContext(String contextName, Properties prop) {
contextOptions.put(contextName, prop);
save();
}

public void addContextOptions(String contextName) {
Properties prop = new Properties();
prop = setBrowserContextOptions(prop, false);
addContext(contextName, prop);

}

public void save() {
for (Map.Entry<String, Properties> entry : contextOptions.entrySet()) {
String contextName = entry.getKey();
Properties contextProp = entry.getValue();
if (!contextName.isBlank()) {
PropUtils.save(contextProp, getContextLocation(contextName));
}
}
}

public void save(String contextName) {
if (contextOptions.containsKey(contextName)) {
PropUtils.save(contextOptions.get(contextName), getContextLocation(contextName));
}
}

public void delete(String contextName) {
if (contextOptions.containsKey(contextName)) {
File context = new File(getContextLocation(contextName));
if (context.exists()) {
context.delete();
}
contextOptions.remove(contextName);
contextList.remove(contextName);
}
}

public String getContextLocation(String contextName) {
return getLocation() + File.separator + contextName + ".properties";
}

private void createContextDirectory() {
File contexts = new File(getLocation());
if (!contexts.exists()) {
contexts.mkdirs();
createDefaultContext(getLocation());
}
}

private void createDefaultContext(String location) {
String fileName = location + File.separator + "default.properties";
File propertiesFile = new File(fileName);
if (!propertiesFile.exists()) {
try (FileOutputStream fos = new FileOutputStream(propertiesFile)) {
Properties prop = new Properties();
prop = setBrowserContextOptions(prop, false);
prop.store(fos, null);
} catch (IOException e) {
System.err.println("Error writing to default.properties file: " + e.getMessage());
}
} else {
System.out.println("default.properties file already exists: " + location);
}
}

private Properties setBrowserContextOptions(Properties prop, Boolean isAuthenticated) {
prop.setProperty("isAuthenticated", String.valueOf(isAuthenticated));
prop.setProperty("userID", "");
prop.setProperty("password", "");
prop.setProperty("useStorageState", "");
prop.setProperty("storageStatePath", "");
prop.setProperty("setGeolocation", "");
prop.setProperty("setViewportSize", "");
prop.setProperty("setDeviceScaleFactor", "");
prop.setProperty("setHasTouch", "");
prop.setProperty("setIsMobile", "");
prop.setProperty("setScreenSize", "");
prop.setProperty("setRecordVideoSize", "");
prop.setProperty("setUserAgent", "");
prop.setProperty("setLocale", "");
prop.setProperty("setTimezoneId", "");
prop.setProperty("setOffline", "");
prop.setProperty("setRecordVideoDir", "");
prop.setProperty("pageTimeout", "30000");
return prop;

}

}
Loading
Loading