diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..43d1389 Binary files /dev/null and b/.DS_Store differ diff --git a/external_word_document_table_editor/.DS_Store b/external_word_document_table_editor/.DS_Store new file mode 100644 index 0000000..15c7459 Binary files /dev/null and b/external_word_document_table_editor/.DS_Store differ diff --git a/external_word_document_table_editor/pom.xml b/external_word_document_table_editor/pom.xml new file mode 100644 index 0000000..abdeab8 --- /dev/null +++ b/external_word_document_table_editor/pom.xml @@ -0,0 +1,102 @@ + + + 4.0.0 + com.testsigma.addons + external_word_document_table_editor + 1.0.0 + jar + + + UTF-8 + 11 + 11 + 1.2.2_cloud + 5.8.0-M1 + 1.0.0 + 3.2.1 + 1.18.20 + + + + + + com.testsigma + testsigma-java-sdk + ${testsigma.sdk.version} + + + org.projectlombok + lombok + ${lombok.version} + true + + + org.apache.poi + poi-ooxml + 3.15 + + + org.junit.jupiter + junit-jupiter-api + ${junit.jupiter.version} + test + + + org.testng + testng + 6.14.3 + + + + org.seleniumhq.selenium + selenium-java + 3.141.59 + + + + io.appium + java-client + 7.0.0 + + + com.fasterxml.jackson.core + jackson-annotations + 2.13.0 + + + + + external_word_document_table_editor + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.4 + + + package + + shade + + + + + + org.apache.maven.plugins + maven-source-plugin + ${maven.source.plugin.version} + + + attach-sources + + jar + + + + + + + \ No newline at end of file diff --git a/external_word_document_table_editor/src/.DS_Store b/external_word_document_table_editor/src/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/external_word_document_table_editor/src/.DS_Store differ diff --git a/external_word_document_table_editor/src/main/java/com/testsigma/addons/web/CellOperations.java b/external_word_document_table_editor/src/main/java/com/testsigma/addons/web/CellOperations.java new file mode 100644 index 0000000..3e2def3 --- /dev/null +++ b/external_word_document_table_editor/src/main/java/com/testsigma/addons/web/CellOperations.java @@ -0,0 +1,60 @@ +package com.testsigma.addons.web; + +import com.testsigma.sdk.ApplicationType; +import com.testsigma.sdk.Result; +import com.testsigma.sdk.WebAction; +import com.testsigma.sdk.annotation.Action; +import com.testsigma.sdk.annotation.TestData; +import lombok.Data; +import org.openqa.selenium.NoSuchElementException; +import utility.CellUtil; + + +@Data +@Action(actionText = "Select a table from word document and edit or verify a cell."+ + "Document path : Path, Table heading : Heading,"+ + "Perform operation : on target cell column : column-name with value : Value,"+ + "where column2-name value equals column2-value.", + description = "Selects a table from word document and edit or verify a cell.", + applicationType = ApplicationType.WEB) +public class CellOperations extends WebAction { + @TestData(reference = "Path") + private com.testsigma.sdk.TestData documentPath; + @TestData(reference = "Heading") + private com.testsigma.sdk.TestData heading; + @TestData(reference = "", allowedValues = {"Modify","Append","Verify"}) + private com.testsigma.sdk.TestData operation; + @TestData(reference = "column-name") + private com.testsigma.sdk.TestData targetColumn; + @TestData(reference = "column2-name") + private com.testsigma.sdk.TestData column; + @TestData(reference = "column2-value") + private com.testsigma.sdk.TestData value; + @TestData(reference = "Value") + private com.testsigma.sdk.TestData data; + @Override + protected Result execute() throws NoSuchElementException { + CellUtil cellUtil = new CellUtil(); + Result result = Result.FAILED; + if(cellUtil.CellOperations( + documentPath.getValue().toString().trim(), + heading.getValue().toString(), + "", + true, + 1, + targetColumn.getValue().toString(), + column.getValue().toString(), + value.getValue().toString(), + operation.getValue().toString(), + data.getValue().toString() + )){ + result = Result.SUCCESS; + setSuccessMessage(cellUtil.getSuccessMessage()); + logger.info(cellUtil.getSuccessMessage()); + }else{ + setErrorMessage(cellUtil.getErrorMessage()); + logger.info(cellUtil.getErrorMessage()); + } + return result; + } +} diff --git a/external_word_document_table_editor/src/main/java/com/testsigma/addons/web/CellOperationsV2.java b/external_word_document_table_editor/src/main/java/com/testsigma/addons/web/CellOperationsV2.java new file mode 100644 index 0000000..54fe920 --- /dev/null +++ b/external_word_document_table_editor/src/main/java/com/testsigma/addons/web/CellOperationsV2.java @@ -0,0 +1,64 @@ +package com.testsigma.addons.web; + +import com.testsigma.sdk.ApplicationType; +import com.testsigma.sdk.Result; +import com.testsigma.sdk.WebAction; +import com.testsigma.sdk.annotation.Action; +import com.testsigma.sdk.annotation.TestData; +import lombok.Data; +import org.openqa.selenium.NoSuchElementException; +import utility.CellUtil; + + +@Data +@Action(actionText = "Select a child/sub table from word document and edit or verify a cell."+ + "Document path : Path, Table main heading : main-heading, sub heading : sub-heading, table position under sub heading : Position,"+ + "Perform operation : on target cell column : column-name with value : Value, where column2-name value equals column2-value.", + description = "Selects a child/sub table from word document and edit or verify a cell.", + applicationType = ApplicationType.WEB) +public class CellOperationsV2 extends WebAction { + @TestData(reference = "Path") + private com.testsigma.sdk.TestData documentPath; + @TestData(reference = "main-heading") + private com.testsigma.sdk.TestData mainHeading; + @TestData(reference = "sub-heading") + private com.testsigma.sdk.TestData subHeading; + @TestData(reference = "Position") + private com.testsigma.sdk.TestData position; + @TestData(reference = "", allowedValues = {"Modify","Append","Verify"}) + private com.testsigma.sdk.TestData operation; + @TestData(reference = "column-name") + private com.testsigma.sdk.TestData targetColumn; + @TestData(reference = "column2-name") + private com.testsigma.sdk.TestData column; + @TestData(reference = "column2-value") + private com.testsigma.sdk.TestData value; + @TestData(reference = "Value") + private com.testsigma.sdk.TestData data; + @Override + protected Result execute() throws NoSuchElementException { + CellUtil cellUtil = new CellUtil(); + Result result = Result.FAILED; + if(cellUtil.CellOperations( + documentPath.getValue().toString(), + mainHeading.getValue().toString(), + subHeading.getValue().toString(), + false, + Integer.parseInt(position.getValue().toString()), + targetColumn.getValue().toString(), + column.getValue().toString(), + value.getValue().toString(), + operation.getValue().toString(), + data.getValue().toString() + )){ + result = Result.SUCCESS; + setSuccessMessage(cellUtil.getSuccessMessage()); + logger.info(cellUtil.getSuccessMessage()); + }else{ + setErrorMessage(cellUtil.getErrorMessage()); + logger.info(cellUtil.getErrorMessage()); + } + return result; + } +} + diff --git a/external_word_document_table_editor/src/main/java/com/testsigma/addons/web/CellSelectionAndDeletion.java b/external_word_document_table_editor/src/main/java/com/testsigma/addons/web/CellSelectionAndDeletion.java new file mode 100644 index 0000000..366890e --- /dev/null +++ b/external_word_document_table_editor/src/main/java/com/testsigma/addons/web/CellSelectionAndDeletion.java @@ -0,0 +1,54 @@ +package com.testsigma.addons.web; + +import com.testsigma.sdk.ApplicationType; +import com.testsigma.sdk.Result; +import com.testsigma.sdk.WebAction; +import com.testsigma.sdk.annotation.Action; +import com.testsigma.sdk.annotation.TestData; +import lombok.Data; +import org.openqa.selenium.NoSuchElementException; +import utility.CellUtil; + +@Data +@Action(actionText = "Select a table from word document and select or clear a cell."+ + "Document path : Path, Table heading : Heading, Perform operation : on target cell column : column-name,"+ + "where column2-name value equals column2-value.", + description = "Selects a table from word document and select or clear a cell.", + applicationType = ApplicationType.WEB) +public class CellSelectionAndDeletion extends WebAction { + @TestData(reference = "Path") + private com.testsigma.sdk.TestData documentPath; + @TestData(reference = "Heading") + private com.testsigma.sdk.TestData heading; + @TestData(reference = "", allowedValues = {"Select", "Clear"}) + private com.testsigma.sdk.TestData operation; + @TestData(reference = "column-name") + private com.testsigma.sdk.TestData targetColumn; + @TestData(reference = "column2-name") + private com.testsigma.sdk.TestData column; + @TestData(reference = "column2-value") + private com.testsigma.sdk.TestData value; + + @Override + protected Result execute() throws NoSuchElementException { + CellUtil cellUtil = new CellUtil(); + Result result = Result.FAILED; + if(cellUtil.CellSelectionAndDeletion( + documentPath.getValue().toString(), + heading.getValue().toString(), + "", + true, + 1, + targetColumn.getValue().toString(), + column.getValue().toString(), + value.getValue().toString(), + operation.getValue().toString() + )){ + result = Result.SUCCESS; + setSuccessMessage(cellUtil.getSuccessMessage()); + }else{ + setErrorMessage(cellUtil.getErrorMessage()); + } + return result; + } +} diff --git a/external_word_document_table_editor/src/main/java/com/testsigma/addons/web/CellSelectionAndDeletionV2.java b/external_word_document_table_editor/src/main/java/com/testsigma/addons/web/CellSelectionAndDeletionV2.java new file mode 100644 index 0000000..d646bfa --- /dev/null +++ b/external_word_document_table_editor/src/main/java/com/testsigma/addons/web/CellSelectionAndDeletionV2.java @@ -0,0 +1,61 @@ +package com.testsigma.addons.web; + + +import com.testsigma.sdk.ApplicationType; +import com.testsigma.sdk.Result; +import com.testsigma.sdk.WebAction; +import com.testsigma.sdk.annotation.Action; +import com.testsigma.sdk.annotation.TestData; +import lombok.Data; +import org.openqa.selenium.NoSuchElementException; +import utility.CellUtil; + + +@Data +@Action(actionText = "Select a child/sub table from word document and select or clear a cell."+ + "Document path : Path, Table main heading : main-heading, sub heading : sub-heading, table position under sub heading : Position,"+ + "Perform operation : on target cell column name : column-name, where column2 name : column2-name value equals column2-value.", + description = "Selects a child/sub table from word document and select or clear a cell.", + applicationType = ApplicationType.WEB) +public class CellSelectionAndDeletionV2 extends WebAction { + @TestData(reference = "Path") + private com.testsigma.sdk.TestData documentPath; + @TestData(reference = "main-heading") + private com.testsigma.sdk.TestData mainHeading; + @TestData(reference = "sub-heading") + private com.testsigma.sdk.TestData subHeading; + @TestData(reference = "Position") + private com.testsigma.sdk.TestData position; + @TestData(reference = "", allowedValues = {"Select", "Clear"}) + private com.testsigma.sdk.TestData operation; + @TestData(reference = "column-name") + private com.testsigma.sdk.TestData targetColumn; + @TestData(reference = "column2-name") + private com.testsigma.sdk.TestData column; + @TestData(reference = "column2-value") + private com.testsigma.sdk.TestData value; + + @Override + protected Result execute() throws NoSuchElementException { + CellUtil cellUtil = new CellUtil(); + Result result = Result.FAILED; + if(cellUtil.CellSelectionAndDeletion( + documentPath.getValue().toString(), + mainHeading.getValue().toString(), + subHeading.getValue().toString(), + false, + Integer.parseInt(position.getValue().toString()), + targetColumn.getValue().toString(), + column.getValue().toString(), + value.getValue().toString(), + operation.getValue().toString() + )){ + result = Result.SUCCESS; + setSuccessMessage(cellUtil.getSuccessMessage()); + }else{ + setErrorMessage(cellUtil.getErrorMessage()); + } + return result; + } +} + diff --git a/external_word_document_table_editor/src/main/java/com/testsigma/addons/web/RowAddition.java b/external_word_document_table_editor/src/main/java/com/testsigma/addons/web/RowAddition.java new file mode 100644 index 0000000..184f19d --- /dev/null +++ b/external_word_document_table_editor/src/main/java/com/testsigma/addons/web/RowAddition.java @@ -0,0 +1,50 @@ +package com.testsigma.addons.web; + +import com.testsigma.sdk.ApplicationType; +import com.testsigma.sdk.Result; +import com.testsigma.sdk.WebAction; +import com.testsigma.sdk.annotation.Action; +import com.testsigma.sdk.annotation.TestData; +import lombok.Data; +import org.openqa.selenium.NoSuchElementException; +import utility.RowUtil; + + +@Data +@Action(actionText = "Select a table from word document and add a row in specific position."+ + "Document path : Path , Table heading : Heading,"+ + "Add row with data : row-data at position row-position.", + description = "Selects a table from word document and add a row in specific position.", + applicationType = ApplicationType.WEB) +public class RowAddition extends WebAction { + @TestData(reference = "Path") + private com.testsigma.sdk.TestData documentPath; + @TestData(reference = "Heading") + private com.testsigma.sdk.TestData heading; + @TestData(reference = "row-data") + private com.testsigma.sdk.TestData data; + @TestData(reference = "row-position") + private com.testsigma.sdk.TestData rowPosition; + @Override + protected Result execute() throws NoSuchElementException { + RowUtil rowUtil = new RowUtil(); + Result result = Result.FAILED; + if(rowUtil.RowAddition( + documentPath.getValue().toString(), + heading.getValue().toString(), + "", + true, + 1, + data.getValue().toString(), + Integer.parseInt(rowPosition.getValue().toString()) + )){ + result = Result.SUCCESS; + setSuccessMessage(rowUtil.getSuccessMessage()); + logger.info(rowUtil.getSuccessMessage()); + }else{ + setErrorMessage(rowUtil.getErrorMessage()); + logger.info(rowUtil.getErrorMessage()); + } + return result; + } +} diff --git a/external_word_document_table_editor/src/main/java/com/testsigma/addons/web/RowAdditionV2.java b/external_word_document_table_editor/src/main/java/com/testsigma/addons/web/RowAdditionV2.java new file mode 100644 index 0000000..7828f57 --- /dev/null +++ b/external_word_document_table_editor/src/main/java/com/testsigma/addons/web/RowAdditionV2.java @@ -0,0 +1,56 @@ +package com.testsigma.addons.web; + + +import com.testsigma.sdk.ApplicationType; +import com.testsigma.sdk.Result; +import com.testsigma.sdk.WebAction; +import com.testsigma.sdk.annotation.Action; +import com.testsigma.sdk.annotation.TestData; +import lombok.Data; +import org.openqa.selenium.NoSuchElementException; +import utility.RowUtil; + + +@Data +@Action(actionText = "Select a child/sub table from word document and add a row in specific position."+ + "Document path : Path , Table main heading : main-heading, sub heading : sub-heading, table position under sub heading : Position,"+ + "Add row with data : row-data at position row-position.", + description = "Selects a child/sub table from word document and add a row in specific position.", + applicationType = ApplicationType.WEB) +public class RowAdditionV2 extends WebAction { + @TestData(reference = "Path") + private com.testsigma.sdk.TestData documentPath; + @TestData(reference = "main-heading") + private com.testsigma.sdk.TestData mainHeading; + @TestData(reference = "sub-heading") + private com.testsigma.sdk.TestData subHeading; + @TestData(reference = "Position") + private com.testsigma.sdk.TestData tablePosition; + @TestData(reference = "row-data") + private com.testsigma.sdk.TestData data; + @TestData(reference = "row-position") + private com.testsigma.sdk.TestData rowPosition; + @Override + protected Result execute() throws NoSuchElementException { + RowUtil rowUtil = new RowUtil(); + Result result = Result.FAILED; + if(rowUtil.RowAddition( + documentPath.getValue().toString(), + mainHeading.getValue().toString(), + subHeading.getValue().toString(), + false, + Integer.parseInt(tablePosition.getValue().toString()), + data.getValue().toString(), + Integer.parseInt(rowPosition.getValue().toString()) + )){ + result = Result.SUCCESS; + setSuccessMessage(rowUtil.getSuccessMessage()); + logger.info(rowUtil.getSuccessMessage()); + }else{ + setErrorMessage(rowUtil.getErrorMessage()); + logger.info(rowUtil.getErrorMessage()); + } + return result; + } +} + diff --git a/external_word_document_table_editor/src/main/java/com/testsigma/addons/web/RowOperations.java b/external_word_document_table_editor/src/main/java/com/testsigma/addons/web/RowOperations.java new file mode 100644 index 0000000..958df6a --- /dev/null +++ b/external_word_document_table_editor/src/main/java/com/testsigma/addons/web/RowOperations.java @@ -0,0 +1,55 @@ +package com.testsigma.addons.web; + +import com.testsigma.sdk.ApplicationType; +import com.testsigma.sdk.Result; +import com.testsigma.sdk.WebAction; +import com.testsigma.sdk.annotation.Action; +import com.testsigma.sdk.annotation.TestData; +import lombok.Data; +import org.openqa.selenium.NoSuchElementException; +import utility.RowUtil; + +@Data +@Action(actionText = "Select a table from word document and edit or verify a row."+ + "Document path : Path, Table heading : Heading,"+ + "Perform operation : on row with data : row-data where column : column-name value equals column-value.", + description = "Selects a table from word document and edit or verify a row.", + applicationType = ApplicationType.WEB) +public class RowOperations extends WebAction { + @TestData(reference = "Path") + private com.testsigma.sdk.TestData documentPath; + @TestData(reference = "Heading") + private com.testsigma.sdk.TestData heading; + @TestData(reference = "", allowedValues = {"Modify","Append","Verify"}) + private com.testsigma.sdk.TestData operation; + @TestData(reference = "column-name") + private com.testsigma.sdk.TestData column; + @TestData(reference = "column-value") + private com.testsigma.sdk.TestData value; + @TestData(reference = "row-data") + private com.testsigma.sdk.TestData data; + @Override + protected Result execute() throws NoSuchElementException { + RowUtil rowUtil = new RowUtil(); + Result result = Result.FAILED; + if(rowUtil.RowOperations( + documentPath.getValue().toString(), + heading.getValue().toString(), + "", + true, + 1, + column.getValue().toString(), + value.getValue().toString(), + operation.getValue().toString(), + data.getValue().toString() + )){ + result = Result.SUCCESS; + setSuccessMessage(rowUtil.getSuccessMessage()); + logger.info(rowUtil.getSuccessMessage()); + }else{ + setErrorMessage(rowUtil.getErrorMessage()); + logger.info(rowUtil.getErrorMessage()); + } + return result; + } +} diff --git a/external_word_document_table_editor/src/main/java/com/testsigma/addons/web/RowOperationsV2.java b/external_word_document_table_editor/src/main/java/com/testsigma/addons/web/RowOperationsV2.java new file mode 100644 index 0000000..9e7c83a --- /dev/null +++ b/external_word_document_table_editor/src/main/java/com/testsigma/addons/web/RowOperationsV2.java @@ -0,0 +1,61 @@ +package com.testsigma.addons.web; + + +import com.testsigma.sdk.ApplicationType; +import com.testsigma.sdk.Result; +import com.testsigma.sdk.WebAction; +import com.testsigma.sdk.annotation.Action; +import com.testsigma.sdk.annotation.TestData; +import lombok.Data; +import org.openqa.selenium.NoSuchElementException; +import utility.RowUtil; + + +@Data +@Action(actionText = "Select a child/sub table from word document and edit or verify a row."+ + "Document path : Path, Table main heading : main-heading, sub heading : sub-heading, table position under sub heading : Position,"+ + "Perform operation : on row with data : row-data where column : column-name value equals column-value.", + description = "Selects a child/sub table from word document and edit or verify a row.", + applicationType = ApplicationType.WEB) +public class RowOperationsV2 extends WebAction { + @TestData(reference = "Path") + private com.testsigma.sdk.TestData documentPath; + @TestData(reference = "main-heading") + private com.testsigma.sdk.TestData mainHeading; + @TestData(reference = "sub-heading") + private com.testsigma.sdk.TestData subHeading; + @TestData(reference = "Position") + private com.testsigma.sdk.TestData position; + @TestData(reference = "", allowedValues = {"Modify","Append","Verify"}) + private com.testsigma.sdk.TestData operation; + @TestData(reference = "column-name") + private com.testsigma.sdk.TestData column; + @TestData(reference = "column-value") + private com.testsigma.sdk.TestData value; + @TestData(reference = "row-data") + private com.testsigma.sdk.TestData data; + @Override + protected Result execute() throws NoSuchElementException { + RowUtil rowUtil = new RowUtil(); + Result result = Result.FAILED; + if(rowUtil.RowOperations( + documentPath.getValue().toString(), + mainHeading.getValue().toString(), + subHeading.getValue().toString(), + false, + Integer.parseInt(position.getValue().toString()), + column.getValue().toString(), + value.getValue().toString(), + operation.getValue().toString(), + data.getValue().toString() + )){ + result = Result.SUCCESS; + setSuccessMessage(rowUtil.getSuccessMessage()); + logger.info(rowUtil.getSuccessMessage()); + }else{ + setErrorMessage(rowUtil.getErrorMessage()); + logger.info(rowUtil.getErrorMessage()); + } + return result; + } +} diff --git a/external_word_document_table_editor/src/main/java/com/testsigma/addons/web/RowSelectionAndDeletion.java b/external_word_document_table_editor/src/main/java/com/testsigma/addons/web/RowSelectionAndDeletion.java new file mode 100644 index 0000000..4118ac0 --- /dev/null +++ b/external_word_document_table_editor/src/main/java/com/testsigma/addons/web/RowSelectionAndDeletion.java @@ -0,0 +1,53 @@ +package com.testsigma.addons.web; + +import com.testsigma.sdk.ApplicationType; +import com.testsigma.sdk.Result; +import com.testsigma.sdk.WebAction; +import com.testsigma.sdk.annotation.Action; +import com.testsigma.sdk.annotation.TestData; +import lombok.Data; +import org.openqa.selenium.NoSuchElementException; +import utility.RowUtil; + + +@Data +@Action(actionText = "Select a table from word document and select or delete a row."+ + "Document path : Path, Table heading : Heading,"+ + "Perform operation : on row, where column : column-name value equals column-value.", + description = "Selects a table from word document and select or delete a row.", + applicationType = ApplicationType.WEB) +public class RowSelectionAndDeletion extends WebAction { + @TestData(reference = "Path") + private com.testsigma.sdk.TestData documentPath; + @TestData(reference = "Heading") + private com.testsigma.sdk.TestData heading; + @TestData(reference = "", allowedValues = {"Select","Delete"}) + private com.testsigma.sdk.TestData operation; + @TestData(reference = "column-name") + private com.testsigma.sdk.TestData column; + @TestData(reference = "column-value") + private com.testsigma.sdk.TestData value; + @Override + protected Result execute() throws NoSuchElementException { + RowUtil rowUtil = new RowUtil(); + Result result = Result.FAILED; + if(rowUtil.RowSelectionAndDeletion( + documentPath.getValue().toString(), + heading.getValue().toString(), + "", + true, + 1, + operation.getValue().toString(), + column.getValue().toString(), + value.getValue().toString() + )){ + result = Result.SUCCESS; + setSuccessMessage(rowUtil.getSuccessMessage()); + logger.info(rowUtil.getSuccessMessage()); + }else{ + setErrorMessage(rowUtil.getErrorMessage()); + logger.info(rowUtil.getErrorMessage()); + } + return result; + } +} diff --git a/external_word_document_table_editor/src/main/java/com/testsigma/addons/web/RowSelectionAndDeletionV2.java b/external_word_document_table_editor/src/main/java/com/testsigma/addons/web/RowSelectionAndDeletionV2.java new file mode 100644 index 0000000..2df0f57 --- /dev/null +++ b/external_word_document_table_editor/src/main/java/com/testsigma/addons/web/RowSelectionAndDeletionV2.java @@ -0,0 +1,58 @@ +package com.testsigma.addons.web; + + +import com.testsigma.sdk.ApplicationType; +import com.testsigma.sdk.Result; +import com.testsigma.sdk.WebAction; +import com.testsigma.sdk.annotation.Action; +import com.testsigma.sdk.annotation.TestData; +import lombok.Data; +import org.openqa.selenium.NoSuchElementException; +import utility.RowUtil; + +@Data +@Action(actionText = "Select a child/sub table from word document and select or delete a row."+ + "Document path : Path, Table main heading : main-heading, sub heading : sub-heading, table position under sub heading : Position,"+ + "Perform operation : on row, where column : column-name value equals column-value.", + description = "Selects a child/sub table from word document and select or delete a row.", + applicationType = ApplicationType.WEB) +public class RowSelectionAndDeletionV2 extends WebAction { + @TestData(reference = "Path") + private com.testsigma.sdk.TestData documentPath; + @TestData(reference = "main-heading") + private com.testsigma.sdk.TestData mainHeading; + @TestData(reference = "sub-heading") + private com.testsigma.sdk.TestData subHeading; + @TestData(reference = "Position") + private com.testsigma.sdk.TestData position; + @TestData(reference = "", allowedValues = {"Select","Delete"}) + private com.testsigma.sdk.TestData operation; + @TestData(reference = "column-name") + private com.testsigma.sdk.TestData column; + @TestData(reference = "column-value") + private com.testsigma.sdk.TestData value; + @Override + protected Result execute() throws NoSuchElementException { + RowUtil rowUtil = new RowUtil(); + Result result = Result.FAILED; + if(rowUtil.RowSelectionAndDeletion( + documentPath.getValue().toString(), + mainHeading.getValue().toString(), + subHeading.getValue().toString(), + false, + Integer.parseInt(position.getValue().toString()), + operation.getValue().toString(), + column.getValue().toString(), + value.getValue().toString() + )){ + result = Result.SUCCESS; + setSuccessMessage(rowUtil.getSuccessMessage()); + logger.info(rowUtil.getSuccessMessage()); + }else{ + setErrorMessage(rowUtil.getErrorMessage()); + logger.info(rowUtil.getErrorMessage()); + } + return result; + } +} + diff --git a/external_word_document_table_editor/src/main/java/utility/CellUtil.java b/external_word_document_table_editor/src/main/java/utility/CellUtil.java new file mode 100644 index 0000000..5f5b3a6 --- /dev/null +++ b/external_word_document_table_editor/src/main/java/utility/CellUtil.java @@ -0,0 +1,127 @@ +package utility; + + +import lombok.Data; +import org.apache.poi.xwpf.usermodel.XWPFDocument; +import org.apache.poi.xwpf.usermodel.XWPFTable; +import org.apache.poi.xwpf.usermodel.XWPFTableCell; +import org.openqa.selenium.NoSuchElementException; +import org.springframework.beans.factory.annotation.Autowired; + +import com.testsigma.sdk.Logger; + +import java.io.*; +import java.net.HttpURLConnection; +import java.net.URL; + +@Data +public class CellUtil { + private String errorMessage; + private String successMessage; + WordTableEditorUtil wordTableEditorUtil = new WordTableEditorUtil(); + public boolean CellOperations( + String documentPath, + String mainHeading, + String subHeading, + boolean onlyMainHeading, + int tablePosition, + String targetColumn, + String column, + String value, + String operation, + String data + ){ + boolean result = false; + try{ + FileInputStream fis = new FileInputStream(documentPath); + XWPFDocument document = new XWPFDocument(fis); + fis.close(); + XWPFTable table = wordTableEditorUtil.getTable( + document, + mainHeading, + subHeading, + onlyMainHeading, + tablePosition + ); + if(table == null){ + throw new NoSuchElementException("Table not found"); + } + XWPFTableCell cell = wordTableEditorUtil.getTableCell( + table, + targetColumn, + column, + value + ); + if(cell == null){ + throw new NoSuchElementException("Specified cell not found"); + } + if(wordTableEditorUtil.tableCellEditor(cell,operation,data)){ + FileOutputStream fos = new FileOutputStream(documentPath); + document.write(fos); + result = true; + this.successMessage = operation+" operation on cell is successful"; + fos.close(); + document.close(); + } + + }catch(IOException | NoSuchElementException e){ + this.errorMessage = e.getMessage(); + } + return result; + } + public boolean CellSelectionAndDeletion( + String documentPath, + String mainHeading, + String subHeading, + boolean onlyMainHeading, + int tablePosition, + String targetColumn, + String column, + String value, + String operation + ){ + boolean result = false; + try{ + FileInputStream fis = new FileInputStream(documentPath); + XWPFDocument document = new XWPFDocument(fis); + fis.close(); + XWPFTable table = wordTableEditorUtil.getTable( + document, + mainHeading, + subHeading, + onlyMainHeading, + tablePosition + ); + if(table == null){ + throw new NoSuchElementException("Table not found"); + } + XWPFTableCell cell = wordTableEditorUtil.getTableCell( + table, + targetColumn, + column, + value + ); + if(cell == null){ + throw new NoSuchElementException("Specified cell not found"); + } + if(operation.equals("Select")){ + result = true; + this.successMessage = "value found: "+cell.getText(); + }else{ + if(wordTableEditorUtil.tableCellEditor(cell,"Clear","")){ + FileOutputStream fos = new FileOutputStream(documentPath); + document.write(fos); + result = true; + this.successMessage = "Target cell cleared successfully"; + fos.close(); + document.close(); + } + } + + }catch(IOException | NoSuchElementException e){ + this.errorMessage = e.getMessage(); + } + + return result; + } +} diff --git a/external_word_document_table_editor/src/main/java/utility/RowUtil.java b/external_word_document_table_editor/src/main/java/utility/RowUtil.java new file mode 100644 index 0000000..6ccd98e --- /dev/null +++ b/external_word_document_table_editor/src/main/java/utility/RowUtil.java @@ -0,0 +1,192 @@ +package utility; + +import lombok.Data; +import org.apache.poi.xwpf.usermodel.*; +import org.apache.xmlbeans.XmlException; +import org.openqa.selenium.NoSuchElementException; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow; + +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.security.InvalidParameterException; +import java.util.InputMismatchException; +import java.util.List; + +@Data +public class RowUtil { + private String errorMessage; + private String successMessage; + WordTableEditorUtil wordTableEditorUtil = new WordTableEditorUtil(); + public boolean RowAddition( + String documentPath, + String mainHeading, + String subHeading, + boolean onlyMainHeading, + int tablePosition, + String data, + int position + ){ + boolean result = false; + List dataList = List.of(data.split("--")); + try{ + FileInputStream fis = new FileInputStream(documentPath); + XWPFDocument document = new XWPFDocument(fis); + fis.close(); + XWPFTable table = wordTableEditorUtil.getTable( + document, + mainHeading, + subHeading, + onlyMainHeading, + tablePosition + ); + if(table == null){ + throw new NoSuchElementException("Table not found"); + } + if(position < 0 || position > table.getNumberOfRows()){ + throw new InvalidParameterException("Invalid position"); + } + XWPFTableRow oldRow = table.getRow(1); + CTRow ctrow = CTRow.Factory.parse(oldRow.getCtRow().newInputStream()); + XWPFTableRow newRow = new XWPFTableRow(ctrow, table); + int i = 0; + if(dataList.size() != oldRow.getTableCells().size()){ + throw new InputMismatchException("Given data items size is incompatible with specified table row"); + } + for (XWPFTableCell cell : newRow.getTableCells()) { + cell.removeParagraph(0); + cell.setText(""); + } + + for (int index = 0; index < newRow.getTableCells().size(); index++) { + XWPFParagraph paragraph = newRow.getCell(index).addParagraph(); + XWPFRun run = paragraph.createRun(); + run.setText(dataList.get(index)); + } + table.addRow(newRow, position); + FileOutputStream fos = new FileOutputStream(documentPath); + document.write(fos); + result = true; + this.successMessage = "Row added successfully"; + fos.close(); + document.close(); + }catch(NoSuchElementException | InputMismatchException e){ + this.errorMessage = e.getMessage(); + } + catch(IOException | RuntimeException | XmlException e){ + this.errorMessage = e.getMessage(); + } + return result; + } + + public boolean RowOperations( + String documentPath, + String mainHeading, + String subHeading, + boolean onlyMainHeading, + int tablePosition, + String column, + String value, + String operation, + String data + ){ + boolean result = false; + List dataList = List.of(data.split("--")); + try{ + FileInputStream fis = new FileInputStream(documentPath); + XWPFDocument document = new XWPFDocument(fis); + fis.close(); + XWPFTable table = wordTableEditorUtil.getTable( + document, + mainHeading, + subHeading, + onlyMainHeading, + tablePosition + ); + if(table == null){ + throw new NoSuchElementException("Table not found"); + } + int rowIndex = wordTableEditorUtil.getRowIndex(table,column,value); + if(rowIndex == -1){ + throw new NoSuchElementException("Specified row not found"); + } + XWPFTableRow row = table.getRow(rowIndex); + if(dataList.size() != row.getTableCells().size()){ + throw new InputMismatchException("Given data items size is incompatible with specified row"); + } + int index = 0; + for(XWPFTableCell cell : row.getTableCells()){ + if(!wordTableEditorUtil.tableCellEditor(cell,operation,dataList.get(index++))){ + throw new RuntimeException(operation+" on specified row failed"); + } + } + FileOutputStream fos = new FileOutputStream(documentPath); + document.write(fos); + result = true; + this.successMessage = operation+" operation on row is successful"; + fos.close(); + document.close(); + + }catch( NoSuchElementException | InputMismatchException e){ + this.errorMessage = e.getMessage(); + } + catch(IOException | RuntimeException e){ + this.errorMessage = e.getMessage(); + } + return result; + } + public boolean RowSelectionAndDeletion( + String documentPath, + String mainHeading, + String subHeading, + boolean onlyMainHeading, + int tablePosition, + String operation, + String column, + String value + ){ + boolean result = false; + try{ + FileInputStream fis = new FileInputStream(documentPath); + XWPFDocument document = new XWPFDocument(fis); + fis.close(); + XWPFTable table = wordTableEditorUtil.getTable( + document, + mainHeading, + subHeading, + onlyMainHeading, + tablePosition + ); + if(table == null){ + throw new NoSuchElementException("Table not found"); + } + int rowIndex = wordTableEditorUtil.getRowIndex(table,column,value); + if(rowIndex == -1){ + throw new NoSuchElementException("Specified row not found"); + } + if(operation.equals("Delete")){ + table.removeRow(rowIndex); + FileOutputStream fos = new FileOutputStream(documentPath); + document.write(fos); + fos.close(); + document.close(); + result = true; + this.successMessage = "Row deletion successful"; + }else{ + String rowData = "Selected row data : "; + for(XWPFTableCell cell : table.getRow(rowIndex).getTableCells()){ + rowData = rowData.concat(cell.getText()+", "); + } + result = true; + this.successMessage = rowData; + } + + }catch( NoSuchElementException | InputMismatchException e){ + this.errorMessage = e.getMessage(); + } + catch(IOException | RuntimeException e){ + this.errorMessage = e.getMessage(); + } + return result; + } +} diff --git a/external_word_document_table_editor/src/main/java/utility/WordTableEditorUtil.java b/external_word_document_table_editor/src/main/java/utility/WordTableEditorUtil.java new file mode 100644 index 0000000..410a43b --- /dev/null +++ b/external_word_document_table_editor/src/main/java/utility/WordTableEditorUtil.java @@ -0,0 +1,156 @@ +package utility; +import java.io.IOException; +import java.security.InvalidParameterException; +import java.util.InputMismatchException; +import java.util.Iterator; +import java.util.List; +import java.util.NoSuchElementException; + +import org.apache.poi.xwpf.usermodel.*; +import org.apache.xmlbeans.XmlException; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow; +public class WordTableEditorUtil { + + public XWPFTable getTable( + XWPFDocument document, + String targetMainHeading, + String targetHeading, + boolean onlyMainHeading, + int tablePosition + ){ + boolean mainHeadingFound = false; + boolean headingFound = false; + int tableCount = 0; + XWPFTable table = null; + if(tablePosition < 1){ + throw new InvalidParameterException("Invalid table position. Must be greater than 0"); + } + Iterator elements = document.getBodyElementsIterator(); + while (elements.hasNext()) { + IBodyElement element = elements.next(); + if (element instanceof XWPFParagraph) { + XWPFParagraph paragraph = (XWPFParagraph) element; + String heading = paragraph.getText().trim(); + if(mainHeadingFound && heading.equals(targetHeading)){ + headingFound = true; + }else if (heading.equals(targetMainHeading)) { + mainHeadingFound = true; + } + }else if (element instanceof XWPFTable) { + String heading = ((XWPFTable)element).getRow(0).getCell(0).getText().trim(); + if (headingFound || (onlyMainHeading && mainHeadingFound)) { + tableCount++; + if(tableCount == tablePosition) { + table = (XWPFTable) element; + break; + } + }else if(mainHeadingFound && heading.equals(targetHeading)){ + headingFound = true; + }else if(heading.equals(targetMainHeading)){ + mainHeadingFound = true; + } + } + } + if (onlyMainHeading && !mainHeadingFound) { + throw new NoSuchElementException("Heading not found in the document."); + } + if(tablePosition != tableCount){ + throw new InvalidParameterException("Invalid table position ." + tableCount); + } + return table; + } + + + public int getRowIndex( + XWPFTable table, + String columnIdentifier, + String rowIdentifier + ){ + int rowIndex = -1; + int columnIndex = getHeaderIndex(table.getRow(0),columnIdentifier); + if(columnIndex == -1){ + return rowIndex; + } + for(int index = 0;index < table.getNumberOfRows();index++) { + if (table.getRow(index).getCell(columnIndex).getText().trim().equals(rowIdentifier)) { + rowIndex = index; + break; + } + } + return rowIndex; + } + public boolean tableCellEditor( + XWPFTableCell cell, + String operation, + String data + ){ + boolean result = true; + if(cell != null){ + switch (operation){ + case "Clear": + for (XWPFParagraph paragraph : cell.getParagraphs()) { + for (XWPFRun run : paragraph.getRuns()) { + run.setText("", 0); + } + } + break; + case "Modify": + for (XWPFParagraph paragraph : cell.getParagraphs()) { + for (XWPFRun run : paragraph.getRuns()) { + run.setText("", 0); + } + } + cell.setText(data); + break; + case "Append": + XWPFParagraph lastParagraph = null; + for (XWPFParagraph paragraph : cell.getParagraphs()) { + lastParagraph = paragraph; + } + if (lastParagraph != null) { + lastParagraph.createRun().setText(" "+data); + } else { + lastParagraph = cell.addParagraph(); + lastParagraph.createRun().setText(" "+data); + } + break; + case "Verify": + if(!cell.getText().trim().equals(data)){ + result = false; + } + break; + } + }else{ + throw new NoSuchElementException("Target cell not found"); + } + return result; + } + public XWPFTableCell getTableCell( + XWPFTable table, + String changeColumnIdentifier, + String columnIdentifier, + String rowIdentifier + ) { + XWPFTableRow headerRow = table.getRow(0); + XWPFTableCell targetCell = null; + int columnIndex = getHeaderIndex(headerRow, columnIdentifier); + int changeColumnIndex = getHeaderIndex(headerRow, changeColumnIdentifier); + if(columnIndex == -1 || changeColumnIndex == -1){ + throw new RuntimeException("Specified cell not found"); + } + for(XWPFTableRow row : table.getRows()){ + if(row.getCell(columnIndex).getText().trim().equals(rowIdentifier)){ + targetCell = row.getCell(changeColumnIndex); + } + } + return targetCell; + } + private static int getHeaderIndex(XWPFTableRow headerRow, String header){ + for(int index = 0;index < headerRow.getTableCells().size();index++){ + if(headerRow.getCell(index).getText().trim().equals(header)){ + return index; + } + } + return -1; + } +} diff --git a/external_word_document_table_editor/src/main/resources/testsigma-sdk.properties b/external_word_document_table_editor/src/main/resources/testsigma-sdk.properties new file mode 100644 index 0000000..170a2f9 --- /dev/null +++ b/external_word_document_table_editor/src/main/resources/testsigma-sdk.properties @@ -0,0 +1 @@ +testsigma-sdk.api.key=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI3MGU0NmE4NC05MzI5LTY3YjItZmIyYi1mOGM1MmNlY2FiNWYiLCJ1bmlxdWVJZCI6IjczNCIsImV4dGVybmFsVGVuYW50SWQiOiIzMzcyIn0.2mdRrIiOTWN3RTeT2E-F1q77Fw7bul9g7v0cO9KzcTd7DznyJhO8RLc1o5T0JdBQTfSahnmjXDPP3v6LZKOeTg \ No newline at end of file diff --git a/mobile_network_operations/.DS_Store b/mobile_network_operations/.DS_Store new file mode 100644 index 0000000..587ecd8 Binary files /dev/null and b/mobile_network_operations/.DS_Store differ