Skip to content

Commit

Permalink
Merge pull request #30 from ing-bank/Fix/RemoveUnusedObject
Browse files Browse the repository at this point in the history
Issue fixed for remove unused object
  • Loading branch information
JPBorude08 authored Sep 30, 2024
2 parents 1035f21 + e4c50a4 commit da02d1f
Show file tree
Hide file tree
Showing 3 changed files with 306 additions and 244 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ private void forObject() {

private void forRoot() {
addPage.setEnabled(true);
removeUnusedObject.setEnabled(false);

renamePage.setEnabled(false);
deletePage.setEnabled(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
/**
*
*
Expand Down Expand Up @@ -505,26 +507,28 @@ private void removeUnusedObject() {

}

public Map usedObject() {
public Map usedObject() {
Map<String, ArrayList<String>> attributeMap = new HashMap<>();
ArrayList<String> records = new ArrayList<String>();
ArrayList<String> records = new ArrayList<>();
try {
String testPlanPath = getProject().getLocation() + "/TestPlan";
String[] scenarioList = getFolderOrFileList(testPlanPath);
for (int i = 0; i < scenarioList.length; i++) {
String[] csvList = getFolderOrFileList(testPlanPath + "/" + scenarioList[i]);
for (int j = 0; j < csvList.length; j++) {
String csvFilePath = testPlanPath + "/" + scenarioList[i] + "/" + csvList[j];
for (String scenario : scenarioList) {
Path path = Paths.get(testPlanPath + "/" + scenario);
if(Files.isDirectory(path))
{
String[] csvList = getFolderOrFileList(testPlanPath + "/" + scenario);
for (String csv : csvList) {
String csvFilePath = testPlanPath + "/" + scenario + "/" + csv;
String[] values = null;
List objList = null;
try (BufferedReader br = new BufferedReader(new FileReader(csvFilePath))) {
String line;
while ((line = br.readLine()) != null) {
values = line.split(",");
if (!values[1].equals("Browser") && !values[1].equals("ObjectName") && (values.length == 7)) {//&& (values[1])!= "Browser" )
records.add(values[1]);
if (!(attributeMap.containsKey(values[6]))) {
attributeMap.put(values[6], new ArrayList<String>());
attributeMap.put(values[6], new ArrayList<>());
attributeMap.get(values[6]).add(values[1]);
} else {
attributeMap.get(values[6]).add(values[1]);
Expand All @@ -537,6 +541,7 @@ public Map usedObject() {
}
}
}
}

} catch (Exception e) {
e.printStackTrace();
Expand Down Expand Up @@ -584,7 +589,17 @@ public Map UnusedObject(Map<String, List> allSelectedObject, Map<String, List> u
}
}
}

else{
for(int s=0;s<allSelectedObject.get(selectedPage).size();s++)
{
if (!unUsedObject.containsKey(selectedPage.toString())) {
unUsedObject.put(selectedPage.toString(), new ArrayList<String>());
unUsedObject.get(selectedPage.toString()).add((String) allSelectedObject.get(selectedPage).get(s));
} else {
unUsedObject.get(selectedPage.toString()).add((String) allSelectedObject.get(selectedPage).get(s));
}
}
}
}
return unUsedObject;

Expand All @@ -606,7 +621,7 @@ public void deleteUnusedObject(String page, String object) {
Transformer t = tf.newTransformer();
StreamResult result = new StreamResult(new File(orFilePath));
t.transform(new DOMSource(document), result);
result.getOutputStream().close();
// result.getOutputStream().close();

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

0 comments on commit da02d1f

Please sign in to comment.