Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
259 views
by Master (1.2k points)
retagged by
I am developing a Keyword Driven framework. How do I read it from XML?

2 Answers

0 like 0 dislike
by
Use testng.

Using testng is is so easy to read data from xml.
0 like 0 dislike
by The go-to Tester (142 points)

Try using SAXReader library.

Here is the sample program.

public static DOM4JSettingsNode readSettingsFile(ImportInteraction importInteraction, FileFilter fileFilter) {

    File file = importInteraction.promptForFile(fileFilter);

    if (file == null) {

        return null;

    }

    if (!file.exists()) {

        importInteraction.reportError("File does not exist: " + file.getAbsolutePath());

        return null;  //we should really sit in a loop until they cancel or give us a valid file.

    }

    try {

        SAXReader reader = new SAXReader();

        Document document = reader.read(file);

        return new DOM4JSettingsNode(document.getRootElement());

    } catch (Throwable t) {

        LOGGER.error("Unable to read file: " + file.getAbsolutePath(), t);

        importInteraction.reportError("Unable to read file: " + file.getAbsolutePath());

        return null;

    }

}

You should import

import org.dom4j.io.SAXReader; 


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

...