0

Team, Problem statement: Scenario2 should skip if dependent scenario1 gets fail. Need some support to fix this issue. Reference: I took reference from below link Skip Dependent scenario issue Issue: End up with error after added @dependsOnMethods:['scenario1']

**Caused by: org.testng.TestNGException: 
Method "scenarios.suite1.feature.scenario2()[pri:2, instance:com.qmetry.qaf.automation.step.client.Scenario@2]" depends on nonexistent method "scenario1"**

Example Feature file:

```Feature: Google Search

@priority:1`enter code here`
Scenario: Scenario1
Given COMMENT: "SC1"
And Call negative step

@priority:2 @dependsOnMethods:['scenario1']
Scenario: Scenario2
Given COMMENT: "SC2" ```

    
**I used same listener from the above link**

public class DependecyListener implements ITestListener {

@Override
public void onTestStart(ITestResult result) {
ITestNGMethod method = result.getMethod();
String[] methodsDependedUpon = method.getMethodsDependedUpon();
if (method.isTest() && null != methodsDependedUpon && methodsDependedUpon.length > 0) {
List<String> methodsDependedUponLst = Arrays.asList(methodsDependedUpon);
IResultMap failedTests = result.getTestContext().getFailedTests();
List<ITestResult> falildMethodsDependedUpon = failedTests.getAllResults().stream()
.filter(t -> methodsDependedUponLst.contains(t.getName())).collect(Collectors.toList());
if(!falildMethodsDependedUpon.isEmpty()) {
throw new SkipException("Skipped because of dependency failure!");
}
}

} 


StepLibrary.Java

    ```@QAFTestStep(description = "Call negative step")
        public static void iCallNegativeStep() {
        System.out.println("Enter into Neg");
        Assert.assertEquals(true, false,"Called Negative step" );
            
        }```

Console Log:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running TestSuite
log4j:WARN No such property [follow] in org.apache.log4j.FileAppender.
Added "QAFMethodSelector"
[ConfigurationManager] - ISFW build info: {qaf-Type=core, qaf-Revision=0b, qaf-Build-Time=24-Oct-2021 19:53:30, qaf-Version=3.1}
[ConfigurationManager] - Resource dir: D:\Temp\DelDepIssue\qaf-blank-project-maven-master\resources. Found property files to load: 6
[ConfigurationManager] - Resource dir: D:\Temp\DelDepIssue\qaf-blank-project-maven-master\resources. Found property files to load: 0
include groups []
 exclude groups: [] Scanarios location:  
org.apache.maven.surefire.util.SurefireReflectionException: java.lang.reflect.InvocationTargetException; nested exception is java.lang.reflect.InvocationTargetException: null
java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:567)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
    at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:172)
    at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:104)
    **at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:70)
Caused by: org.testng.TestNGException: 
Method "scenarios.suite1.feature.Scenario2()[pri:2, instance:com.qmetry.qaf.automation.step.client.Scenario@2]" depends on nonexistent method "scenario1"**
    at org.testng.DependencyMap.getMethodDependingOn(DependencyMap.java:65)
    at org.testng.TestRunner.createDynamicGraph(TestRunner.java:1041)
    at org.testng.TestRunner.privateRun(TestRunner.java:723)
    at org.testng.TestRunner.run(TestRunner.java:610)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:387)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:382)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
    at org.testng.SuiteRunner.run(SuiteRunner.java:289)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1293)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1218)
    at org.testng.TestNG.runSuites(TestNG.java:1133)
    at org.testng.TestNG.run(TestNG.java:1104)
    at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:122)
    at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:92)
    at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:101)
     9 more
Preparing For Shut Down...
[ResultUpdator] - Using QAF Json Reporter

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  6.142 s
[INFO] Finished at: 2022-03-08T00:09:40+05:30
[INFO] ------------------------------------------------------------------------
Rafeek
  • 61
  • 6

1 Answers1

0

While specifying dependency, method name value need to be exact same including upper/lower case, it is case sensitive. In your case when providing method name in dependsOnMethods you didn't provided name in the same case. For instance, method name is Scenario1 and in dependsOnMethods it is provided scenario1, if you observer it is not equal considering case sensitivity. That's why it complains that depends on nonexistent method scenario1. You can correct as sample below:

Scenario: Scenario1
Given COMMENT: "SC1"
And Call negative step

@priority:2 @dependsOnMethods:['Scenario1'] 
Scenario: Scenario2

user861594
  • 5,733
  • 3
  • 29
  • 45