Skip to content

Commit 8f36491

Browse files
Merge pull request #376 from testsigmahq/feat/CUS-12011-Added-table-row-and-column-index-lookup-actions-with-exact-and-contains-match
feat/CUS-12011-Added table row and column index lookup actions with exact and contains match
2 parents a23e6cb + 22bafeb commit 8f36491

10 files changed

Lines changed: 614 additions & 0 deletions

table_actions/pom.xml

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project
3+
xmlns="http://maven.apache.org/POM/4.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
6+
<modelVersion>4.0.0</modelVersion>
7+
<groupId>com.testsigma.addons</groupId>
8+
<artifactId>table_actions</artifactId>
9+
<version>1.0.0</version>
10+
<packaging>jar</packaging>
11+
12+
<properties>
13+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
14+
<maven.compiler.source>11</maven.compiler.source>
15+
<maven.compiler.target>11</maven.compiler.target>
16+
<testsigma.sdk.version>1.2.26_cloud</testsigma.sdk.version>
17+
<junit.jupiter.version>5.12.1</junit.jupiter.version>
18+
<testsigma.addon.maven.plugin>1.0.0</testsigma.addon.maven.plugin>
19+
<maven.source.plugin.version>3.2.1</maven.source.plugin.version>
20+
<lombok.version>1.18.30</lombok.version>
21+
<testng.version>7.10.2</testng.version>
22+
<selenium.version>4.33.0</selenium.version>
23+
<appium.java.client.version>9.4.0</appium.java.client.version>
24+
<jackson.version>2.13.0</jackson.version>
25+
<maven.shade.plugin.version>3.2.4</maven.shade.plugin.version>
26+
27+
</properties>
28+
29+
<dependencies>
30+
<dependency>
31+
<groupId>com.testsigma</groupId>
32+
<artifactId>testsigma-java-sdk</artifactId>
33+
<version>${testsigma.sdk.version}</version>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.projectlombok</groupId>
37+
<artifactId>lombok</artifactId>
38+
<version>${lombok.version}</version>
39+
<optional>true</optional>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.junit.jupiter</groupId>
43+
<artifactId>junit-jupiter-api</artifactId>
44+
<version>${junit.jupiter.version}</version>
45+
<scope>test</scope>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.testng</groupId>
49+
<artifactId>testng</artifactId>
50+
<version>${testng.version}</version>
51+
</dependency>
52+
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
53+
<dependency>
54+
<groupId>org.seleniumhq.selenium</groupId>
55+
<artifactId>selenium-java</artifactId>
56+
<version>${selenium.version}</version>
57+
</dependency>
58+
<!-- https://mvnrepository.com/artifact/io.appium/java-client -->
59+
<dependency>
60+
<groupId>io.appium</groupId>
61+
<artifactId>java-client</artifactId>
62+
<version>${appium.java.client.version}</version>
63+
</dependency>
64+
<dependency>
65+
<groupId>com.fasterxml.jackson.core</groupId>
66+
<artifactId>jackson-annotations</artifactId>
67+
<version>${jackson.version}</version>
68+
</dependency>
69+
<dependency>
70+
<groupId>org.apache.commons</groupId>
71+
<artifactId>commons-lang3</artifactId>
72+
<version>3.18.0</version>
73+
</dependency>
74+
</dependencies>
75+
<build>
76+
<finalName>table_actions</finalName>
77+
<plugins>
78+
<plugin>
79+
<groupId>org.apache.maven.plugins</groupId>
80+
<artifactId>maven-shade-plugin</artifactId>
81+
<version>${maven.shade.plugin.version}</version>
82+
<executions>
83+
<execution>
84+
<phase>package</phase>
85+
<goals>
86+
<goal>shade</goal>
87+
</goals>
88+
</execution>
89+
</executions>
90+
</plugin>
91+
<plugin>
92+
<groupId>org.apache.maven.plugins</groupId>
93+
<artifactId>maven-source-plugin</artifactId>
94+
<version>${maven.source.plugin.version}</version>
95+
<executions>
96+
<execution>
97+
<id>attach-sources</id>
98+
<goals>
99+
<goal>jar</goal>
100+
</goals>
101+
</execution>
102+
</executions>
103+
</plugin>
104+
</plugins>
105+
</build>
106+
</project>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package com.testsigma.addons.web;
2+
3+
import com.testsigma.sdk.WebAction;
4+
import com.testsigma.sdk.ApplicationType;
5+
import com.testsigma.sdk.annotation.Action;
6+
import com.testsigma.sdk.annotation.TestData;
7+
import com.testsigma.sdk.annotation.Element;
8+
import com.testsigma.sdk.annotation.RunTimeData;
9+
import lombok.Data;
10+
import org.apache.commons.lang3.exception.ExceptionUtils;
11+
import org.openqa.selenium.NoSuchElementException;
12+
import org.openqa.selenium.WebElement;
13+
14+
import java.util.ArrayList;
15+
import java.util.List;
16+
17+
@Data
18+
@Action(actionText = "Store the ALL column numbers in the table element-locator which has the exact text test-data in ANY row into the variable variable-name",
19+
description = "Stores all column numbers in a table element that contains the text in any row into runtime variable",
20+
applicationType = ApplicationType.WEB,
21+
useCustomScreenshot = false)
22+
public class StoreAllColumnIndexesWithExactMatchTextInAnyRowAction extends WebAction {
23+
24+
@TestData(reference = "test-data")
25+
private com.testsigma.sdk.TestData text;
26+
27+
@TestData(reference = "variable-name", isRuntimeVariable = true)
28+
private com.testsigma.sdk.TestData variableName;
29+
30+
@Element(reference = "element-locator")
31+
private com.testsigma.sdk.Element element;
32+
33+
@RunTimeData
34+
private com.testsigma.sdk.RunTimeData runTimeData;
35+
36+
@Override
37+
public com.testsigma.sdk.Result execute() throws NoSuchElementException {
38+
com.testsigma.sdk.Result result = com.testsigma.sdk.Result.SUCCESS;
39+
logger.info("Initiating execution");
40+
try {
41+
List<Integer> columnIndexes = getAllColumnIndexesOfText(text.getValue().toString(), element.getElement());
42+
String runTimeVarValue = columnIndexes.toString().replaceAll("\\[|\\]", "");
43+
runTimeData.setValue(runTimeVarValue);
44+
runTimeData.setKey(variableName.getValue().toString());
45+
setSuccessMessage("Column numbers stored successfully in variable: " + variableName.getValue().toString() + " . " + variableName.getValue().toString() + " = " + runTimeVarValue);
46+
} catch (Exception e) {
47+
logger.warn("Error occurred while executing action: " + ExceptionUtils.getStackTrace(e));
48+
setErrorMessage("Error occurred while executing action: " + ExceptionUtils.getStackTrace(e));
49+
return com.testsigma.sdk.Result.FAILED;
50+
}
51+
return result;
52+
}
53+
54+
private List<Integer> getAllColumnIndexesOfText(String text, WebElement table) throws Exception {
55+
List<WebElement> rows = TableActionUtils.getRows(table);
56+
List<Integer> indexes = new ArrayList<>();
57+
for (WebElement row : rows) {
58+
List<WebElement> cells = TableActionUtils.getCellsOfRow(row);
59+
for (int j = 0; j < cells.size(); j++) {
60+
if (cells.get(j).getText().trim().equals(text.trim()) && !indexes.contains(j + 1)) {
61+
indexes.add(j + 1);
62+
}
63+
}
64+
}
65+
if (indexes.isEmpty()) {
66+
throw new Exception("Column with specified text is not found in given table");
67+
} else {
68+
return indexes;
69+
}
70+
}
71+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.testsigma.addons.web;
2+
3+
import com.testsigma.sdk.WebAction;
4+
import com.testsigma.sdk.ApplicationType;
5+
import com.testsigma.sdk.annotation.Action;
6+
import com.testsigma.sdk.annotation.TestData;
7+
import com.testsigma.sdk.annotation.Element;
8+
import com.testsigma.sdk.annotation.RunTimeData;
9+
import lombok.Data;
10+
import org.apache.commons.lang3.exception.ExceptionUtils;
11+
import org.openqa.selenium.NoSuchElementException;
12+
import org.openqa.selenium.WebElement;
13+
14+
import java.util.ArrayList;
15+
import java.util.List;
16+
17+
@Data
18+
@Action(actionText = "Store the ALL row numbers in the table element-locator which has the exact text test-data in ANY column into the variable variable-name",
19+
description = "Stores all row numbers in a table element that contains the text in any column into runtime variable",
20+
applicationType = ApplicationType.WEB,
21+
useCustomScreenshot = false)
22+
public class StoreAllRowIndexesWithExactMatchTextInAnyColumnAction extends WebAction {
23+
24+
@TestData(reference = "test-data")
25+
private com.testsigma.sdk.TestData text;
26+
27+
@TestData(reference = "variable-name", isRuntimeVariable = true)
28+
private com.testsigma.sdk.TestData variableName;
29+
30+
@Element(reference = "element-locator")
31+
private com.testsigma.sdk.Element element;
32+
33+
@RunTimeData
34+
private com.testsigma.sdk.RunTimeData runTimeData;
35+
36+
@Override
37+
public com.testsigma.sdk.Result execute() throws NoSuchElementException {
38+
com.testsigma.sdk.Result result = com.testsigma.sdk.Result.SUCCESS;
39+
logger.info("Initiating execution");
40+
try {
41+
List<Integer> rowIndexes = getAllRowIndexesOfText(text.getValue().toString(), element.getElement());
42+
String runTimeVarValue = rowIndexes.toString().replaceAll("\\[|\\]", "");
43+
runTimeData.setValue(runTimeVarValue);
44+
runTimeData.setKey(variableName.getValue().toString());
45+
setSuccessMessage("Row number stored successfully in variable: " + variableName.getValue().toString() + " . " + variableName.getValue().toString() + " = " + runTimeVarValue);
46+
} catch (Exception e) {
47+
logger.warn("Error occurred while executing action: " + ExceptionUtils.getStackTrace(e));
48+
setErrorMessage("Error occurred while executing action: " + ExceptionUtils.getStackTrace(e));
49+
return com.testsigma.sdk.Result.FAILED;
50+
}
51+
return result;
52+
}
53+
54+
private List<Integer> getAllRowIndexesOfText(String text, WebElement table) throws Exception {
55+
List<WebElement> rows = TableActionUtils.getRows(table);
56+
List<Integer> indexes = new ArrayList<>();
57+
for (int i = 0; i < rows.size(); i++) {
58+
List<WebElement> cells = TableActionUtils.getCellsOfRow(rows.get(i));
59+
for (WebElement cell : cells) {
60+
if (cell.getText().trim().equals(text.trim())) {
61+
indexes.add(i + 1);
62+
break;
63+
}
64+
}
65+
}
66+
if (indexes.isEmpty()) {
67+
throw new Exception("Row with specified text is not found in given table");
68+
} else {
69+
return indexes;
70+
}
71+
}
72+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.testsigma.addons.web;
2+
3+
import com.testsigma.sdk.WebAction;
4+
import com.testsigma.sdk.ApplicationType;
5+
import com.testsigma.sdk.annotation.Action;
6+
import com.testsigma.sdk.annotation.TestData;
7+
import com.testsigma.sdk.annotation.Element;
8+
import com.testsigma.sdk.annotation.RunTimeData;
9+
import lombok.Data;
10+
import org.apache.commons.lang3.exception.ExceptionUtils;
11+
import org.openqa.selenium.NoSuchElementException;
12+
import org.openqa.selenium.WebElement;
13+
14+
import java.util.List;
15+
16+
@Data
17+
@Action(actionText = "Store the column number in the table element-locator which contains the text test-data in row row-number into the variable variable-name",
18+
description = "Stores the column number in a table element whose cell in the specified row contains the text into runtime variable",
19+
applicationType = ApplicationType.WEB,
20+
useCustomScreenshot = false)
21+
public class StoreColumnIndexWithContainsTextInExactRowAction extends WebAction {
22+
23+
@TestData(reference = "test-data")
24+
private com.testsigma.sdk.TestData text;
25+
26+
@TestData(reference = "row-number")
27+
private com.testsigma.sdk.TestData rowNumber;
28+
29+
@TestData(reference = "variable-name", isRuntimeVariable = true)
30+
private com.testsigma.sdk.TestData variableName;
31+
32+
@Element(reference = "element-locator")
33+
private com.testsigma.sdk.Element element;
34+
35+
@RunTimeData
36+
private com.testsigma.sdk.RunTimeData runTimeData;
37+
38+
@Override
39+
public com.testsigma.sdk.Result execute() throws NoSuchElementException {
40+
com.testsigma.sdk.Result result = com.testsigma.sdk.Result.SUCCESS;
41+
logger.info("Initiating execution");
42+
try {
43+
int rowIndex = Integer.parseInt(rowNumber.getValue().toString());
44+
int columnIndex = getColumnIndexOfTextInRow(text.getValue().toString(), rowIndex, element.getElement());
45+
runTimeData.setValue(String.valueOf(columnIndex));
46+
runTimeData.setKey(variableName.getValue().toString());
47+
setSuccessMessage("Column number stored successfully in variable: " + variableName.getValue().toString() + " . " + variableName.getValue().toString() + " = " + columnIndex);
48+
} catch (Exception e) {
49+
logger.warn("Error occurred while executing action: " + ExceptionUtils.getStackTrace(e));
50+
setErrorMessage("Error occurred while executing action: " + ExceptionUtils.getStackTrace(e));
51+
return com.testsigma.sdk.Result.FAILED;
52+
}
53+
return result;
54+
}
55+
56+
private int getColumnIndexOfTextInRow(String text, int rowIndex, WebElement table) throws Exception {
57+
List<WebElement> rows = TableActionUtils.getRows(table);
58+
if (rowIndex <= 0 || rowIndex > rows.size()) {
59+
throw new Exception("Given row number is not valid");
60+
}
61+
List<WebElement> cells = TableActionUtils.getCellsOfRow(rows.get(rowIndex - 1));
62+
for (int j = 0; j < cells.size(); j++) {
63+
if (cells.get(j).getText().contains(text)) {
64+
return j + 1;
65+
}
66+
}
67+
throw new Exception("Column with specified text is not found in given row");
68+
}
69+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.testsigma.addons.web;
2+
3+
import com.testsigma.sdk.WebAction;
4+
import com.testsigma.sdk.ApplicationType;
5+
import com.testsigma.sdk.annotation.Action;
6+
import com.testsigma.sdk.annotation.TestData;
7+
import com.testsigma.sdk.annotation.Element;
8+
import com.testsigma.sdk.annotation.RunTimeData;
9+
import lombok.Data;
10+
import org.apache.commons.lang3.exception.ExceptionUtils;
11+
import org.openqa.selenium.NoSuchElementException;
12+
import org.openqa.selenium.WebElement;
13+
14+
import java.util.List;
15+
16+
@Data
17+
@Action(actionText = "Store the column number in the table element-locator which has the exact text test-data in row row-number into the variable variable-name",
18+
description = "Stores the column number in a table element that contains the text in the specified row into runtime variable",
19+
applicationType = ApplicationType.WEB,
20+
useCustomScreenshot = false)
21+
public class StoreColumnIndexWithExactMatchInExactRowTextAction extends WebAction {
22+
23+
@TestData(reference = "test-data")
24+
private com.testsigma.sdk.TestData text;
25+
26+
@TestData(reference = "row-number")
27+
private com.testsigma.sdk.TestData rowNumber;
28+
29+
@TestData(reference = "variable-name", isRuntimeVariable = true)
30+
private com.testsigma.sdk.TestData variableName;
31+
32+
@Element(reference = "element-locator")
33+
private com.testsigma.sdk.Element element;
34+
35+
@RunTimeData
36+
private com.testsigma.sdk.RunTimeData runTimeData;
37+
38+
@Override
39+
public com.testsigma.sdk.Result execute() throws NoSuchElementException {
40+
com.testsigma.sdk.Result result = com.testsigma.sdk.Result.SUCCESS;
41+
logger.info("Initiating execution");
42+
try {
43+
int rowIndex = Integer.parseInt(rowNumber.getValue().toString());
44+
int columnIndex = getColumnIndexOfTextInRow(text.getValue().toString(), rowIndex, element.getElement());
45+
runTimeData.setValue(String.valueOf(columnIndex));
46+
runTimeData.setKey(variableName.getValue().toString());
47+
setSuccessMessage("Column number stored successfully in variable: " + variableName.getValue().toString() + " . " + variableName.getValue().toString() + " = " + columnIndex);
48+
} catch (Exception e) {
49+
logger.warn("Error occurred while executing action: " + ExceptionUtils.getStackTrace(e));
50+
setErrorMessage("Error occurred while executing action: " + ExceptionUtils.getStackTrace(e));
51+
return com.testsigma.sdk.Result.FAILED;
52+
}
53+
return result;
54+
}
55+
56+
private int getColumnIndexOfTextInRow(String text, int rowIndex, WebElement table) throws Exception {
57+
List<WebElement> rows = TableActionUtils.getRows(table);
58+
if (rowIndex <= 0 || rowIndex > rows.size()) {
59+
throw new Exception("Given row number is not valid");
60+
}
61+
List<WebElement> cells = TableActionUtils.getCellsOfRow(rows.get(rowIndex - 1));
62+
for (int j = 0; j < cells.size(); j++) {
63+
if (cells.get(j).getText().trim().equals(text.trim())) {
64+
return j + 1;
65+
}
66+
}
67+
throw new Exception("Column with specified text is not found in given row");
68+
}
69+
}

0 commit comments

Comments
 (0)