Search in sources :

Example 1 with TestStep

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);
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) Date(java.util.Date)

Example 2 with 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);
        }
    }
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) Element(org.jdom2.Element)

Example 3 with TestStep

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);
        }
    }
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) Element(org.jdom2.Element) TestAction(com.seleniumtests.reporter.logger.TestAction)

Example 4 with TestStep

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);
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) MethodSignature(org.aspectj.lang.reflect.MethodSignature) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StepName(com.seleniumtests.core.StepName) AfterMethod(org.testng.annotations.AfterMethod) Method(java.lang.reflect.Method) Step(com.seleniumtests.core.Step) TestStep(com.seleniumtests.reporter.logger.TestStep) Annotation(java.lang.annotation.Annotation) Entry(java.util.Map.Entry) RootCause(com.seleniumtests.core.Step.RootCause)

Example 5 with TestStep

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()));
        }
    }
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) ScenarioException(com.seleniumtests.customexception.ScenarioException)

Aggregations

TestStep (com.seleniumtests.reporter.logger.TestStep)190 Test (org.testng.annotations.Test)148 GenericTest (com.seleniumtests.GenericTest)120 ArrayList (java.util.ArrayList)80 TestAction (com.seleniumtests.reporter.logger.TestAction)47 File (java.io.File)37 ScreenShot (com.seleniumtests.driver.screenshots.ScreenShot)25 Snapshot (com.seleniumtests.reporter.logger.Snapshot)24 ErrorCause (com.seleniumtests.core.testanalysis.ErrorCause)19 TestMessage (com.seleniumtests.reporter.logger.TestMessage)16 GenericFile (com.seleniumtests.reporter.logger.GenericFile)15 MockitoTest (com.seleniumtests.MockitoTest)12 HashMap (java.util.HashMap)12 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 ITestResult (org.testng.ITestResult)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 Uft (com.seleniumtests.connectors.extools.Uft)8 DriverExceptions (com.seleniumtests.customexception.DriverExceptions)8 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)7 SeleniumRobotServerException (com.seleniumtests.customexception.SeleniumRobotServerException)6