Search in sources :

Example 16 with TestMessage

use of com.seleniumtests.reporter.logger.TestMessage in project seleniumRobot by bhecquet.

the class TestTestStep method testTestMessageEncodeXml.

@Test(groups = { "ut" })
public void testTestMessageEncodeXml() {
    TestMessage msg = new TestMessage("everything OK \"'<>&", MessageType.INFO);
    TestMessage encodedMsg = msg.encode("xml");
    Assert.assertEquals(encodedMsg.toString(), "everything OK &quot;&apos;&lt;&gt;&amp;");
}
Also used : TestMessage(com.seleniumtests.reporter.logger.TestMessage) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 17 with TestMessage

use of com.seleniumtests.reporter.logger.TestMessage in project seleniumRobot by bhecquet.

the class TestTestStep method testToJson.

/**
 * Checks getFailed correctly compute test step status if sub step is not failed
 *
 * @throws IOException
 */
@Test(groups = { "ut" })
public void testToJson() throws IOException {
    TestStep step = new TestStep("step1", null, new ArrayList<>(), true);
    step.addMessage(new TestMessage("everything OK", MessageType.INFO));
    step.addAction(new TestAction("action2", false, new ArrayList<>()));
    Har har = new Har(new HarLog());
    har.getLog().addPage(new HarPage("title", "a title"));
    step.addNetworkCapture(new HarCapture(har, "main"));
    GenericFile file = new GenericFile(File.createTempFile("video", ".avi"), "video file");
    step.addFile(file);
    TestStep subStep = new TestStep("subStep", null, new ArrayList<>(), true);
    subStep.addMessage(new TestMessage("everything in subStep almost OK", MessageType.WARNING));
    subStep.addAction(new TestAction("action1", false, new ArrayList<>()));
    step.addAction(subStep);
    JSONObject stepJson = step.toJson();
    Assert.assertEquals(stepJson.getString("type"), "step");
    Assert.assertEquals(stepJson.getString("name"), "step1");
    Assert.assertEquals(stepJson.getJSONArray("actions").length(), 3);
    // check actions order
    Assert.assertEquals(stepJson.getJSONArray("actions").getJSONObject(0).getString("type"), "message");
    Assert.assertEquals(stepJson.getJSONArray("actions").getJSONObject(0).getString("messageType"), "INFO");
    Assert.assertEquals(stepJson.getJSONArray("actions").getJSONObject(1).getString("type"), "action");
    Assert.assertEquals(stepJson.getJSONArray("actions").getJSONObject(1).getString("name"), "action2");
    Assert.assertEquals(stepJson.getJSONArray("actions").getJSONObject(1).getBoolean("failed"), false);
    Assert.assertEquals(stepJson.getJSONArray("harCaptures").getJSONObject(0).getString("type"), "networkCapture");
    Assert.assertEquals(stepJson.getJSONArray("harCaptures").getJSONObject(0).getString("name"), "main");
    Assert.assertEquals(stepJson.getJSONArray("actions").getJSONObject(2).getString("type"), "step");
    Assert.assertEquals(stepJson.getJSONArray("actions").getJSONObject(2).getString("name"), "subStep");
    Assert.assertEquals(stepJson.getJSONArray("actions").getJSONObject(2).getJSONArray("actions").length(), 2);
    Assert.assertEquals(stepJson.getJSONArray("files").getJSONObject(0).getString("type"), "file");
    Assert.assertEquals(stepJson.getJSONArray("files").getJSONObject(0).getString("name"), "video file");
    Assert.assertTrue(stepJson.getJSONArray("files").getJSONObject(0).getString("file").contains(".avi"));
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) HarLog(net.lightbody.bmp.core.har.HarLog) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) Har(net.lightbody.bmp.core.har.Har) HarCapture(com.seleniumtests.reporter.logger.HarCapture) TestMessage(com.seleniumtests.reporter.logger.TestMessage) HarPage(net.lightbody.bmp.core.har.HarPage) GenericFile(com.seleniumtests.reporter.logger.GenericFile) TestAction(com.seleniumtests.reporter.logger.TestAction) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 18 with TestMessage

use of com.seleniumtests.reporter.logger.TestMessage in project seleniumRobot by bhecquet.

the class TestTestStep method testPasswordMaskingHtmlEncodedMainStepWithSpecialCharacters.

/**
 * issue #431: check encoded steps have there password encoded when using special characters
 */
