Closed NewUser310 closed 7 years ago
I am not able to recreate the problem using TestNG 6.11 (The latest released version of TestNG)
Here's a trimmed down version of the test class
import org.testng.ITestContext;
import org.testng.TestNG;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.testng.xml.XmlClass;
import org.testng.xml.XmlSuite;
import org.testng.xml.XmlTest;
import java.util.Collections;
public class Practice {
public static void main(String[] args) {
for (String each : new String[]{"A", "B"}) {
runWith(each);
}
}
private static void runWith(String group) {
TestNG testNG = new TestNG();
XmlSuite xmlSuite = new XmlSuite();
xmlSuite.setName("suite");
XmlTest xmlTest = new XmlTest(xmlSuite);
xmlTest.setName("test");
xmlTest.addIncludedGroup(group);
XmlClass clazz = new XmlClass(Practice.class);
clazz.loadClasses();
xmlTest.getClasses().add(clazz);
testNG.setXmlSuites(Collections.singletonList(xmlSuite));
System.out.println(xmlSuite.toXml());
testNG.run();
}
@Test(dataProvider = "SearchProvider", groups = "A")
public void testMethodA(String author, String searchKey) {
System.out.println("testMethodA :" + author + ", " + searchKey);
}
@Test(dataProvider = "SearchProvider", groups = "B")
public void testMethodB(String searchKey) {
System.out.println("testMethodB :" + searchKey);
}
@DataProvider(name = "SearchProvider")
public Object[][] getDataFromDataprovider(ITestContext c) {
Object[][] groupArray = null;
for (String group : c.getIncludedGroups()) {
if (group.equalsIgnoreCase("A")) {
groupArray = new Object[][]{
{"Guru99", "India"},
{"Krishna", "UK"},
{"Bhupesh", "USA"}
};
break;
} else if (group.equalsIgnoreCase("B")) {
groupArray = new Object[][]{
{"Canada"},
{"Russia"},
{"Japan"}
};
}
break;
}
//return groupArray;
return groupArray;
}
}
Output:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="suite">
<test name="test">
<groups>
<run>
<include name="A"/>
</run>
</groups>
<classes>
<class name="com.rationaleemotions.github.issue1476.Practice"/>
</classes>
</test> <!-- test -->
</suite> <!-- suite -->
testMethodA :Guru99, India
testMethodA :Krishna, UK
testMethodA :Bhupesh, USA
===============================================
suite
Total tests run: 3, Failures: 0, Skips: 0
===============================================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="suite">
<test name="test">
<groups>
<run>
<include name="B"/>
</run>
</groups>
<classes>
<class name="com.rationaleemotions.github.issue1476.Practice"/>
</classes>
</test> <!-- test -->
</suite> <!-- suite -->
testMethodB :Canada
testMethodB :Russia
testMethodB :Japan
===============================================
suite
Total tests run: 3, Failures: 0, Skips: 0
===============================================
I am also using TestNG 6.11.0. I tried the same code you updated above but I am getting below error:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
@NewUser310 - Your error is not related to TestNG but it looks like its coming from selenium due to a mismatch between the selenium version and the firefox browser that you are using. Can you please run the sample that I shared and let us know if that works? My sample is a simple TestNG test that doesn't have any dependencies on other things but still adheres to the original test code you shared in terms of functional similarity.
I ran your code and with that I got the above error. I am unable to understand if there is any issue with my code.
@NewUser310 - Are you sure you ran the sample that I shared in https://github.com/cbeust/testng/issues/1476#issuecomment-315585696 ?
The sample I shared doesn't have any web driver code. Your error shows the involvement of WebDriver
. Please create a new Java class, copy paste the code that I shared, run that and please tell me what you see.
Yes
Exactly same i did. I created a new class and pasted your code. But got below error while running.
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
@NewUser310 - How are you running this ? My sample has a main method. Can you please rename the class to something else, and from within your IDE run it once again. The error still suggests that you aren't running what I shared, but perhaps your java class. Both the classes have the same name. Yours has web driver involved and mine doesn't. I think you are perhaps getting confused due to the same names.
I am trying in the same way you suggested. I created a new class and pasted your code. Tool asks me to run as Java code or TestNG. I select Java and after that once it runs, it displays me the below output. Can it be a reason that i tried to upgrade my Eclipse IDE (i know it may not be but just curious).
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
@NewUser310 - Ok, this is not going anywhere I guess. Can you please share screenshots of what you are doing ? The error is still the same. It is related to WebDriver and not TestNG. Your error says its having problems dealing with Firefox browser spawning. I guess it should be evident for you as well looking at your error logs.
ping @NewUser310 . Did you manage to get this resolved ?
Yes. thanks a lot for the prompt response.
Awesome. Can you please help close off the issue if it works fine ?
Thanks & Regards
Krishnan Mahadevan
"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/
From: NewUser310 notifications@github.com Reply-To: cbeust/testng reply@reply.github.com Date: Tuesday, July 18, 2017 at 7:52 AM To: cbeust/testng testng@noreply.github.com Cc: Krishnan Mahadevan krishnan.mahadevan1978@gmail.com, Comment comment@noreply.github.com Subject: Re: [cbeust/testng] Error "DataProvider must return either Object[][] or Iterator<Object>[], not class [[Ljava.lang.Object;" (#1476)
Yes. thanks a lot for the prompt response.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.
I am new to Selenium. I was using below code and getting the error as DataProvider must return either Object[][] or Iterator<Object>[], not class [[Ljava.lang.Object;
package example2;
Please let me know where is the issue.