0

I have the path to my XML file on my computer, but how can I use selenium (web automation tool) to inject the XML file ?

Usually how it is done (manually) is navigate to the URL and COPY AND PASTE the entire XML text into the provided text box..

Any ideas how to inject the file using automation ? There is no way to "drag" the XML file to the text box and I believe the way I'm thinking that it will work is very complicated.

1
  • What's it being used for? I highly doubt that physically injecting it into the page is the way to go. Commented Dec 18, 2012 at 19:14

3 Answers 3

1

I think this is actually what you want -

File xml = new File("xmlpath");

String url = xml.getAbsolutePath();
url = url.replace('\\', '/');
url = url.replace(" ", "%20");

String actual = "file:/" + url;

selenium.open(actual);

Then you should be able to get the xml using String theXML = selenium.getText("//rootxmlnode"); Then do what you will with it.

Sign up to request clarification or add additional context in comments.

2 Comments

Author of question asked, how he could inject XML file, not evaluate it.
Strange and complicated method. Your first variant of answer was closer to the idea.
1

Check out the topic of Data Driven Testing to get you started. Something like this should get you going.

Comments

1

Selenium tool allows you to create an automatically generated code in Java. So, you need to place any text in the provided text box and generate this Java-test code. Next step is modifying of the generated test. You have to manually write a simplest code, which will read your XML file, get it contents and paste into the text box. The last thing is replacement (in the generated Java code of test!) of the mentioned above text-block to the contents of read XML.

A simplest way for reading file into a string is using Apache commons-io library. For example: FileUtils.readFileToString(File file, String encoding) gives you a string object with contents of the file.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.