Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
110 changes: 110 additions & 0 deletions windows_advanced_actions/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.testsigma.addons</groupId>
<artifactId>windows_advanced_actions</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<testsigma.sdk.version>1.2.24_cloud</testsigma.sdk.version>
<junit.jupiter.version>5.8.0-M1</junit.jupiter.version>
<testsigma.addon.maven.plugin>1.0.0</testsigma.addon.maven.plugin>
<maven.source.plugin.version>3.2.1</maven.source.plugin.version>
<lombok.version>1.18.30</lombok.version>

</properties>

<dependencies>
<dependency>
<groupId>com.testsigma</groupId>
<artifactId>testsigma-java-sdk</artifactId>
<version>${testsigma.sdk.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.33.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.appium/java-client -->
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>9.4.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.13.0</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.17.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.melloware/jintellitype -->
<dependency>
<groupId>com.melloware</groupId>
<artifactId>jintellitype</artifactId>
<version>1.3.9</version>
</dependency>

</dependencies>
<build>
<finalName>windows_advanced_actions</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${maven.source.plugin.version}</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.testsigma.addons.windowsAdvanced;

import com.testsigma.sdk.ApplicationType;
import com.testsigma.sdk.Result;
import com.testsigma.sdk.WindowsAdvancedAction;
import com.testsigma.sdk.annotation.Action;
import com.testsigma.sdk.annotation.TestData;
import lombok.Data;
import org.apache.commons.lang3.exception.ExceptionUtils;

import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.awt.event.KeyEvent;


@Data
@Action(actionText = "Enter data test-data using keyboard",
description = "This action allows you to enter data into a field using the keyboard.",
applicationType = ApplicationType.WINDOWS_ADVANCED,
displayName = "EnterData"
)
public class EnterDataUsingKeyboard extends WindowsAdvancedAction {
@TestData(reference = "test-data")
private com.testsigma.sdk.TestData testData;

@Override
public com.testsigma.sdk.Result execute() {
Result result = Result.SUCCESS;
try {
// Instantiate the Robot Class
Robot robot = new Robot();
StringSelection stringSelection = new StringSelection(testData.getValue().toString());
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable data = clipboard.getContents(null);
clipboard.setContents(stringSelection, null);
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
Thread.sleep(500);
clipboard.setContents(data, null);
setSuccessMessage("Given data entered successfully on the given image");
} catch (Exception e) {
result = Result.FAILED;
setErrorMessage("An error occurred while initializing the Robot class: " + e.getMessage());
logger.debug("Error initializing Robot class: " + ExceptionUtils.getStackTrace(e));
return result;
}
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.testsigma.addons.windowsAdvanced;

import com.testsigma.sdk.Result;
import com.testsigma.sdk.WindowsAdvancedAction;
import com.testsigma.sdk.annotation.Action;
import com.testsigma.sdk.annotation.TestData;
import lombok.Data;
import org.apache.commons.lang3.exception.ExceptionUtils;

import java.awt.*;
import java.awt.event.KeyEvent;


@Data
@Action(actionText = "Press Function Key key-type",
description = "This action allows you to press a function key on the keyboard.",
applicationType = com.testsigma.sdk.ApplicationType.WINDOWS_ADVANCED,
displayName = "PressFunctionKey")
public class PressFunctionKey extends WindowsAdvancedAction {

@TestData(reference = "key-type",allowedValues = {"F1", "F2", "F3", "F4", "F5", "F6",
"F7", "F8", "F9", "F10", "F11", "F12"})
private com.testsigma.sdk.TestData keyType;

@Override
public Result execute() {
Result result = Result.SUCCESS;
try {
// Instantiate the Robot Class
Robot robot = new java.awt.Robot();
String key = keyType.getValue().toString();

// Convert the function key to its corresponding KeyEvent constant
int keyCode = KeyEvent.class.getField("VK_" + key).getInt(null);

// Press and release the function key
robot.keyPress(keyCode);
robot.keyRelease(keyCode);

setSuccessMessage("Successfully pressed the " + key + " key.");
} catch (Exception e) {
setErrorMessage("An error occurred while pressing the function key: " + e.getMessage());
logger.debug("Error pressing function key: " + ExceptionUtils.getStackTrace(e));
result = Result.FAILED; }
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.testsigma.addons.windowsAdvanced;

import com.testsigma.addons.windowsAdvanced.utils.KeyboardUtils;
import com.testsigma.sdk.Result;
import com.testsigma.sdk.WindowsAdvancedAction;
import com.testsigma.sdk.annotation.Action;
import com.testsigma.sdk.annotation.TestData;
import lombok.Data;
import org.apache.commons.lang3.exception.ExceptionUtils;

import java.awt.*;

@Data
@Action(actionText = "Press a modifier key key-type",
description = "This action allows you to press a modifier key on the keyboard.",
applicationType = com.testsigma.sdk.ApplicationType.WINDOWS_ADVANCED,
displayName = "PressModifierKey")
public class PressModifierKey extends WindowsAdvancedAction {

@TestData(reference = "key-type", allowedValues = {"Alt", "Ctrl", "Enter", "Shift", "Tab", "WINDOW"})
private com.testsigma.sdk.TestData keyType;

@Override
public Result execute() {
Result result = Result.SUCCESS;
try {
// Instantiate the Robot Class
Robot robot = new Robot();
String key = keyType.getValue().toString();

// Convert the modifier key to its corresponding KeyEvent constant
int keyCode = KeyboardUtils.getModifierKeyCode(key);

// Press and release the modifier key
robot.keyPress(keyCode);
robot.keyRelease(keyCode);

setSuccessMessage("Successfully pressed the " + key + " key.");
} catch (Exception e) {
setErrorMessage("An error occurred while pressing the modifier key: " + e.getMessage());
logger.debug("Error pressing modifier key: " + ExceptionUtils.getStackTrace(e));
result = Result.FAILED;
}
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.testsigma.addons.windowsAdvanced;

import com.testsigma.addons.windowsAdvanced.utils.KeyboardUtils;
import com.testsigma.sdk.Result;
import com.testsigma.sdk.WindowsAdvancedAction;
import com.testsigma.sdk.annotation.Action;
import com.testsigma.sdk.annotation.TestData;
import lombok.Data;
import org.apache.commons.lang3.exception.ExceptionUtils;

import java.awt.*;

@Data
@Action(actionText = "Press a modifier key key-type with an alphanumeric key alphanumeric-key",
description = "This action allows you to press a modifier key with an alphanumeric key on the keyboard.",
applicationType = com.testsigma.sdk.ApplicationType.WINDOWS_ADVANCED,
displayName = "PressModifierKeyWithAlphanumericKey")
public class PressModifierKeyWithAlphanumericKey extends WindowsAdvancedAction {

@TestData(reference = "key-type", allowedValues = {"Alt", "Ctrl", "Enter", "Shift", "Tab", "WINDOW"})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add other modifier keys

private com.testsigma.sdk.TestData keyType;

@TestData(reference = "alphanumeric-key", allowedValues = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
"K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
"U", "V", "W", "X", "Y", "Z",
"Space", "Comma", "Period", "Semicolon", "Colon", "Exclamation", "Question",
"At", "Hash", "Dollar", "Percent", "Caret", "Ampersand", "Asterisk",
"Left_Parenthesis", "Right_Parenthesis", "Minus", "Plus", "Equals",
"Left_Bracket", "Right_Bracket", "Backslash", "Forward_Slash", "Pipe",
"Left_Brace", "Right_Brace", "Tilde", "Backtick", "Quote", "Double_Quote"})
private com.testsigma.sdk.TestData alphanumericKey;

@Override
public Result execute() {
Result result = Result.SUCCESS;
try {
// Instantiate the Robot Class
Robot robot = new Robot();
String modifierKey = keyType.getValue().toString();
String alphanumericKeyValue = alphanumericKey.getValue().toString();

// Convert the modifier key to its corresponding KeyEvent constant
int modifierKeyCode = KeyboardUtils.getModifierKeyCode(modifierKey);
int alphanumericKeyCode = KeyboardUtils.getAlphanumericKeyCode(alphanumericKeyValue);

// Press modifier key, then alphanumeric key
robot.keyPress(modifierKeyCode);
robot.keyPress(alphanumericKeyCode);

// Small delay
Thread.sleep(100);

// Release keys in reverse order
robot.keyRelease(alphanumericKeyCode);
robot.keyRelease(modifierKeyCode);

setSuccessMessage("Successfully pressed " + modifierKey + " + " + alphanumericKeyValue + " keys.");
} catch (Exception e) {
setErrorMessage("An error occurred while pressing the modifier key with alphanumeric key: " + e.getMessage());
logger.debug("Error pressing modifier key with alphanumeric key: " + ExceptionUtils.getStackTrace(e));
result = Result.FAILED;
}
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.testsigma.addons.windowsAdvanced;

import com.testsigma.addons.windowsAdvanced.utils.KeyboardUtils;
import com.testsigma.sdk.Result;
import com.testsigma.sdk.WindowsAdvancedAction;
import com.testsigma.sdk.annotation.Action;
import com.testsigma.sdk.annotation.TestData;
import lombok.Data;
import org.apache.commons.lang3.exception.ExceptionUtils;

import java.awt.*;

@Data
@Action(actionText = "Press a modifier key key-type with a specific key test-data",
description = "This action allows you to press a modifier key with a specific key on the keyboard.",
applicationType = com.testsigma.sdk.ApplicationType.WINDOWS_ADVANCED,
displayName = "PressModifierKeyWithSpecificKey")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to : PressModifierKeyWithGivenKey

public class PressModifierKeyWithSpecificKey extends WindowsAdvancedAction {

@TestData(reference = "key-type", allowedValues = {"Alt", "Ctrl", "Enter", "Shift", "Tab", "WINDOW"})
private com.testsigma.sdk.TestData keyType;

@TestData(reference = "test-data", allowedValues = {"Space", "Backspace", "Delete", "Escape", "Home", "End",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This testdata is a user input. Do not give allowed values for this.

"Page_Up", "Page_Down", "Insert", "F1", "F2", "F3", "F4",
"F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12"})
private com.testsigma.sdk.TestData testData;

@Override
public Result execute() {
Result result = Result.SUCCESS;
try {
// Instantiate the Robot Class
Robot robot = new Robot();
String modifierKey = keyType.getValue().toString();
String specificKey = testData.getValue().toString();

// Convert the modifier key to its corresponding KeyEvent constant
int modifierKeyCode = KeyboardUtils.getModifierKeyCode(modifierKey);
int specificKeyCode = KeyboardUtils.getSpecificKeyCode(specificKey);

// Press modifier key, then specific key
robot.keyPress(modifierKeyCode);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be minimum of 10 Millisecs between eack key event

robot.keyPress(specificKeyCode);

// Small delay
Thread.sleep(100);

// Release keys in reverse order
robot.keyRelease(specificKeyCode);
robot.keyRelease(modifierKeyCode);

setSuccessMessage("Successfully pressed " + modifierKey + " + " + specificKey + " keys.");
} catch (Exception e) {
setErrorMessage("An error occurred while pressing the modifier key with specific key: " + e.getMessage());
logger.debug("Error pressing modifier key with specific key: " + ExceptionUtils.getStackTrace(e));
result = Result.FAILED;
}
return result;
}
}
Loading