javaseleniumtestngbddqaf

java.lang.NoClassDefFoundError: org/testng/IAnnotationTransformer2


I am getting the following error while runing testng config for QAFTestSteps:

Error shown

[RemoteTestNG] detected TestNG version 7.5.0
log4j:WARN No such property [follow] in org.apache.log4j.FileAppender.
java.lang.NoClassDefFoundError: org/testng/IAnnotationTransformer2
        at java.base/java.lang.ClassLoader.defineClass1(Native Method)
        at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1010)
        at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
        at 
java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:855)

Step Definitions

import java.util.List;


import com.qmetry.qaf.automation.step.QAFTestStep;

public class GoogleSearchSteps {
   
   
            @QAFTestStep(description = "user is on google Web Page")
            public void step1() {
                    System.out.println("I am on Google Search Page");

            }

            @QAFTestStep(description = "user enters text {strText} in google search box")
            public void iSearchFor(String strText) {
                    System.out.println("I search for " + strText);

            }

            @QAFTestStep(description="click on Google Search button")
            public void clickOnGoogleSearchButton(List<String> s) {
                    System.out.printf("List: %s\n", s);

            }
           
            @QAFTestStep(description="search result page should generate")
            public void searcgResultsShouldPopulate(List<String> s) {
                    System.out.printf("List: %s\n", s);

            }
        

}

Feature file

Feature: Text box validation

Scenario: Validate google search text box

   Given user is on google Web Page
   When user enters text 'DNA' in google search box
   And click on Google Search button
   Then search result page should generate

Testng Config for Test Execution

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="QAF Demo" verbose="0">
<test name="Gherkin-QAF-Test">
   <parameter name="step.provider.pkg" value="com.qmetry.qaf.automation.impl.step.qaf;" />
   <parameter name="scenario.file.loc" value="scenarios/searchtext.feature" />
   <classes>
      <class name="com.qmetry.qaf.automation.step.client.gherkin.GherkinScenarioFactory" />
   </classes>
</test>
</suite>

Solution

  • Looks like version compatibility issue. Use latest version of qaf 3.1.0-RC2 with testng 7.4.0.

    Updating version will fix above error, still you will see issue related to step. The reason is following steps:

    @QAFTestStep(description="click on Google Search button") //missing argument placeholder 
       public void clickOnGoogleSearchButton(List<String> s) {
          System.out.printf("List: %s\n", s);
       }
               
    @QAFTestStep(description="search result page should generate")//missing argument placeholder
       public void searcgResultsShouldPopulate(List<String> s) {
          System.out.printf("List: %s\n", s);
       }
    

    If your step (method) has arguments, step description need to have argument placeholder and those arguments needs to be passed where step called. See the example below:

    @QAFTestStep(description="click on Google Search button")
       public void clickOnGoogleSearchButton() {
          System.out.printf("clickOnGoogleSearchButton");
       }
               
    @QAFTestStep(description="search result page should generate {results}")
       public void searcgResultsShouldPopulate(List<String> s) {
          System.out.printf("List: %s\n", s);
       }
    

    feature file:

    Feature: Text box validation
    
    Scenario: Validate google search text box
    
       Given user is on google Web Page
       When user enters text 'DNA' in google search box
       And click on Google Search button
       Then search result page should generate ["a","b","c"]