Module 23 testng error Cannot inject @Test annotated Method [openBrowser] with [class java.lang.String]. | Selenium Forum

Module 23 testng error Cannot inject @Test annotated Method [openBrowser] with [class java.lang.String].

R
ramu.gande Post on 27/12/2019

Base Test code

 

package com.qtpselenium1.core.ddf.base;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.Test;

import com.beust.jcommander.Parameters;

public class BaseTest {

public WebDriver driver;

@Test
public void openBrowser(String bType) {

if(bType.equals("Mozilla")) {
System.setProperty("webdriver.gecko.driver", "F:\\driversnew\\geckodriver.exe");
driver=new FirefoxDriver();
}


else if(bType.equals("Chrome")) {

driver=new ChromeDriver();
}


else if(bType.equals("IE")) {

driver=new InternetExplorerDriver();
}


}

 

 

Test B

 

package com.qtpselenium1.core.ddf.testcases;

import org.testng.annotations.Test;

import com.qtpselenium1.core.ddf.base.BaseTest;

public class DummyTestB extends BaseTest{

@Test
public void testB() {

openBrowser("Firefox");



}
}

 

i am getting following error for this

 


PASSED: testB
FAILED: openBrowser
org.testng.TestNGException:
Cannot inject @Test annotated Method [openBrowser] with [class java.lang.String].
For more information on native dependency injection please refer to http://testng.org/doc/documentation-main.html#native-dependency-injection
at org.testng.internal.Parameters.checkParameterTypes(Parameters.java:458)
at org.testng.internal.Parameters.createParametersForMethod(Parameters.java:372)
at org.testng.internal.Parameters.createParameters(Parameters.java:729)
at org.testng.internal.Parameters.handleParameters(Parameters.java:895)
at org.testng.internal.Parameters.handleParameters(Parameters.java:762)
at org.testng.internal.ParameterHandler.handleParameters(ParameterHandler.java:60)
at org.testng.internal.ParameterHandler.createParameters(ParameterHandler.java:39)
at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:771)
at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:145)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
at java.util.ArrayList.forEach(ArrayList.java:1257)
at org.testng.TestRunner.privateRun(TestRunner.java:770)
at org.testng.TestRunner.run(TestRunner.java:591)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:402)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:396)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:355)
at org.testng.SuiteRunner.run(SuiteRunner.java:304)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1180)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1102)
at org.testng.TestNG.runSuites(TestNG.java:1032)
at org.testng.TestNG.run(TestNG.java:1000)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)


===============================================
Default test
Tests run: 2, Failures: 1, Skips: 0

S

Instructor

Support Team Reply on 09/01/2020

As I can see the code, you are parameterizing the test case, But you have missed the dependency to provide the parameterized data. 

I request you to refer the video again carefully.