Is there an accepted way (or code already written) to input complex data to TestNG from external file(s)?
For example, using TestNG and HTMLUnit, I might want to define a bunch of URLs, and custom Xpath tests in either a separate XML file, or in the testng file, extract it and then use it as a dataProvider.
For example inputing this file to testNG (either as a separate file, or as part of testng.xml):
<pages>
<url value="http://www.bar.com">
<element-exists>
<xpath>//div[@class='baz']</xpaths>
<xpath>//div[@class='bat']</xpath>
</element-exists>
</url>
<url value="http://www.bar.com/foo">
...
</url>
</pages>
Would tell my tests to run against bar.com and bar.com/foo, running some element-exists assertions against the pages. Possible? If so, how? I understand using dataProviders to parameterize tests and using @Factory to conditionally create test cases, but how to get TestNG to read the input? Any best practices are appreciated.
Read the data in your @DataProvider and feed it in your test method, which will receive this data as parameters. It should be quite straightforward.