Best Testsigma code snippet using com.testsigma.automator.actions.DriverAction
Source:ActionStepExecutor.java
...6import com.testsigma.automator.entity.TestCaseResult;7import com.testsigma.automator.entity.TestCaseStepEntity;8import com.testsigma.automator.entity.TestCaseStepResult;9import com.testsigma.automator.exceptions.AutomatorException;10import com.testsigma.automator.actions.DriverAction;11import com.testsigma.automator.actions.constants.ErrorCodes;12import com.testsigma.automator.actions.exceptions.NaturalActionException;13import com.testsigma.automator.utilities.RuntimeDataProvider;14import lombok.AllArgsConstructor;15import lombok.Data;16import lombok.extern.log4j.Log4j2;17import org.openqa.selenium.StaleElementReferenceException;18import java.lang.reflect.InvocationTargetException;19import java.util.Arrays;20import java.util.List;21import java.util.Map;22@Data23@Log4j224@AllArgsConstructor25public class ActionStepExecutor {26 private static final List<ErrorCodes> ERROR_CODES = Arrays.asList(27 ErrorCodes.UNREACHABLE_BROWSER,28 ErrorCodes.NO_SUCH_SESSION_EXCEPTION,29 ErrorCodes.GENERAL_EXCEPTION);30 private TestCaseStepEntity testCaseStepEntity;31 private TestCaseStepResult testCaseStepResult;32 private Map<String, String> envSettings;33 private TestCaseResult testCaseResult;34 public void execute() throws IllegalAccessException,35 IllegalArgumentException, InvocationTargetException, SecurityException, NoSuchMethodException,36 AutomatorException, ClassNotFoundException, InstantiationException {37 Class<?> className = Class.forName(testCaseStepEntity.getSnippetClass());38 DriverAction snippet = (DriverAction) className.getDeclaredConstructor().newInstance();39 snippet.setDriver(DriverManager.getRemoteWebDriver());40 snippet.setTimeout(testCaseStepEntity.getWaitTime().longValue());41 snippet.setTestDataPropertiesEntityMap(testCaseStepEntity.getTestDataMap());42 snippet.setElementPropertiesEntityMap(testCaseStepEntity.getElementsMap());43 snippet.setAttributesMap(testCaseStepEntity.getAttributesMap());44 snippet.setGlobalElementTimeOut(testCaseStepResult.getTestPlanRunSettingEntity().getElementTimeOut().longValue());45 snippet.setRuntimeDataProvider(prepareRunTimeDataProvider());46 snippet.setEnvSettings(envSettings);47 snippet.setAdditionalData(testCaseStepEntity.getAdditionalData());48 ActionResult snippetResult = snippet.run();49 //We retry test step execution on failure based on the exception type.50 snippetResult = reTrySnippetIfEligible(snippetResult, snippet, testCaseStepEntity, testCaseStepResult);51 testCaseStepResult.getMetadata().setSnippetResultMetadata(snippet.getResultMetadata());52 testCaseStepResult.getOutputData().putAll(snippet.getTestDataParams());53 if (snippetResult == ActionResult.FAILED) {54 log.error("Test case step FAILED....");55 NaturalActionException naturalActionException = new NaturalActionException(snippet.getErrorMessage(), snippet.getException(),56 snippet.getErrorCode().getErrorCode().intValue());57 testCaseStepResult.setWebDriverException(naturalActionException.getErrorStackTraceTruncated());58 testCaseStepResult.setErrorCode(snippet.getErrorCode().getErrorCode().intValue());59 testCaseStepResult.setMessage(snippet.getErrorMessage());60 markTestcaseAborted(testCaseResult, testCaseStepResult, snippet);61 testCaseStepResult.getMetadata().setLog(testCaseStepResult.getWebDriverException());62 throw naturalActionException; //We are throwing an InvocationTargetException to handle Auto Healing63 } else {64 testCaseStepResult.setMessage(snippet.getSuccessMessage());65 }66 }67 private ActionResult reTrySnippetIfEligible(ActionResult snippetResult, DriverAction snippet,68 TestCaseStepEntity testCaseStepEntity,69 TestCaseStepResult testCaseStepResult) throws AutomatorException {70 for (int i = 0; i < testCaseStepEntity.getNoOfRetriesOnStepFailure(); i++) {71 boolean reTryRequired = eligibleForReTry(snippetResult, snippet, testCaseStepEntity, testCaseStepResult);72 if (reTryRequired) {73 testCaseStepResult.setRetriedCount(testCaseStepResult.getRetriedCount() + 1);74 log.info("Snippet Retry Count - " + testCaseStepResult.getRetriedCount());75 snippetResult = snippet.run();76 } else {77 log.info("Snippet is not eligible for retry...continuing");78 break;79 }80 }81 return snippetResult;82 }83 private boolean eligibleForReTry(ActionResult snippetResult, DriverAction snippet, TestCaseStepEntity stepEntity,84 TestCaseStepResult stepResult) {85 if (snippetResult != ActionResult.FAILED) {86 return false;87 }88 if (stepResult.getRetriedCount() < stepEntity.getNoOfRetriesOnStepFailure() && snippet.getException() != null89 && snippet.getException().getCause() != null) {90 if (snippet.getException().getCause() instanceof StaleElementReferenceException) {91 log.info("Snippet is eligible for retry...retrying");92 return true;93 }94 }95 return false;96 }97 private RuntimeDataProvider prepareRunTimeDataProvider() {98 return new RuntimeDataProvider();99 }100 private void markTestcaseAborted(TestCaseResult testCaseResult, TestCaseStepResult result, DriverAction snippet) {101 boolean isInAbortedList = ERROR_CODES.stream().anyMatch(code -> snippet.getErrorCode().equals(code));102 if (isInAbortedList) {103 DriverManager.getDriverManager().setRestartDriverSession(Boolean.TRUE);104 result.setResult(ResultConstant.ABORTED);105 result.setSkipExe(true);106 result.setMessage(AutomatorMessages.MSG_STEP_MAJOR_STEP_FAILURE);107 testCaseResult.setResult(ResultConstant.ABORTED);108 testCaseResult.setMessage(AutomatorMessages.MSG_TEST_CASE_ABORTED);109 if(!testCaseStepEntity.getStepDetails().getIgnoreStepResult()) {110 testCaseResult.setResult(ResultConstant.ABORTED);111 testCaseResult.setMessage(AutomatorMessages.MSG_TEST_CASE_ABORTED);112 }113 } else {114 result.setResult(ResultConstant.FAILURE);...
Source:ClickOnButtonInTheBrowserProxyAction.java
1package com.testsigma.automator.actions.web.generic;2import com.testsigma.automator.exceptions.AutomatorException;3import com.testsigma.automator.actions.DriverAction;4import com.testsigma.automator.actions.ElementAction;5import com.testsigma.automator.actions.common.NavigateBackAction;6import com.testsigma.automator.actions.common.NavigateForwardAction;7import com.testsigma.automator.actions.constants.ActionConstants;8import lombok.extern.log4j.Log4j2;9import java.lang.reflect.InvocationTargetException;10@Log4j211public class ClickOnButtonInTheBrowserProxyAction extends ElementAction {12 @Override13 public void execute() throws Exception {14 String button = getTestData();15 switch (button) {16 case ActionConstants.REFRESH:17 ReLoadCurrentPageAction refresh = (ReLoadCurrentPageAction) this.initializeChildSnippet(ReLoadCurrentPageAction.class);18 refresh.execute();19 this.setSuccessMessage(refresh.getSuccessMessage());20 break;21 case ActionConstants.BACK:22 NavigateBackAction back = (NavigateBackAction) this.initializeChildSnippet(NavigateBackAction.class);23 back.execute();24 this.setSuccessMessage(back.getSuccessMessage());25 break;26 case ActionConstants.FORWARD:27 NavigateForwardAction forward = (NavigateForwardAction) this.initializeChildSnippet(NavigateForwardAction.class);28 forward.execute();29 this.setSuccessMessage(forward.getSuccessMessage());30 break;31 default:32 setErrorMessage("Unable to Click on Button in the Browser due to error at test data");33 throw new AutomatorException("Unable to Click on Button in the Browser due to error at test data");34 }35 }36 protected Object initializeChildSnippet(Class<?> snippetClassName) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {37 DriverAction snippet = (DriverAction) snippetClassName.getDeclaredConstructor().newInstance();38 snippet.setDriver(this.getDriver());39 return snippet;40 }41 }...
DriverAction
Using AI Code Generation
1package com.testsigma.automator.actions;2import java.io.File;3import java.io.IOException;4import java.util.ArrayList;5import java.util.List;6import org.openqa.selenium.WebDriver;7import org.openqa.selenium.WebElement;8import org.openqa.selenium.chrome.ChromeDriver;9import org.openqa.selenium.chrome.ChromeOptions;10import org.openqa.selenium.remote.RemoteWebDriver;11import com.testsigma.automator.actions.DriverAction;12import com.testsigma.automator.actions.DriverActionFactory;13import com.testsigma.automator.actions.DriverActionType;14import com.testsigma.automator.actions.DriverActionWaitType;15import com.testsigma.automator.actions.DriverActionWaitUtil;16import com.testsigma.automator.actions.DriverActions;17import com.testsigma.automator.actions.DriverActionsFactory;18import com.testsigma.automator.actions.DriverActionsType;19import com.testsigma.automator.actions.DriverActionsWaitType;20import com.testsigma.automator.actions.DriverActionsWaitUtil;21import com.testsigma.automator.actions.DriverUtil;22import com.testsigma.automator.actions.DriverUtilType;23import com.testsigma.automator.actions.DriverUtilWaitType;24import com.testsigma.automator.actions.DriverUtilWaitUtil;25import com.testsigma.automator.actions.DriverWait;26import com.testsigma.automator.actions.DriverWaitFactory;27import com.testsigma.automator.actions.DriverWaitType;28import com.testsigma.automator.actions.DriverWaitWaitType;29import com.testsigma.automator.actions.DriverWaitWaitUtil;30import com.testsigma.automator.actions.ElementAction;31import com.testsigma.automator.actions.ElementActionFactory;32import com.testsigma.automator.actions.ElementActionType;33import com.testsigma.automator.actions.ElementActionWaitType;34import com.testsigma.automator.actions.ElementActionWaitUtil;35import com.testsigma.automator.actions.ElementActions;36import com.testsigma.automator.actions.ElementActionsFactory;37import com.testsigma.automator.actions.ElementActionsType;38import com.testsigma.automator.actions.ElementActionsWaitType;39import com.testsigma.automator.actions.ElementActionsWaitUtil;40import com.testsigma.automator.actions.ElementUtil;41import com.testsigma.automator.actions.ElementUtilFactory;42import com.testsigma.automator.actions.ElementUtilType;43import com.testsigma.automator.actions.ElementUtilWaitType;44import com.testsigma.automator.actions.ElementUtilWaitUtil;45import com.testsigma.automator.actions.ElementWait;46import com.testsigma.automator
DriverAction
Using AI Code Generation
1import com.testsigma.automator.actions.DriverAction;2import com.testsigma.automator.actions.DriverActionBuilder;3import com.testsigma.automator.actions.DriverActionBuilder.ActionType;4import com.testsigma.automator.actions.DriverActionBuilder.ElementType;5import com.testsigma.automator.actions.DriverActionBuilder.LocatorType;6import com.testsigma.automator.actions.DriverActionBuilder.ValueType;7import com.testsigma.automator.actions.DriverActionBuilder.WindowType;8import com.testsigma.automator.actions.DriverActionBuilder.WaitType;9import com.testsigma.automator.actions.DriverActionBuilder.SwitchType;10import com.testsigma.automator.actions.DriverActionBuilder.SelectType;11import com.testsigma.automator.actions.DriverActionBuilder.MouseType;12import com.testsigma.automator.actions.DriverActionBuilder.KeyboardType;13import com.testsigma.automator.actions.DriverActionBuilder.JsType;14import com.testsigma.automator.actions.DriverActionBuilder.AlertType;15import com.testsigma.automator.actions.DriverActionBuilder.AssertType;16import com.testsigma.automator.actions.DriverActionBuilder.ScreenshotType;17import com.testsigma.automator.actions.DriverActionBuilder.FileType;18import com.testsigma.automator.actions.DriverActionBuilder.FrameType;19import com.testsigma.automator.actions.DriverActionBuilder.DataBaseType;20import com.testsigma.automator.actions.DriverActionBuilder.WebServiceType;21import com.testsigma.automator.actions.DriverActionBuilder.ReportType;22import com.testsigma.automator.actions.DriverActionBuilder.EmailType;23import com.testsigma.automator.actions.DriverActionBuilder.CryptoType;24import com.testsigma.automator.actions.DriverActionBuilder.FileUploadType;25import com.testsigma.automator.actions.DriverActionBuilder.FileDownloadType;26import com.testsigma.automator.actions.DriverActionBuilder.FileCompareType;27import com.testsigma.automator.actions.DriverActionBuilder.FileSearchType;28import com.testsigma.automator.actions.DriverActionBuilder.FileDeleteType;29import com.testsigma.automator.actions.DriverActionBuilder.FileRenameType;30import com.testsigma.automator.actions.DriverActionBuilder.FileMoveType;31import com.testsigma.automator.actions.DriverActionBuilder.FileCopyType;32import com.testsigma.automator.actions.DriverActionBuilder.FileZipType;33import com.testsigma.automator.actions.DriverActionBuilder.FileUnzipType;34import com.testsigma.automator.actions.DriverActionBuilder.FileCreateType;35import com.testsigma.automator.actions
DriverAction
Using AI Code Generation
1import com.testsigma.automator.actions.DriverAction;2import com.testsigma.automator.actions.DriverActionFactory;3import com.testsigma.automator.actions.DriverActionType;4import com.testsigma.automator.actions.DriverActionFactory;5import com.testsigma.automator.actions.DriverActionType;6import com.testsigma.automator.actions.DriverAction;7import com.testsigma.automator.actions.DriverActionType;8import com.testsigma.automator.actions.DriverActionFactory;9import com.testsigma.automator.actions.DriverActionType;10import com.testsigma.automator.actions.DriverAction;11import com.testsigma.automator.actions.DriverActionType;12import com.testsigma.automator.actions.DriverActionFactory;13import com.testsigma.automator.actions.DriverActionType;14import com.testsigma.automator.actions.DriverAction;15import com.testsigma.automator.actions.DriverActionType;16import com.testsigma.automator.actions.DriverActionFactory;17import com.testsigma.automator.actions.DriverActionType;18import com.testsigma.automator.actions.DriverAction;19import com.testsigma.automator.actions.DriverActionType;20import com.testsigma.automator.actions.DriverActionFactory;21import com.testsigma.automator.actions.DriverActionType;22import com.testsigma.automator.actions.DriverAction;23import com.testsigma.automator.actions.DriverActionType;24import com.testsigma.automator.actions.DriverActionFactory;25import com.testsigma.automator.actions.DriverActionType;26import com.testsigma.automator.actions.DriverAction;27import com.testsigma.automator.actions.DriverActionType;28import com.testsigma.automator.actions.DriverActionFactory;29import com.testsigma.automator.actions.DriverActionType;30import com.testsigma.automator.actions.DriverAction;31import com.testsigma.automator.actions.DriverActionType;32import com.testsigma.automator.actions.DriverActionFactory;33import com.testsigma.automator.actions.DriverActionType;34import com.testsigma.automator.actions.DriverAction;35import com.testsigma.automator.actions.DriverActionType;36import com.testsigma.automator.actions.DriverActionFactory;37import com.testsigma.automator.actions.DriverActionType;38import com.testsigma.automator.actions.DriverAction;39import com.testsigma.automator.actions.DriverActionType;40import com.testsigma.automator.actions.DriverActionFactory;41import com.testsigma.automator.actions.DriverActionType;42import com.testsigma.automator.actions.DriverAction;
DriverAction
Using AI Code Generation
1package com.testsigma.automator.actions;2import org.openqa.selenium.By;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.WebElement;5import org.openqa.selenium.chrome.ChromeDriver;6import java.util.concurrent.TimeUnit;7public class DriverAction {8 private WebDriver driver;9 public DriverAction(WebDriver driver) {10 this.driver = driver;11 }12 public WebElement findElement(By by) {13 return driver.findElement(by);14 }15 public WebElement findElement(String locator) {16 return driver.findElement(getBy(locator));17 }18 public void click(String locator) {19 findElement(locator).click();20 }21 public void click(By by) {22 findElement(by).click();23 }24 public void click(WebElement element) {25 element.click();26 }27 public void type(String locator, String text) {28 findElement(locator).sendKeys(text);29 }30 public void type(By by, String text) {31 findElement(by).sendKeys(text);32 }33 public void type(WebElement element, String text) {34 element.sendKeys(text);35 }36 public void clear(String locator) {37 findElement(locator).clear();38 }39 public void clear(By by) {40 findElement(by).clear();41 }42 public void clear(WebElement element) {43 element.clear();44 }45 public void submit(String locator) {46 findElement(locator).submit();47 }48 public void submit(By by) {49 findElement(by).submit();50 }51 public void submit(WebElement element) {52 element.submit();53 }54 public String getText(String locator) {55 return findElement(locator).getText();56 }57 public String getText(By by) {58 return findElement(by).getText();59 }60 public String getText(WebElement element) {61 return element.getText();62 }63 public String getAttribute(String locator, String attribute) {64 return findElement(locator).getAttribute(attribute);65 }66 public String getAttribute(By by, String attribute) {67 return findElement(by).getAttribute(attribute);68 }69 public String getAttribute(WebElement element, String attribute) {70 return element.getAttribute(attribute);71 }72 public void select(String locator, String text) {73 new Select(findElement(locator)).selectByVisibleText(text);74 }75 public void select(By by, String text) {76 new Select(findElement(by)).selectByVisibleText(text);
DriverAction
Using AI Code Generation
1import com.testsigma.automator.actions.DriverAction;2public class 2 {3public static void main(String[] args) {4DriverAction driverAction = new DriverAction();5}6}7import com.testsigma.automator.actions.DriverAction;8public class 3 {9public static void main(String[] args) {10DriverAction driverAction = new DriverAction();11}12}13import com.testsigma.automator.actions.DriverAction;14public class 4 {15public static void main(String[] args) {16DriverAction driverAction = new DriverAction();17}18}19import com.testsigma.automator.actions.DriverAction;20public class 5 {21public static void main(String[] args) {22DriverAction driverAction = new DriverAction();23}24}25import com.testsigma.automator.actions.DriverAction;26public class 6 {27public static void main(String[] args) {28DriverAction driverAction = new DriverAction();
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!