I'm trying to use the testng.xml... and looks like Device Farm is ignoring the whole file.
My example is simple. I have a factory class that instantiate test classes, and this is how my xml file looks like
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Default Suite">
<test name="test">
<classes>
<class name="Factory"/>
</classes>
</test>
</suite>
I even tried to exclude methods manually
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Default Suite">
<test name="test">
<classes>
<class name="Factory"/>
<class name="TestSingleUrl">
<methods>
<exclude name="testCorrectSiteKey"/>
<exclude name="testIsTagImplemented"/>
<exclude name="testHttpsScheme"/>
<exclude name="testCorrectTagName"/>
<exclude name="testCorrectBootstrapPath"/>
</methods>
</class>
</classes>
</test>
</suite>
But I'm getting a "Can't invoke method: either make it static or create a non-args constructor" . Which means that the Device Farm is trying to run the methods from TestSingleUrl Class..But the one who call these test should be the factory
Does anyone know how can we make the Device Farm to accept our xml file?
This is my Factory Class:
public class Factory{
private String targetSiteKey;
//Data Provider that consumes the first line, which contains the target sitekey of the tag
@DataProvider(name = "urlProvider")
public Iterator<Object[]> createData() throws IOException {
List<String> lines = IOUtils.readLines(new InputStreamReader(this.getClass().getResourceAsStream("Urls.csv")));
List<Object[]> objectArrays = lines.stream().map(x -> new Object[]{x}).collect(Collectors.toList());
Iterator<Object[]> itr = objectArrays.iterator();
targetSiteKey = itr.next()[0].toString();
return itr;
}
@Factory(dataProvider="urlProvider")
public Object[] creatingTests(String url){
System.out.println(System.currentTimeMillis());
String siteKey=null;
String path = null;
String tagName = null;
WebElement browsi;
try{
RemoteWebDriver driver = DriverWrapper.getDriver();
driver.get(url);
browsi = driver.findElement(By.id("browsi-tag"));
tagName = browsi.getTagName();
siteKey = browsi.getAttribute("data-sitekey");
path = browsi.getAttribute("src");
}catch(Exception ignored){}
finally{
return new Object[] {new TestSingleUrl(targetSiteKey,siteKey,path,tagName,url)};
}
}
}
And this is my TestSingleUrl Class:
public class TestSingleUrl {
private String targetSiteKey,siteKey,path,tagName,url;
public TestSingleUrl(String targetSiteKey,String siteKey, String path, String tagName,String url){
this.targetSiteKey = targetSiteKey;
this.siteKey=siteKey;
this.path=path;
this.tagName=tagName;
this.url=url;
}
@Test
public void testCorrectSiteKey(){
System.out.println(url);
Assert.assertEquals(siteKey, targetSiteKey);
}
@Test
public void testIsTagImplemented(){
System.out.println(url);
Assert.assertFalse(siteKey.isEmpty());
Assert.assertFalse(tagName.isEmpty());
Assert.assertFalse(path.isEmpty());
}
@Test
public void testHttpsScheme(){
System.out.println(url);
Assert.assertTrue(path.contains("https"));
}
@Test
public void testCorrectTagName(){
System.out.println(url);
Assert.assertEquals(tagName,"script");
}
@Test
public void testCorrectBootstrapPath(){
System.out.println(url);
Assert.assertTrue(path.contains("middycdn-a.akamaihd.net/bootstrap/bootstrap.js"));
}
}
I think that the error messages I'm getting is because the device farm is trying to run every method with a @Test annotation that it finds. If it was reading my xml file it wouldn't happen.