如何在 TestNG 中解析 org.testng.internal.reflect.MethodMatcherException?
How to resolve org.testng.internal.reflect.MethodMatcherException in TestNG?
联系人页面Class:-
public class ContactsPage extends TestBase {
public ContactsPage()
{
PageFactory.initElements(driver, this);
}
public boolean contactsLabel()
{
return contactsLabel.isDisplayed();
}
public void createNewContact1(String subject, String fName, String lName, String petname ) throws InterruptedException, AWTException
{
.....
}
public void createNewContact2(String comp, String comPos, String dept, String conLookSup ) throws InterruptedException
{
.....
}
public void createNewContact3(String conLookAss, String conLookRef ) throws InterruptedException
{
.....
}
}
ContactsPageTestClass:-
public class ContactsPageTest extends TestBase {
TestUtil testUtil;
LoginPage loginpage;
HomePage homepage;
ContactsPage contactsPage;
String sheetName = "Contacts";
public ContactsPageTest() {
super();
}
@BeforeMethod()
public void setUp() throws InterruptedException {
initialzation();
testUtil = new TestUtil();
loginpage = new LoginPage();
homepage = loginpage.login(prop.getProperty("username"), prop.getProperty("password"));
contactsPage = new ContactsPage();
}
/*
* @Test(priority = 1) public void contactsLabelTest() throws
* InterruptedException { testUtil.switchToFrame(); contactsPage =
* homepage.contactsLink(); Thread.sleep(3000);
* Assert.assertTrue(contactsPage.contactsLabel(), "Exception has caught!"); }
*/
@DataProvider
public Object[][] getCRMTestData() {
Object data[][] = TestUtil.getTestData("Contacts");
return data;
}
@Test(priority = 2, dataProvider = "getCRMTestData")
public void createNewContactTest1(String subject, String fName, String lName, String petname)
throws InterruptedException, AWTException {
testUtil.switchToFrame();
homepage.moveToNewContact();
contactsPage.createNewContact1(subject, fName, lName, petname);
}
@Test(priority = 3, dataProvider = "getCRMTestData")
public void createNewContactTest2(String comp, String comPos, String dept, String conLookSup)
throws InterruptedException, AWTException
{
contactsPage.createNewContact2(comp, comPos, dept, conLookSup);
}
@Test(priority = 4, dataProvider = "getCRMTestData")
public void createNewContactTest3(String conLookAss, String conLookRef)
throws InterruptedException, AWTException
{
contactsPage.createNewContact3(conLookAss, conLookRef);
}
@AfterMethod
public void close() {
driver.close();
}
}
错误信息:
FAILED: createNewContactTest1
org.testng.internal.reflect.MethodMatcherException:
Data provider mismatch
Method: createNewContactTest1([Parameter{index=0, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=1, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=2, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=3, type=java.lang.String, declaredAnnotations=[]}])
Arguments: [(java.lang.String) Mr,(java.lang.String) Manideep,(java.lang.String) Latchupatula,(java.lang.String) Deep,(java.lang.String) Accenture,(java.lang.String) ASE,(java.lang.String) CSE,(java.lang.String) TL,(java.lang.String) NA,(java.lang.String) NA]
at org.testng.internal.reflect.DataProviderMethodMatcher.getConformingArguments(DataProviderMethodMatcher.java:45)
at org.testng.internal.Parameters.injectParameters(Parameters.java:796)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:982)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
描述:我正在使用 Selenium 开发混合框架。我以积极的态度开始,但我一直坚持:
org.testng.internal.reflect.MethodMatcherException.
我试了一段时间了,还是一头雾水。所以我来了。
你能告诉我问题出在哪里吗?
它抛出 MethodMatcherException 因为您将相同的数据提供程序传递给不同的 @Test 方法,并且每个测试方法都有不同的参数值。 @DataProvider 和@Test 方法的参数 return 必须匹配才能检索和分配数据。
您需要确定 returning 是什么数据提供者,并且您可以根据这些参数将其分配给测试方法。
Here your Data Provider is returning Parameters as Following: Its 10
Parameter [Mr,Manideep,Latchupatula,Deep, Accenture, ASE, CSE,TL, NA,
NA]
并且您将它与 @Test createNewContactTest1 方法的 4 个参数绑定:
createNewContactTest1(String subject, String fName, String lName, String petname)
您需要管理
您的数据提供程序检索代码根据您需要的参数或
您可以使用所需参数创建不同的 sheet 或
您可以根据 DP returns
将所有 10 个参数添加到 @Test 方法
联系人页面Class:-
public class ContactsPage extends TestBase {
public ContactsPage()
{
PageFactory.initElements(driver, this);
}
public boolean contactsLabel()
{
return contactsLabel.isDisplayed();
}
public void createNewContact1(String subject, String fName, String lName, String petname ) throws InterruptedException, AWTException
{
.....
}
public void createNewContact2(String comp, String comPos, String dept, String conLookSup ) throws InterruptedException
{
.....
}
public void createNewContact3(String conLookAss, String conLookRef ) throws InterruptedException
{
.....
}
}
ContactsPageTestClass:-
public class ContactsPageTest extends TestBase {
TestUtil testUtil;
LoginPage loginpage;
HomePage homepage;
ContactsPage contactsPage;
String sheetName = "Contacts";
public ContactsPageTest() {
super();
}
@BeforeMethod()
public void setUp() throws InterruptedException {
initialzation();
testUtil = new TestUtil();
loginpage = new LoginPage();
homepage = loginpage.login(prop.getProperty("username"), prop.getProperty("password"));
contactsPage = new ContactsPage();
}
/*
* @Test(priority = 1) public void contactsLabelTest() throws
* InterruptedException { testUtil.switchToFrame(); contactsPage =
* homepage.contactsLink(); Thread.sleep(3000);
* Assert.assertTrue(contactsPage.contactsLabel(), "Exception has caught!"); }
*/
@DataProvider
public Object[][] getCRMTestData() {
Object data[][] = TestUtil.getTestData("Contacts");
return data;
}
@Test(priority = 2, dataProvider = "getCRMTestData")
public void createNewContactTest1(String subject, String fName, String lName, String petname)
throws InterruptedException, AWTException {
testUtil.switchToFrame();
homepage.moveToNewContact();
contactsPage.createNewContact1(subject, fName, lName, petname);
}
@Test(priority = 3, dataProvider = "getCRMTestData")
public void createNewContactTest2(String comp, String comPos, String dept, String conLookSup)
throws InterruptedException, AWTException
{
contactsPage.createNewContact2(comp, comPos, dept, conLookSup);
}
@Test(priority = 4, dataProvider = "getCRMTestData")
public void createNewContactTest3(String conLookAss, String conLookRef)
throws InterruptedException, AWTException
{
contactsPage.createNewContact3(conLookAss, conLookRef);
}
@AfterMethod
public void close() {
driver.close();
}
}
错误信息:
FAILED: createNewContactTest1
org.testng.internal.reflect.MethodMatcherException:
Data provider mismatch
Method: createNewContactTest1([Parameter{index=0, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=1, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=2, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=3, type=java.lang.String, declaredAnnotations=[]}])
Arguments: [(java.lang.String) Mr,(java.lang.String) Manideep,(java.lang.String) Latchupatula,(java.lang.String) Deep,(java.lang.String) Accenture,(java.lang.String) ASE,(java.lang.String) CSE,(java.lang.String) TL,(java.lang.String) NA,(java.lang.String) NA]
at org.testng.internal.reflect.DataProviderMethodMatcher.getConformingArguments(DataProviderMethodMatcher.java:45)
at org.testng.internal.Parameters.injectParameters(Parameters.java:796)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:982)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
描述:我正在使用 Selenium 开发混合框架。我以积极的态度开始,但我一直坚持:
org.testng.internal.reflect.MethodMatcherException.
我试了一段时间了,还是一头雾水。所以我来了。
你能告诉我问题出在哪里吗?
它抛出 MethodMatcherException 因为您将相同的数据提供程序传递给不同的 @Test 方法,并且每个测试方法都有不同的参数值。 @DataProvider 和@Test 方法的参数 return 必须匹配才能检索和分配数据。
您需要确定 returning 是什么数据提供者,并且您可以根据这些参数将其分配给测试方法。
Here your Data Provider is returning Parameters as Following: Its 10 Parameter [Mr,Manideep,Latchupatula,Deep, Accenture, ASE, CSE,TL, NA, NA]
并且您将它与 @Test createNewContactTest1 方法的 4 个参数绑定:
createNewContactTest1(String subject, String fName, String lName, String petname)
您需要管理
您的数据提供程序检索代码根据您需要的参数或
您可以使用所需参数创建不同的 sheet 或
您可以根据 DP returns
将所有 10 个参数添加到 @Test 方法