2
votes
@QAFDataProvider(dataFile = "src/test/resources/data/logintestdata.csv")
@Test(testName="testLoginPage", description="Login Page landing validation", priority=1, groups={"SMOKE"})
public void testLoginPage(Map<String, Object> data) {       

    // QAF - Qmetry Automation Framework calls

      get("/"); // Check base url in src/test/resources/application.properies file

      verifyText("login.box.header", "Sign In");
      verifyLinkWithTextPresent("Or Sign Up");
      verifyPresent("login.input.username");
      verifyPresent("login.input.password");
      verifyPresent("login.button.submit");
}

[Error] org.testng.TestNGException: Cannot inject @Test annotated Method [testLoginPage] with [interface java.util.Map]. For more information on native dependency injection please refer to http://testng.org/doc/documentation-main.html#native-depend ency-injection at org.testng.internal.Parameters.checkParameterTypes(Parameters.java:244) at org.testng.internal.Parameters.createParameters(Parameters.java:172) at org.testng.internal.Parameters.createParameters(Parameters.java:458) at org.testng.internal.Parameters.handleParameters(Parameters.java:568) at org.testng.internal.Invoker.handleParameters(Invoker.java:1293) at org.testng.internal.Invoker.createParameters(Invoker.java:1020) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1110) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)

1
if I remove parameter from the method, then it doesn't error out. But the question is how can I use the data from dataFile inside the test method body. e.g. data.get("username") and data.get("password")Ashis Raj
Could you show the entire class?LppEdd
Which version of QAF and TestNG you are using? Also make sure you are providing correct path of the file may be resources/data/logintestdata.csv.user861594
QAF version - 2.1.13, TestNG version - 6.10. I have overridden the default path of data file into pom file as below. I believe this works fine as all my properties and locator files are being successfully read and loaded by WebDriverTestCase class. <systemPropertyVariables> <application.properties.file>${project.basedir}/src/test/resources</application.properties.file> </systemPropertyVariables>Ashis Raj
Try changing method argument from Map<String, Object> to Map<String, String> as you are using 2.1.13 or update qaf version to 2.1.14user861594

1 Answers

0
votes

As you have already noticed your method does not work with java.util.Map as parameter. Have you tried to use a DataProvider instead?

Here a short example:

@DataProvider(name = "data")
public static Object[][] dataProvider() {
    return new Object[][] { { "key1", "value1" }, { "key2", "value2" }};
}

@Test(dataProvider = "Authentication")
public void testLoginPage(String key, String value) {     
  //do something
}

The method testLoginPage gets called once for each key value pair in your data provider. Not sure if it works with java.util.Map as well.