Search in sources :

Example 1 with XMLHandler

use of com.lazerycode.ebselen.handlers.XMLHandler in project Ebselen by Ardesco.

the class IDEToEbselen method generateTestCode.

/**
     * Reads in a sky.sns.selenium IDE file and creates Sky Selenium format test code
     *
     * @param filename - Selenium IDE file to convert
     * @return Name of the Selenium IDE file
     * @throws Exception
     */
public String generateTestCode(String filename) throws Exception {
    FileHandler convertFrom = new FileHandler(convertToXML(filename));
    XMLHandler seleniumXMLFile = new XMLHandler(convertFrom.getFile());
    int commandCount = seleniumXMLFile.performXPathQueryReturnInteger("count(/html/body/table/tbody/tr)");
    for (int i = 1; i <= commandCount; i++) {
        String command = "";
        String target = "";
        String value = "";
        try {
            command = seleniumXMLFile.performXPathQueryReturnString("//table/tbody/tr[" + i + "]/td[1]");
            target = seleniumXMLFile.performXPathQueryReturnString("/html/body/table/tbody/tr[" + i + "]/td[2]");
            value = seleniumXMLFile.performXPathQueryReturnString("/html/body/table/tbody/tr[" + i + "]/td[3]");
        } catch (Exception Ex) {
            LOGGER.warn("Invalid command '{}' found", command);
        }
        addToTestCode(codeGenerator.convertCommandToEbselenCode(command, target, value));
    }
    convertFrom.close();
    return convertFrom.getFileName().split("\\.")[0];
}
Also used : XMLHandler(com.lazerycode.ebselen.handlers.XMLHandler) FileHandler(com.lazerycode.ebselen.handlers.FileHandler)

Example 2 with XMLHandler

use of com.lazerycode.ebselen.handlers.XMLHandler in project Ebselen by Ardesco.

the class XMLHandlerTest method addTextToElement.

@Test
public void addTextToElement() throws Exception {
    XMLHandler textBased = new XMLHandler("<?xml version=\"1.0\" encoding=\"UTF-8\"?><root><foo></foo></root>");
    textBased.addTextToElement("Some Text", "/root/foo");
    assertThat(textBased.returnXML(), is(equalTo("<?xml version=\"1.0\" encoding=\"UTF-8\"?><root><foo>Some Text</foo></root>")));
}
Also used : XMLHandler(com.lazerycode.ebselen.handlers.XMLHandler) Test(org.junit.Test)

Example 3 with XMLHandler

use of com.lazerycode.ebselen.handlers.XMLHandler in project Ebselen by Ardesco.

the class XMLHandlerTest method returnXMLAsString.

@Test
public void returnXMLAsString() throws Exception {
    URI normalXMLFile = this.getClass().getResource("/xml/normal.xml").toURI();
    XMLHandler normal = new XMLHandler(new File(normalXMLFile));
    String XMLResult = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root>" + cr + "    <foo>" + cr + "        <food>" + cr + "            <fruit>Apple</fruit>" + cr + "            <fruit>Banana</fruit>" + cr + "        </food>" + cr + "    </foo>" + cr + "</root>";
    assertThat(normal.returnXML(), is(equalTo(XMLResult)));
}
Also used : XMLHandler(com.lazerycode.ebselen.handlers.XMLHandler) URI(java.net.URI) File(java.io.File) Test(org.junit.Test)

Example 4 with XMLHandler

use of com.lazerycode.ebselen.handlers.XMLHandler in project Ebselen by Ardesco.

the class XMLHandlerTest method performXPathQueryWithNamespaceXML.

@Test
public void performXPathQueryWithNamespaceXML() throws Exception {
    URI namespaceXMLFile = this.getClass().getResource("/xml/namespace.xml").toURI();
    XMLHandler namespace = new XMLHandler(new File(namespaceXMLFile));
    assertThat(namespace.performXPathQueryReturnInteger("count(//atom:link)"), is(equalTo(2)));
    assertThat(namespace.performXPathQueryReturnInteger("count(//link)"), is(equalTo(3)));
}
Also used : XMLHandler(com.lazerycode.ebselen.handlers.XMLHandler) URI(java.net.URI) File(java.io.File) Test(org.junit.Test)

Example 5 with XMLHandler

use of com.lazerycode.ebselen.handlers.XMLHandler in project Ebselen by Ardesco.

the class XMLHandlerTest method addChildElement.

@Test
public void addChildElement() throws Exception {
    XMLHandler textBased = new XMLHandler("<?xml version=\"1.0\" encoding=\"UTF-8\"?><root></root>");
    textBased.addChildElement("foo", "/root");
    assertThat(textBased.returnXML(), is(equalTo("<?xml version=\"1.0\" encoding=\"UTF-8\"?><root><foo/></root>")));
}
Also used : XMLHandler(com.lazerycode.ebselen.handlers.XMLHandler) Test(org.junit.Test)

Aggregations

XMLHandler (com.lazerycode.ebselen.handlers.XMLHandler)8 Test (org.junit.Test)6 File (java.io.File)4 URI (java.net.URI)3 FileHandler (com.lazerycode.ebselen.handlers.FileHandler)2