-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat[TE-16771]: Added another nlp with key press for multiple times
- Loading branch information
1 parent
d2c62e3
commit ae21b15
Showing
5 changed files
with
209 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
android_tv_operations/src/main/java/com/testsigma/addons/android/KeyUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
android_tv_operations/src/main/java/com/testsigma/addons/android/PressKeyMultipleTimes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters