use of com.seleniumtests.reporter.logger.TestStep in project seleniumRobot by bhecquet.
the class Uft method executeScript.
/**
* Executes an UFT script with timeout
* @param timeout timeout in seconds for UFT execution
* @return the generated test step
*/
public TestStep executeScript(int timeout, Map<String, String> parameters) {
if (!loaded) {
throw new IllegalStateException("Test script has not been loaded. Call 'loadScript' before");
}
this.parameters = parameters;
TestStep testStep = new TestStep(String.format("UFT: %s", scriptName), Reporter.getCurrentTestResult(), new ArrayList<>(), false);
Date startDate = new Date();
String output = TestTasks.executeCommand("cscript.exe", timeout, null, prepareArguments(false, true).toArray(new String[] {}));
testStep.setDuration(new Date().getTime() - startDate.getTime());
// when execution ends, UFT is stopped
loaded = false;
return analyseOutput(output, testStep);
}
use of com.seleniumtests.reporter.logger.TestStep in project seleniumRobot by bhecquet.
the class Uft method readAction.
/**
* Read an action element
* @param parentStep
* @param actionElement
* @throws DataConversionException
*/
private void readAction(TestStep parentStep, Element actionElement) throws DataConversionException {
TestStep actionStep = new TestStep(actionElement.getChildText("AName"), Reporter.getCurrentTestResult(), new ArrayList<>(), false);
parentStep.addStep(actionStep);
Element summary = actionElement.getChild("Summary");
if (summary != null && summary.getAttribute("failed").getIntValue() != 0) {
actionStep.setFailed(true);
}
for (Element element : actionElement.getChildren()) {
if ("Action".equals(element.getName())) {
readAction(actionStep, element);
} else if ("Step".equals(element.getName())) {
readStep(actionStep, element);
}
}
}
use of com.seleniumtests.reporter.logger.TestStep in project seleniumRobot by bhecquet.
the class Uft method readStep.
/**
* Read a step element
* @param parentStep
* @param stepElement
*/
private void readStep(TestStep parentStep, Element stepElement) {
List<Element> stepList = stepElement.getChildren("Step");
org.jsoup.nodes.Document htmlDoc = Jsoup.parseBodyFragment(stepElement.getChildText("Details"));
String details = htmlDoc.text();
String stepDescription = String.format("%s: %s", stepElement.getChildText("Obj"), details);
if (stepList.isEmpty()) {
TestAction action = new TestAction(stepDescription, false, new ArrayList<>());
parentStep.addAction(action);
} else {
TestStep stepStep = new TestStep(stepDescription, Reporter.getCurrentTestResult(), new ArrayList<>(), false);
parentStep.addStep(stepStep);
for (Element subStepElement : stepElement.getChildren("Step")) {
readStep(stepStep, subStepElement);
}
}
}
use of com.seleniumtests.reporter.logger.TestStep in project seleniumRobot by bhecquet.
the class LogAction method buildRootStep.
/**
* Returns step with name depending on step type
* In case of cucumber step, get the annotation value.
* /!\ THIS WORKS ONLY IF
* parameters of the annotated method are the Object version ones. Use 'Integer' instead of 'int' for example, when declaring
* a cucumber method which uses an integer as parameter. Else method discovery won't find it and step name will fall back to method name
*
* Else, get method name
* @param joinPoint
* @param returnArgs if true, returns method arguments
* @return
*/
private TestStep buildRootStep(JoinPoint joinPoint, String stepNamePrefix, boolean returnArgs) {
String stepName;
List<String> pwdToReplace = new ArrayList<>();
Map<String, String> arguments = new HashMap<>();
String argumentString = buildArgString(joinPoint, pwdToReplace, arguments);
if (returnArgs) {
stepName = String.format("%s %s", joinPoint.getSignature().getName(), argumentString);
} else {
stepName = joinPoint.getSignature().getName();
}
// Get the method called by this joinPoint
Method method = ((MethodSignature) joinPoint.getSignature()).getMethod();
RootCause errorCause = RootCause.NONE;
String errorCauseDetails = null;
boolean disableBugtracker = false;
for (Annotation annotation : method.getAnnotations()) {
if ((annotation.annotationType().getCanonicalName().contains("cucumber.api.java.en") || annotation.annotationType().getCanonicalName().contains("cucumber.api.java.fr") || annotation.annotationType().getCanonicalName().contains("io.cucumber.java.en") || annotation.annotationType().getCanonicalName().contains("io.cucumber.java.fr")) && SeleniumRobotTestPlan.isCucumberTest()) {
stepName = getAnnotationValue(annotation) + " " + argumentString;
break;
} else if (annotation instanceof StepName) {
stepName = ((StepName) annotation).value();
// replaces argument placeholders with values
for (Entry<String, String> entry : arguments.entrySet()) {
stepName = stepName.replaceAll(String.format("\\$\\{%s\\}", entry.getKey()), entry.getValue().replace("$", "\\$"));
}
break;
} else if (annotation instanceof Step) {
stepName = ((Step) annotation).name();
errorCause = ((Step) annotation).errorCause();
errorCauseDetails = ((Step) annotation).errorCauseDetails();
disableBugtracker = ((Step) annotation).disableBugTracker();
// replaces argument placeholders with values
for (Entry<String, String> entry : arguments.entrySet()) {
stepName = stepName.replaceAll(String.format("\\$\\{%s\\}", entry.getKey()), entry.getValue().replace("$", "\\$"));
}
break;
}
}
return new TestStep(stepNamePrefix + stepName, Reporter.getCurrentTestResult(), pwdToReplace, SeleniumTestsContextManager.getThreadContext().getMaskedPassword(), errorCause, errorCauseDetails, disableBugtracker);
}
use of com.seleniumtests.reporter.logger.TestStep in project seleniumRobot by bhecquet.
the class SeleniumRobotTestPlan method executeUftScript.
/**
* Execute a UFT script locally or remotely via a VBS script called through csscript.exe
* @param args parameters to give to UFT script
* @param timeout timeout in seconds. Max time the script will run
*/
public void executeUftScript(Uft uft, int timeout, Map<String, String> args) {
TestTasks.terminateCurrentStep();
List<TestStep> uftSteps = uft.executeScript(timeout, args);
for (TestStep uftStep : uftSteps) {
TestStepManager.setCurrentRootTestStep(uftStep);
TestStepManager.logTestStep(TestStepManager.getCurrentRootTestStep());
if (Boolean.TRUE.equals(uftStep.getFailed())) {
throw new ScenarioException(String.format("UFT execution failed on script %s", uft.getScriptPath()));
}
}
}
Aggregations