@Test(groups = { "ut" })
public void testPasswordMaskingHtmlEncodedMainStepWithSpecialCharacters() {
    TestStep step = new TestStep("step1 with args: (bar, passwd§~$µ)", null, Arrays.asList("passwd§~$µ"), true);
    TestAction action = new TestAction("action in step1 with args: (foo, passwd§~$µ)", false, new ArrayList<>());
    TestMessage message = new TestMessage("everything OK on passwd§~$µ", MessageType.INFO);
    TestStep substep = new TestStep("substep with args: (passwd§~$µ)", null, new ArrayList<>(), true);
    step.addAction(action);
    step.addMessage(message);
    step.addStep(substep);
    Assert.assertEquals(step.encode("html").getName(), "step1 with args: (bar, ******)");
    Assert.assertEquals(action.encode("html").getName(), "action in step1 with args: (foo, ******)");
    Assert.assertEquals(message.encode("html").getName(), "everything OK on ******");
    Assert.assertEquals(substep.encode("html").getName(), "substep with args: (******)");
    Assert.assertEquals(step.encode("html").toString(), "Step step1 with args: (bar, ******)\n" + "  - action in step1 with args: (foo, ******)\n" + "  - everything OK on ******\n" + "  - Step substep with args: (******)");
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) TestMessage(com.seleniumtests.reporter.logger.TestMessage) TestAction(com.seleniumtests.reporter.logger.TestAction) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 19 with TestMessage

use of com.seleniumtests.reporter.logger.TestMessage in project seleniumRobot by bhecquet.

the class TestTestStep method testNoPasswordMasking.

/**
 * check that when disabled, password masking does not change test step
 */
@Test(groups = { "ut" })
public void testNoPasswordMasking() {
    TestStep step = new TestStep("step1 with args: (bar, passwd)", null, new ArrayList<>(), false);
    TestStep substep = new TestStep("substep with args: (passwd)", null, Arrays.asList("passwd"), false);
    TestAction action = new TestAction("action in step1 with args: (foo, passwd)", false, new ArrayList<>());
    TestMessage message = new TestMessage("everything OK on passwd", MessageType.INFO);
    step.addAction(substep);
    substep.addAction(action);
    substep.addMessage(message);
    Assert.assertEquals(step.getName(), "step1 with args: (bar, passwd)");
    Assert.assertEquals(action.getName(), "action in step1 with args: (foo, passwd)");
    Assert.assertEquals(message.getName(), "everything OK on passwd");
    Assert.assertEquals(substep.getName(), "substep with args: (passwd)");
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) TestMessage(com.seleniumtests.reporter.logger.TestMessage) TestAction(com.seleniumtests.reporter.logger.TestAction) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 20 with TestMessage

use of com.seleniumtests.reporter.logger.TestMessage in project seleniumRobot by bhecquet.

the class Uft method readXmlResult.

public void readXmlResult(String xmlString, TestStep testStep) {
    Document document;
    SAXBuilder builder = new SAXBuilder();
    try {
        String xml = xmlString.substring(xmlString.indexOf("<"));
        String xml10pattern = "[^" + "\u0009\r\n" + "\u0020-\uD7FF" + "\uE000-\uFFFD" + "\ud800\udc00-\udbff\udfff" + "]";
        xml = xml.replaceAll(xml10pattern, "");
        // we skip BOM by searching the first "<" character
        document = builder.build(new InputSource(new StringReader(xml)));
        Element docElement = document.getRootElement().getChild("Doc");
        Element summary = docElement.getChild("Summary");
        if (summary != null && summary.getAttribute("failed").getIntValue() != 0) {
            testStep.setFailed(true);
        }
        Element iteration = docElement.getChild("DIter");
        for (Element element : iteration.getChildren()) {
            if ("Action".equals(element.getName())) {
                readAction(testStep, element);
            } else if ("Step".equals(element.getName())) {
                readStep(testStep, element);
            }
        }
    } catch (JDOMException | IOException | StringIndexOutOfBoundsException e) {
        logger.error("Could not read UFT report: " + e.getMessage());
        testStep.addMessage(new TestMessage("Could not read UFT report: " + e.getMessage(), MessageType.ERROR));
    }
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) InputSource(org.xml.sax.InputSource) Element(org.jdom2.Element) StringReader(java.io.StringReader) IOException(java.io.IOException) TestMessage(com.seleniumtests.reporter.logger.TestMessage) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException)

Aggregations

TestMessage (com.seleniumtests.reporter.logger.TestMessage)20 Test (org.testng.annotations.Test)17 TestStep (com.seleniumtests.reporter.logger.TestStep)16 GenericTest (com.seleniumtests.GenericTest)14 TestAction (com.seleniumtests.reporter.logger.TestAction)12 ArrayList (java.util.ArrayList)7 GenericFile (com.seleniumtests.reporter.logger.GenericFile)2 HarCapture (com.seleniumtests.reporter.logger.HarCapture)2 Har (net.lightbody.bmp.core.har.Har)2 HarLog (net.lightbody.bmp.core.har.HarLog)2 HarPage (net.lightbody.bmp.core.har.HarPage)2 ScreenShot (com.seleniumtests.driver.screenshots.ScreenShot)1 Snapshot (com.seleniumtests.reporter.logger.Snapshot)1 ScenarioLogger (com.seleniumtests.util.logging.ScenarioLogger)1 File (java.io.File)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 Document (org.jdom2.Document)1 Element (org.jdom2.Element)1 JDOMException (org.jdom2.JDOMException)1