2
@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)

Ashis Raj
  • 53
  • 4
  • 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 Feb 24 '19 at 14:35
  • Could you show the entire class? – LppEdd Feb 24 '19 at 14:40
  • 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 Feb 24 '19 at 18:57
  • 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. ${project.basedir}/src/test/resources – Ashis Raj Feb 26 '19 at 08:50
  • Try changing method argument from Map to Map as you are using 2.1.13 or update qaf version to 2.1.14 – user861594 Feb 26 '19 at 16:01
  • Still not working using both ways. – Ashis Raj Feb 27 '19 at 17:26
  • Can you share entire log as well as your java class? – user861594 Feb 27 '19 at 20:47

1 Answers1

0

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.

AndiCover
  • 1,724
  • 3
  • 17
  • 38
  • Thanks. But I want to use QAFDataProvider instead of TestNG DataProvider. – Ashis Raj Feb 24 '19 at 16:12
  • Why can't you use the TestNG DataProvider? Maybe you could try using both? Using your QAFDataProvider method to call a TestNG DataProvider and use that in your test method. – AndiCover Feb 24 '19 at 16:17
  • I want to use only one of them and using QAFDataProvider has an advantage of not writing code to read and load data. – Ashis Raj Feb 25 '19 at 12:50
  • 1
    Here is the QAF doc reference for using QAFDataProvider. [link](https://qmetry.github.io/qaf/latest/maketest_data_driven.html#java) The document suggests that it should work that way, but why it is giving TestNG error? – Ashis Raj Feb 25 '19 at 12:54
  • @cjayswal please help. – Ashis Raj Feb 26 '19 at 05:36
  • Try changing method argument from Map to Map as you are using 2.1.13. refer 2.1.13 documentation. – user861594 Feb 26 '19 at 16:00