Skip to content

Commit

Permalink
Feat/TE-16149,TE-16771 : Added another nlp with press key multiple ti…
Browse files Browse the repository at this point in the history
…mes (#49)

* Feat[TE-16149]: Android TV operations addon with press keys nlps

* Feat[TE-16771]: Added another nlp with key press for multiple times
  • Loading branch information
SunilGembali authored Feb 23, 2024
1 parent 3518a3e commit a17effa
Show file tree
Hide file tree
Showing 5 changed files with 420 additions and 0 deletions.
102 changes: 102 additions & 0 deletions android_tv_operations/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?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>android_tv_operations</artifactId>
<version>1.0.2</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.6_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.20</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.14.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.appium/java-client -->
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>9.0.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.14.0</version>
</dependency>

</dependencies>
<build>
<finalName>android_tv_operations</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,134 @@
package com.testsigma.addons.android;

import io.appium.java_client.android.nativekey.AndroidKey;

public class KeyUtil {

public static AndroidKey getKey(String value) {
AndroidKey androidKey;
switch (value) {
case "Up":
androidKey = AndroidKey.DPAD_UP;
break;
case "Down":
androidKey = AndroidKey.DPAD_DOWN;
break;
case "Left":
androidKey = AndroidKey.DPAD_LEFT;
break;
case "Right":
androidKey = AndroidKey.DPAD_RIGHT;
break;
case "Guide":
androidKey = AndroidKey.GUIDE;
break;
case "Tv-contents-menu":
androidKey = AndroidKey.TV_CONTENTS_MENU;
break;
case "Menu":
androidKey = AndroidKey.MENU;
break;
case "Info":
androidKey = AndroidKey.INFO;
break;
case "Ch+":
androidKey = AndroidKey.CHANNEL_UP;
break;
case "Ch-":
androidKey = AndroidKey.CHANNEL_DOWN;
break;
case "Back":
androidKey = AndroidKey.BACK;
break;
case "Ok":
androidKey = AndroidKey.DPAD_CENTER;
break;
case "NUM_0":
androidKey = AndroidKey.DIGIT_0;
break;
case "NUM_1":
androidKey = AndroidKey.DIGIT_1;
break;
case "NUM_2":
androidKey = AndroidKey.DIGIT_2;
break;
case "NUM_3":
androidKey = AndroidKey.DIGIT_3;
break;
case "NUM_4":
androidKey = AndroidKey.DIGIT_4;
break;
case "NUM_5":
androidKey = AndroidKey.DIGIT_5;
break;
case "NUM_6":
androidKey = AndroidKey.DIGIT_6;
break;
case "NUM_7":
androidKey = AndroidKey.DIGIT_7;
break;
case "NUM_8":
androidKey = AndroidKey.DIGIT_8;
break;
case "NUM_9":
androidKey = AndroidKey.DIGIT_9;
break;
case "Volume-Up":
androidKey = AndroidKey.VOLUME_UP;
break;
case "Volume-Down":
androidKey = AndroidKey.VOLUME_DOWN;
break;
case "PlayPause":
androidKey = AndroidKey.MEDIA_PLAY_PAUSE;
break;
case "Rewind":
androidKey = AndroidKey.MEDIA_REWIND;
break;
case "Forward":
androidKey = AndroidKey.MEDIA_FAST_FORWARD;
break;
case "Home":
androidKey = AndroidKey.HOME;
break;
case "Power":
androidKey = AndroidKey.POWER;
break;
case "App-switch":
androidKey = AndroidKey.APP_SWITCH;
break;
case "Soft-left":
androidKey = AndroidKey.SOFT_LEFT;
break;
case "Soft-right":
androidKey = AndroidKey.SOFT_RIGHT;
break;
case "Navigate-previous":
androidKey = AndroidKey.NAVIGATE_PREVIOUS;
break;
case "Navigate-next":
androidKey = AndroidKey.NAVIGATE_NEXT;
break;
case "Navigate-in":
androidKey = AndroidKey.NAVIGATE_IN;
break;
case "Navigate-out":
androidKey = AndroidKey.NAVIGATE_OUT;
break;
case "Stem-1-Netflix":
androidKey = AndroidKey.STEM_1;
break;
case "Stem-2":
androidKey = AndroidKey.STEM_2;
break;
case "Stem-3":
androidKey = AndroidKey.STEM_3;
break;

default:
throw new IllegalArgumentException("Invalid key value");
}

return androidKey;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.testsigma.addons.android;

import com.testsigma.sdk.AndroidAction;
import com.testsigma.sdk.ApplicationType;
import com.testsigma.sdk.Result;
import com.testsigma.sdk.annotation.Action;
import com.testsigma.sdk.annotation.TestData;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.nativekey.AndroidKey;
import io.appium.java_client.android.nativekey.KeyEvent;
import lombok.Data;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.openqa.selenium.NoSuchElementException;


@Data
@Action(actionText = "Long press Key key-value in TV Remote",
description = "Long press the given key in the android tv remote",
applicationType = ApplicationType.ANDROID)
public class LongPressKeyOnRemote extends AndroidAction {

@TestData(
reference = "key-value",
allowedValues =
{
"Ok"
}
)
private com.testsigma.sdk.TestData key;

@Override
protected Result execute() throws NoSuchElementException {
Result result = Result.SUCCESS;
try {
logger.info("Initiating execution");
AndroidDriver androidDriver = (AndroidDriver)this.driver;
AndroidKey androidKey = KeyUtil.getKey(key.getValue().toString());
androidDriver.longPressKey(new KeyEvent(androidKey));
setSuccessMessage("Pressed the key successfully");
} catch (IllegalArgumentException e) {
logger.info("Invalid key value");
logger.info("Error occurred: "+ExceptionUtils.getStackTrace(e));
result = Result.FAILED;
setErrorMessage("Invalid key value");
} catch (Exception e) {
logger.info("Something went wrong while pressing the given key");
logger.info("Error occurred: "+ExceptionUtils.getStackTrace(e));
result = Result.FAILED;
setErrorMessage("Unable to press the given key");
}
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.testsigma.addons.android;

import com.testsigma.sdk.AndroidAction;
import com.testsigma.sdk.ApplicationType;
import com.testsigma.sdk.Result;
import com.testsigma.sdk.annotation.Action;
import com.testsigma.sdk.annotation.TestData;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.nativekey.AndroidKey;
import io.appium.java_client.android.nativekey.KeyEvent;
import lombok.Data;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.openqa.selenium.NoSuchElementException;

@Data
@Action(actionText = "Press Key key-value for test-data times in TV Remote with wait time test-data1 seconds between the key press",
description = "Press the given key in the android tv remote with given no of times with given wait time between the key press",
applicationType = ApplicationType.ANDROID)
public class PressKeyMultipleTimes extends AndroidAction {

@TestData(
reference = "key-value",
allowedValues =
{
"Up", "Down", "Left", "Right", "Guide", "Tv-contents-menu",
"Menu", "Info", "Ch+", "Ch-", "Back", "Ok",
"NUM_0", "NUM_1", "NUM_2", "NUM_3", "NUM_4", "NUM_5",
"NUM_6", "NUM_7", "NUM_8", "NUM_9", "Volume-Up", "Volume-Down",
"PlayPause", "Rewind", "Forward", "Home", "Power", "App-switch",
"Soft-left", "Soft-right", "Navigate-previous", "Navigate-next", "Navigate-in", "Navigate-out",
"Stem-1-Netflix", "Stem-2", "Stem-3"
}
)
private com.testsigma.sdk.TestData key;

@TestData(reference = "test-data")
private com.testsigma.sdk.TestData testData;

@TestData(reference = "test-data1")
private com.testsigma.sdk.TestData testData1;

@Override
protected Result execute() throws NoSuchElementException {
Result result = Result.SUCCESS;
try {
logger.info("Initiating execution");
AndroidDriver androidDriver = (AndroidDriver)this.driver;
int noOfTimes = Integer.parseInt(testData.getValue().toString());
int waitTime = Integer.parseInt(testData1.getValue().toString()) * 1000;
logger.info("Wait time:" + waitTime + "milliseconds");
AndroidKey androidKey = KeyUtil.getKey(key.getValue().toString());
for (int i = 0; i < noOfTimes; i++) {
androidDriver.pressKey(new KeyEvent(androidKey));
logger.info("Press key event done");
Thread.sleep(waitTime);
}
setSuccessMessage("Pressed the key successfully");
} catch (IllegalArgumentException e) {
logger.info("Invalid key value");
logger.info("Error occurred: "+ExceptionUtils.getStackTrace(e));
result = Result.FAILED;
setErrorMessage("Invalid key value");
} catch (Exception e) {
logger.info("Something went wrong while pressing the given key");
logger.info("Error occurred: "+ExceptionUtils.getStackTrace(e));
result = Result.FAILED;
setErrorMessage("Unable to press the given key");
}
return result;
}
}
Loading

0 comments on commit a17effa

Please sign in to comment.