How to use AddonAction method of com.testsigma.automator.actions.AddonAction class

Best Testsigma code snippet using com.testsigma.automator.actions.AddonAction.AddonAction

Source:AddonAction.java Github

copy

Full Screen

1package com.testsigma.automator.actions;2import com.testsigma.automator.service.AddonService;3import com.testsigma.sdk.annotation.RunTimeData;4import com.testsigma.automator.constants.AddonActionParameterType;5import com.testsigma.automator.constants.ActionResult;6import com.testsigma.automator.drivers.DriverManager;7import com.testsigma.automator.entity.*;8import com.testsigma.automator.exceptions.AutomatorException;9import com.testsigma.automator.actions.constants.ErrorCodes;10import com.testsigma.automator.actions.exceptions.ElementNotDisplayedException;11import com.testsigma.automator.utilities.RuntimeDataProvider;12import lombok.Data;13import lombok.Getter;14import lombok.SneakyThrows;15import lombok.extern.log4j.Log4j2;16import org.apache.commons.lang3.ObjectUtils;17import org.apache.commons.lang3.StringUtils;18import org.apache.commons.lang3.reflect.FieldUtils;19import org.openqa.selenium.*;20import org.openqa.selenium.interactions.MoveTargetOutOfBoundsException;21import org.openqa.selenium.remote.UnreachableBrowserException;22import org.openqa.selenium.support.ui.UnexpectedTagNameException;23import java.io.IOException;24import java.lang.reflect.Field;25import java.lang.reflect.InvocationTargetException;26import java.lang.reflect.Method;27import java.util.LinkedList;28import java.util.Map;29@Data30@Log4j231public class AddonAction {32 private static final int MESSAGE_MAX_SIZE = 500;33 protected Exception exception;34 @Getter35 protected String errorMessage;36 @Getter37 protected String successMessage;38 protected ErrorCodes errorCode = ErrorCodes.GENERIC_ERROR;39 private TestCaseStepEntity testCaseStepEntity;40 private TestCaseStepResult result;41 private Class<?> elementClass;42 private Class<?> testDataClass;43 private Class<?> loggerClass;44 private Class<?> runTimeDataClass;45 private Class<?> clazz;46 private Object instance;47 private AddonService addonService;48 private String elementValue;49 private String by;50 private ElementPropertiesEntity elementPropertiesEntity;51 private Map<String, String> envSettings;52 private RuntimeDataProvider runtimeDataProvider;53 private LinkedList<ElementPropertiesEntity> addonElementPropertiesEntity;54 public AddonAction(TestCaseStepEntity testCaseStepEntity, TestCaseStepResult result,55 LinkedList<ElementPropertiesEntity> addonElementPropertiesEntity, Map<String, String> envSettings)56 throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException, IOException, ClassNotFoundException {57 this.testCaseStepEntity = testCaseStepEntity;58 this.result = result;59 this.addonService = AddonService.getInstance();60 this.addonElementPropertiesEntity = addonElementPropertiesEntity;61 this.envSettings = envSettings;62 this.loadClasses();63 }64 private void loadClasses() throws IOException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {65 AddonNaturalTextActionEntity entity = testCaseStepEntity.getAddonNaturalTextActionEntity();66 String jarFilePath = addonService.checkAndDownloadJar(entity.getClassPath(), entity.getModifiedHash());67 this.clazz = addonService.loadJarClass(jarFilePath, entity.getFullyQualifiedName(), true);68 this.instance = clazz.getDeclaredConstructor().newInstance();69 }70 private static Field getField(Class clazz, String fieldName)71 throws NoSuchFieldException {72 try {73 return clazz.getDeclaredField(fieldName);74 } catch (NoSuchFieldException e) {75 Class superClass = clazz.getSuperclass();76 if (superClass == null) {77 throw e;78 } else {79 return getField(superClass, fieldName);80 }81 }82 }83 public ActionResult execute() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {84 Method executeMethod = clazz.getDeclaredMethod("execute");85 executeMethod.setAccessible(true);86 Object returnValue = executeMethod.invoke(instance);87 return ActionResult.valueOf(returnValue.toString());88 }89 @SneakyThrows90 public ActionResult run() {91 ActionResult snippetResult;92 try {93 beforeExecute();94 snippetResult = execute();95 if (snippetResult == ActionResult.SUCCESS)96 setSuccessMessage();97 else98 setErrorMessage();99 return snippetResult;100 } catch (Exception e) {101 log.error(e.getMessage(), e);102 setException(new Exception(ObjectUtils.defaultIfNull(e.getCause(), e)));103 String message = StringUtils.isBlank(e.getMessage()) ? e.getCause().getMessage() : e.getMessage();104 setErrorMessage(message);105 if (e.getCause() == null || !e.getCause().getClass().getName().equals("java.lang.AssertionError"))106 handleException((Exception) getException().getCause());107 log.info(ActionResult.FAILED + " - " + getErrorMessage());108 snippetResult = ActionResult.FAILED;109 } finally {110 afterExecute();111 }112 return snippetResult;113 }114 private void beforeExecute() throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, AutomatorException {115 setDriver(null);116 setElements();117 setTestData();118 initRunTimeDataVariable();119 this.setRuntimeDataProvider(this.prepareRunTimeDataProvider());120 }121 private void afterExecute() throws NoSuchFieldException, IllegalAccessException, AutomatorException {122 saveRunTimeData();123 setAddonLogsInTestStep(instance);124 }125 protected void setSuccessMessage() throws NoSuchFieldException, IllegalAccessException {126 String msg = getSuccessMessageFromSnippet(instance);127 if (msg == null)128 this.successMessage = "Teststep executed successfully";129 else130 this.successMessage = StringUtils.abbreviate(msg, MESSAGE_MAX_SIZE);131 }132 protected void setErrorMessage() throws NoSuchFieldException, IllegalAccessException {133 String msg = getErrorMessageFromSnippet(instance);134 if (msg == null)135 this.errorMessage = "Teststep execution failed. No Additional message was available.";136 else137 this.errorMessage = StringUtils.abbreviate(msg, MESSAGE_MAX_SIZE);138 }139 private void setAddonLogsInTestStep(Object instance) throws NoSuchFieldException, IllegalAccessException {140 log.info("Saving Addon Logs in Test Step Result");141 Field loggerField = getField(instance.getClass(), "logger");142 loggerField.setAccessible(true);143 Field valueField = getField(loggerField.get(instance).getClass(), "value");144 valueField.setAccessible(true);145 StringBuilder val = (StringBuilder) valueField.get(loggerField.get(instance));146 result.setAddonActionLogs(val.toString());147 log.info("Successfully saved logs::" + val);148 }149 public void setDriver(Object object) throws IllegalAccessException {150 if (object != null)151 FieldUtils.writeField(object, "driver", DriverManager.getRemoteWebDriver(), true);152 else153 FieldUtils.writeField(instance, "driver", DriverManager.getRemoteWebDriver(), true);154 }155 public void setElements() throws AutomatorException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {156 AddonNaturalTextActionEntity addonNaturalTextActionEntity = testCaseStepEntity.getAddonNaturalTextActionEntity();157 Map<String, ElementPropertiesEntity> elementsMap = testCaseStepEntity.getElementsMap();158 if (!elementsMap.isEmpty()) {159 for (AddonNaturalTextActionParameterEntity addonNaturalTextActionParameterEntity : addonNaturalTextActionEntity.getPluginParameters()) {160 if (addonNaturalTextActionParameterEntity.getType() == AddonActionParameterType.ELEMENT) {161 log.info("Setting Element for Addon Plugin Action Step - " + addonNaturalTextActionParameterEntity);162 elementPropertiesEntity = elementsMap.get(addonNaturalTextActionParameterEntity.getReference());163 ElementSearchCriteria elementSearchCriteria = new ElementSearchCriteria(elementPropertiesEntity.getFindByType(),164 elementPropertiesEntity.getLocatorValue());165 Object elementInstance = addonService.getElementInstance(elementPropertiesEntity.getLocatorValue(),166 elementSearchCriteria.getBy());167 FieldUtils.writeField(instance, addonNaturalTextActionParameterEntity.getName(), elementInstance, true);168 setDriver(elementInstance);169 log.info("Setting element instance - " + elementInstance);170 }171 }172 }173 }174 public void setTestData() throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {175 AddonNaturalTextActionEntity addonNaturalTextActionEntity = testCaseStepEntity.getAddonNaturalTextActionEntity();176 Map<String, TestDataPropertiesEntity> testDataMap = testCaseStepEntity.getTestDataMap();177 if (!testDataMap.isEmpty()) {178 for (AddonNaturalTextActionParameterEntity addonNaturalTextActionParameterEntity : addonNaturalTextActionEntity.getPluginParameters()) {179 if (addonNaturalTextActionParameterEntity.getType() == AddonActionParameterType.TEST_DATA) {180 log.info("Setting Test Data for Addon Plugin Action Step - " + addonNaturalTextActionParameterEntity);181 Object testDataInstance = addonService.getTestDataInstance(testDataMap.get(addonNaturalTextActionParameterEntity182 .getReference()).getTestDataValue());183 FieldUtils.writeField(instance, addonNaturalTextActionParameterEntity.getName(), testDataInstance, true);184 log.info("Setting test data instance - " + testDataInstance);185 }186 }187 }188 }189 private void initRunTimeDataVariable() throws AutomatorException {190 try {191 for (Field field : clazz.getDeclaredFields()) {192 RunTimeData runTimeData = field.getAnnotation(RunTimeData.class);193 if (runTimeData != null) {...

Full Screen

Full Screen

Source:AddonNaturalTextActionStepExecutor.java Github

copy

Full Screen

...3import com.testsigma.automator.constants.AutomatorMessages;4import com.testsigma.automator.drivers.DriverManager;5import com.testsigma.automator.entity.*;6import com.testsigma.automator.exceptions.AutomatorException;7import com.testsigma.automator.actions.AddonAction;8import com.testsigma.automator.actions.constants.ErrorCodes;9import com.testsigma.automator.actions.exceptions.NaturalActionException;10import lombok.Data;11import lombok.extern.log4j.Log4j2;12import java.io.IOException;13import java.lang.reflect.InvocationTargetException;14import java.net.URLClassLoader;15import java.util.Arrays;16import java.util.LinkedList;17import java.util.List;18import java.util.Map;19@Data20@Log4j221public class AddonNaturalTextActionStepExecutor {22 private static final List<ErrorCodes> ERROR_CODES = Arrays.asList(23 ErrorCodes.UNREACHABLE_BROWSER,24 ErrorCodes.NO_SUCH_SESSION_EXCEPTION,25 ErrorCodes.GENERAL_EXCEPTION);26 private TestCaseStepEntity testCaseStepEntity;27 private TestCaseStepResult testCaseStepResult;28 private TestCaseResult testCaseResult;29 private URLClassLoader jarFileLoader;30 private Class<?> elementClass;31 private Class<?> testDataClass;32 private Class<?> loggerClass;33 private Class<?> runTimeDataClass;34 private Map<String, String> envSettings;35 private LinkedList<ElementPropertiesEntity> addonElementPropertiesEntity;36 public AddonNaturalTextActionStepExecutor(TestCaseStepEntity testCaseStepEntity, TestCaseStepResult testCaseStepResult,37 TestCaseResult testCaseResult,38 Map<String, String> envSettings) {39 this.testCaseStepEntity = testCaseStepEntity;40 this.testCaseStepResult = testCaseStepResult;41 this.testCaseResult = testCaseResult;42 this.envSettings = envSettings;43 }44 public void execute() throws IOException, IllegalAccessException, NoSuchMethodException, ClassNotFoundException, InvocationTargetException, InstantiationException, AutomatorException, NoSuchFieldException, NaturalActionException {45 AddonAction addonAction = new AddonAction(testCaseStepEntity, testCaseStepResult, this.addonElementPropertiesEntity, this.envSettings);46 ActionResult snippetResult = addonAction.run();47 if (snippetResult == ActionResult.FAILED) {48 log.error("Test case step FAILED....");49 NaturalActionException actionException;50 if(addonAction.getException() != null){51 actionException = new NaturalActionException(addonAction.getErrorMessage(), addonAction.getException(),52 addonAction.getErrorCode().getErrorCode().intValue());53 } else {54 actionException = new NaturalActionException(addonAction.getErrorMessage());55 }56 testCaseStepResult.setWebDriverException(actionException.getErrorStackTraceTruncated());57 testCaseStepResult.setErrorCode(addonAction.getErrorCode().getErrorCode().intValue());58 testCaseStepResult.setMessage(addonAction.getErrorMessage());59 markTestcaseAborted(testCaseResult, testCaseStepResult, addonAction);60 testCaseStepResult.getMetadata().setLog(testCaseStepResult.getWebDriverException());61 throw actionException; //We are throwing an InvocationTargetException to handle Auto Healing62 } else {63 testCaseStepResult.setMessage(addonAction.getSuccessMessage());64 }65 }66 private void markTestcaseAborted(TestCaseResult testCaseResult, TestCaseStepResult result, AddonAction snippet) {67 boolean isInAbortedList = ERROR_CODES.stream().anyMatch(code -> snippet.getErrorCode().equals(code));68 if (isInAbortedList) {69 DriverManager.getDriverManager().setRestartDriverSession(Boolean.TRUE);70 result.setResult(ResultConstant.ABORTED);71 result.setSkipExe(true);72 result.setMessage(AutomatorMessages.MSG_STEP_MAJOR_STEP_FAILURE);73 testCaseResult.setResult(ResultConstant.ABORTED);74 testCaseResult.setMessage(AutomatorMessages.MSG_TEST_CASE_ABORTED);75 if(!testCaseStepEntity.getStepDetails().getIgnoreStepResult()) {76 testCaseResult.setResult(ResultConstant.ABORTED);77 testCaseResult.setMessage(AutomatorMessages.MSG_TEST_CASE_ABORTED);78 }79 } else {80 result.setResult(ResultConstant.FAILURE);...

Full Screen

Full Screen

AddonAction

Using AI Code Generation

copy

Full Screen

1package com.testsigma.automator.actions;2import com.testsigma.automator.Action;3import com.testsigma.automator.ActionContext;4import com.testsigma.automator.ActionException;5import com.testsigma.automator.ActionResult;6import com.testsigma.automator.AddonAction;7import com.testsigma.automator.AddonActionContext;8import com.testsigma.automator.AddonActionResult;9import com.testsigma.automator.AddonActionType;10import com.testsigma.automator.AddonActionParameter;11import com.testsigma.automator.AddonActionParameterType;12import com.testsigma.automator.AddonActionParameterMode;13import com.testsigma.automator.AddonActionParameterValidation;14import com.testsigma.automator.AddonActionParameterValidationType;15import com.testsigma.automator.AddonActionParameterValidationOptions;16@AddonAction(17 parameters = {18 @AddonActionParameter(19 validation = @AddonActionParameterValidation(20 options = @AddonActionParameterValidationOptions(regex = "[0-9]*")21 @AddonActionParameter(22 validation = @AddonActionParameterValidation(23 options = @AddonActionParameterValidationOptions(regex = "[0-9]*")24 }25public class Add extends Action {26 public ActionResult execute(ActionContext actionContext) throws ActionException {27 String number1 = actionContext.getParameter("number1");28 String number2 = actionContext.getParameter("number2");29 int sum = Integer.parseInt(number1) + Integer.parseInt(number2);30 return new ActionResult(sum);31 }32}

Full Screen

Full Screen

AddonAction

Using AI Code Generation

copy

Full Screen

1package com.testsigma.automator.actions;2import java.util.ArrayList;3import java.util.HashMap;4import java.util.List;5import java.util.Map;6import java.util.concurrent.TimeUnit;7import java.util.logging.Level;8import java.util.logging.Logger;9import org.openqa.selenium.By;10import org.openqa.selenium.WebDriver;11import org.openqa.selenium.WebElement;12import org.openqa.selenium.chrome.ChromeDriver;13import org.openqa.selenium.chrome.ChromeOptions;14import org.openqa.selenium.remote.DesiredCapabilities;15import org.openqa.selenium.support.ui.ExpectedConditions;16import org.openqa.selenium.support.ui.WebDriverWait;17import org.openqa.selenium.support.ui.Select;18public class AddonAction {19public static void main(String[] args) {

Full Screen

Full Screen

AddonAction

Using AI Code Generation

copy

Full Screen

1import com.testsigma.automator.actions.AddonAction;2import com.testsigma.automator.actions.AddonAction.AddonActionType;3import com.testsigma.automator.actions.AddonAction.AddonActionType.AddonActionTypeValue;4import com.testsigma.automator.actions.AddonAction.AddonActionType.AddonActionTypeValue.AddonActionTypeValueValue;5import com.testsigma.automator.actions.AddonAction.AddonActionType.AddonActionTypeValue.AddonActionTypeValueValue.AddonActionTypeValueValueValue;6import com.testsigma.automator.actions.AddonAction.AddonActionType.AddonActionTypeValue.AddonActionTypeValueValue.AddonActionTypeValueValueValue.AddonActionTypeValueValueValueValue;7import com.testsigma.automator.actions.AddonAction.AddonActionType.AddonActionTypeValue.AddonActionTypeValueValue.AddonActionTypeValueValueValue.AddonActionTypeValueValueValueValue.AddonActionTypeValueValueValueValueValue;8import com.testsigma.automator.actions.AddonAction.AddonActionType.AddonActionTypeValue.AddonActionTypeValueValue.AddonActionTypeValueValueValue.AddonActionTypeValueValueValueValue.AddonActionTypeValueValueValueValueValue.AddonActionTypeValueValueValueValueValueValue;9import com.testsigma.automator.actions.AddonAction.AddonActionType.AddonActionTypeValue.AddonActionTypeValueValue.AddonActionTypeValueValueValue.AddonActionTypeValueValueValueValue.AddonActionTypeValueValueValueValueValue.AddonActionTypeValueValueValueValueValueValue.AddonActionTypeValueValueValueValueValueValueValue;10import com.testsigma.automator.actions.AddonAction.AddonActionType.AddonActionTypeValue.AddonActionTypeValueValue.AddonActionTypeValueValueValue.AddonActionTypeValueValueValueValue.AddonActionTypeValueValueValueValueValue.AddonActionTypeValueValueValueValueValueValue.AddonActionTypeValueValueValueValueValueValueValue.AddonActionTypeValueValueValueValueValueValueValueValue;11import com.testsigma.automator.actions.AddonAction.AddonActionType.AddonActionTypeValue.AddonActionTypeValueValue.AddonActionTypeValueValueValue.AddonActionTypeValueValueValueValue.AddonActionTypeValueValueValueValueValue.AddonActionTypeValueValueValueValueValueValue.Addon

Full Screen

Full Screen

AddonAction

Using AI Code Generation

copy

Full Screen

1package com.testsigma.automator.actions;2import com.testsigma.automator.core.AddonAction;3import com.testsigma.automator.core.TestStep;4import com.testsigma.automator.core.TestStepResult;5import com.testsigma.automator.util.TestStepUtil;6public class AddonActionExample extends AddonAction {7 public AddonActionExample() {8 super("AddonActionExample", "AddonActionExample", "AddonActionExample");9 }10 public TestStepResult execute(TestStep testStep) {11 TestStepResult result = new TestStepResult();12 result.setSuccess(true);13 result.setErrorMessage("");14 result.setStepMessage("AddonActionExample is executed successfully");15 return result;16 }17}18package com.testsigma.automator.actions;19import com.testsigma.automator.core.AddonAction;20import com.testsigma.automator.core.TestStep;21import com.testsigma.automator.core.TestStepResult;22import com.testsigma.automator.util.TestStepUtil;23public class AddonActionExample extends AddonAction {24 public AddonActionExample() {25 super("AddonActionExample", "AddonActionExample", "AddonActionExample");26 }27 public TestStepResult execute(TestStep testStep) {28 TestStepResult result = new TestStepResult();29 result.setSuccess(true);30 result.setErrorMessage("");31 result.setStepMessage("AddonActionExample is executed successfully");32 return result;33 }34}35package com.testsigma.automator.actions;36import com.testsigma.automator.core.AddonAction;37import com.testsigma.automator.core.TestStep;38import com.testsigma.automator.core.TestStepResult;39import com.testsigma.automator.util.TestStepUtil;40public class AddonActionExample extends AddonAction {41 public AddonActionExample() {42 super("AddonActionExample", "AddonActionExample", "AddonActionExample");43 }44 public TestStepResult execute(TestStep testStep) {

Full Screen

Full Screen

AddonAction

Using AI Code Generation

copy

Full Screen

1import com.testsigma.automator.actions.AddonAction;2import org.openqa.selenium.WebDriver;3import org.testng.annotations.Test;4public class AddonActionExample {5 public void testAddonAction(WebDriver driver) {6 try {7 AddonAction.takeScreenshot(driver);8 } catch (Exception e) {9 AddonAction.takeScreenshot(driver);10 throw e;11 }12 }13}14import com.testsigma.automator.actions.AddonAction;15import org.openqa.selenium.WebDriver;16import org.testng.annotations.Test;17public class AddonActionExample {18 public void testAddonAction(WebDriver driver) {19 try {20 AddonAction.takeScreenshot(driver, "screenshotName");21 } catch (Exception e) {22 AddonAction.takeScreenshot(driver, "screenshotName");23 throw e;24 }25 }26}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful