use of com.testsigma.automator.constants.ActionResult in project testsigma by testsigmahq.
the class ActionStepExecutor method execute.
public void execute() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, NoSuchMethodException, AutomatorException, ClassNotFoundException, InstantiationException {
Class<?> className = Class.forName(testCaseStepEntity.getSnippetClass());
DriverAction snippet = (DriverAction) className.getDeclaredConstructor().newInstance();
snippet.setDriver(DriverManager.getRemoteWebDriver());
snippet.setTimeout(testCaseStepEntity.getWaitTime().longValue());
snippet.setTestDataPropertiesEntityMap(testCaseStepEntity.getTestDataMap());
snippet.setElementPropertiesEntityMap(testCaseStepEntity.getElementsMap());
snippet.setAttributesMap(testCaseStepEntity.getAttributesMap());
snippet.setGlobalElementTimeOut(testCaseStepResult.getTestPlanRunSettingEntity().getElementTimeOut().longValue());
snippet.setRuntimeDataProvider(prepareRunTimeDataProvider());
snippet.setEnvSettings(envSettings);
snippet.setAdditionalData(testCaseStepEntity.getAdditionalData());
ActionResult snippetResult = snippet.run();
// We retry test step execution on failure based on the exception type.
snippetResult = reTrySnippetIfEligible(snippetResult, snippet, testCaseStepEntity, testCaseStepResult);
testCaseStepResult.getMetadata().setSnippetResultMetadata(snippet.getResultMetadata());
testCaseStepResult.getOutputData().putAll(snippet.getTestDataParams());
if (snippetResult == ActionResult.FAILED) {
log.error("Test case step FAILED....");
NaturalActionException naturalActionException = new NaturalActionException(snippet.getErrorMessage(), snippet.getException(), snippet.getErrorCode().getErrorCode().intValue());
testCaseStepResult.setWebDriverException(naturalActionException.getErrorStackTraceTruncated());
testCaseStepResult.setErrorCode(snippet.getErrorCode().getErrorCode().intValue());
testCaseStepResult.setMessage(snippet.getErrorMessage());
markTestcaseAborted(testCaseResult, testCaseStepResult, snippet);
testCaseStepResult.getMetadata().setLog(testCaseStepResult.getWebDriverException());
// We are throwing an InvocationTargetException to handle Auto Healing
throw naturalActionException;
} else {
testCaseStepResult.setMessage(snippet.getSuccessMessage());
}
}
use of com.testsigma.automator.constants.ActionResult in project testsigma by testsigmahq.
the class AddonNaturalTextActionStepExecutor method execute.
public void execute() throws IOException, IllegalAccessException, NoSuchMethodException, ClassNotFoundException, InvocationTargetException, InstantiationException, AutomatorException, NoSuchFieldException, NaturalActionException {
AddonAction addonAction = new AddonAction(testCaseStepEntity, testCaseStepResult, this.addonElementPropertiesEntity, this.envSettings);
ActionResult snippetResult = addonAction.run();
if (snippetResult == ActionResult.FAILED) {
log.error("Test case step FAILED....");
NaturalActionException actionException;
if (addonAction.getException() != null) {
actionException = new NaturalActionException(addonAction.getErrorMessage(), addonAction.getException(), addonAction.getErrorCode().getErrorCode().intValue());
} else {
actionException = new NaturalActionException(addonAction.getErrorMessage());
}
testCaseStepResult.setWebDriverException(actionException.getErrorStackTraceTruncated());
testCaseStepResult.setErrorCode(addonAction.getErrorCode().getErrorCode().intValue());
testCaseStepResult.setMessage(addonAction.getErrorMessage());
markTestcaseAborted(testCaseResult, testCaseStepResult, addonAction);
testCaseStepResult.getMetadata().setLog(testCaseStepResult.getWebDriverException());
// We are throwing an InvocationTargetException to handle Auto Healing
throw actionException;
} else {
testCaseStepResult.setMessage(addonAction.getSuccessMessage());
}
}
use of com.testsigma.automator.constants.ActionResult in project testsigma by testsigmahq.
the class AddonAction method run.
@SneakyThrows
public ActionResult run() {
ActionResult snippetResult;
try {
beforeExecute();
snippetResult = execute();
if (snippetResult == ActionResult.SUCCESS)
setSuccessMessage();
else
setErrorMessage();
return snippetResult;
} catch (Exception e) {
log.error(e.getMessage(), e);
setException(new Exception(ObjectUtils.defaultIfNull(e.getCause(), e)));
String message = StringUtils.isBlank(e.getMessage()) ? e.getCause().getMessage() : e.getMessage();
setErrorMessage(message);
if (e.getCause() == null || !e.getCause().getClass().getName().equals("java.lang.AssertionError"))
handleException((Exception) getException().getCause());
log.info(ActionResult.FAILED + " - " + getErrorMessage());
snippetResult = ActionResult.FAILED;
} finally {
afterExecute();
}
return snippetResult;
}
use of com.testsigma.automator.constants.ActionResult in project testsigma by testsigmahq.
the class PageElementsAction method execute.
@Override
public void execute() throws Exception {
MobileElement mobileElement;
getDriver().context("NATIVE_APP");
String pageSource = getDriver().getPageSource();
log.debug("Page source fetched: " + pageSource);
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document document = documentBuilder.parse(new ByteArrayInputStream(pageSource.getBytes(StandardCharsets.UTF_8)));
Match match = JOOX.$(document).xpath("//*");
mobileElement = new MobileElement(match.get(0).cloneNode(true), 1, getPlatform());
mobileElement.setParent(null);
Set<String> contextNames = getDriver().getContextHandles();
mobileElement.setContextNames(contextNames);
List<MobileWebElement> webViewElements = new ArrayList<>();
List<MobileElement> webViewElementReferences = new ArrayList<>();
if (contextNames.size() > 1) {
this.findWebViewNativeElementReferences(mobileElement, webViewElementReferences);
log.info("webViewElementReferences size:" + webViewElementReferences.size());
log.info("No of Contexts:" + contextNames.size());
log.info("Contexts:" + contextNames);
}
if (webViewElementReferences.size() > 0) {
int webViewIndex = 0;
for (String name : contextNames) {
if (name.equals("NATIVE_APP") || name.equals("WEBVIEW_chrome"))
continue;
if (webViewIndex >= webViewElementReferences.size()) {
break;
}
MobileWebViewElementsAction webViewSnippet = new MobileWebViewElementsAction();
webViewSnippet.setDriver(getDriver());
webViewSnippet.setContext(name);
webViewSnippet.setPlatform(platform);
webViewSnippet.setNativeReference(webViewElementReferences.get(webViewIndex));
ActionResult result = webViewSnippet.run();
if (result.equals(ActionResult.FAILED)) {
log.error(webViewSnippet.getErrorMessage());
continue;
// throw new Exception("Failed to fetch page elements " + " : " + webViewSnippet.getErrorMessage());
}
MobileWebElement webViewParentElement = (MobileWebElement) webViewSnippet.getActualValue();
MobileElement nativeRef = webViewSnippet.getNativeReference();
// webViewParentElement.setParent(nativeRef.getParent());
List<MobileElement> children = nativeRef.getParent().getChildElements();
if (children == null)
children = new ArrayList<>();
children.add(children.size() - 1, webViewParentElement);
nativeRef.getParent().setChildElements(children);
webViewElements.add(webViewParentElement);
webViewIndex++;
}
}
mobileElement.setWebViewElements(webViewElements);
getDriver().context("NATIVE_APP");
setActualValue(mobileElement);
populateXpath(mobileElement);
setSuccessMessage(SUCCESS_MESSAGE);
}
Aggregations