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 "'<>&");
}
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"));
}
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: (******)");
}
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)");
}
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));
}
}
Aggregations