1

Error I am getting is:

java.util.NoSuchElementException while running junit test. Here is full error from console in eclipse:
java.util.NoSuchElementException
at java.base/java.util.ArrayList$Itr.next(ArrayList.java:970)
at java.base/java.util.Collections.max(Collections.java:713)
at io.cucumber.core.feature.FeatureParser.parseResource(FeatureParser.java:45)
at java.base/java.util.function.BiFunction.lambda$andThen$0(BiFunction.java:70)
at io.cucumber.core.resource.ResourceScanner.lambda$processResource$1(ResourceScanner.java:79)
at io.cucumber.core.resource.PathScanner$ResourceFileVisitor.visitFile(PathScanner.java:75)
at io.cucumber.core.resource.PathScanner$ResourceFileVisitor.visitFile(PathScanner.java:60)
at java.base/java.nio.file.Files.walkFileTree(Files.java:2811)
at io.cucumber.core.resource.PathScanner.findResourcesForPath(PathScanner.java:53)
at io.cucumber.core.resource.PathScanner.findResourcesForUri(PathScanner.java:31)
at io.cucumber.core.resource.ResourceScanner.findResourcesForUri(ResourceScanner.java:61)
at io.cucumber.core.resource.ResourceScanner.scanForResourcesUri(ResourceScanner.java:134)
at io.cucumber.core.runtime.FeaturePathFeatureSupplier.loadFeatures(FeaturePathFeatureSupplier.java:62)
at io.cucumber.core.runtime.FeaturePathFeatureSupplier.get(FeaturePathFeatureSupplier.java:45)
at io.cucumber.junit.Cucumber.<init>(Cucumber.java:156)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at  java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:70)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:37)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:70)
at org.junit.internal.requests.ClassRequest.createRunner(ClassRequest.java:28)
at org.junit.internal.requests.MemoizingRequest.getRunner(MemoizingRequest.java:19)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(JUnit4TestLoader.java:90)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:76)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:49)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:513)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:756)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)

Library I am using:

enter image descriptioen here

My Testrunner script is:

package TestRunner;

import org.junit.runner.RunWith;
import org.openqa.selenium.NoSuchElementException;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;

@RunWith(Cucumber.class)                
@CucumberOptions(features="C:\\Users\\Ashok Kumar\\eclipse-workspace\\CucumberWithSelenium\\Features",glue={"StepDefinition"})

public class Runner {

}

My steps script:

package StepDefinition;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.NoSuchElementException;

//import io.cucumber.java.*;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;

import io.cucumber.java.en.When;
//import cucumber.api.junit.Cucumber;

public class Steps {
    WebDriver driver = null; 
    
    @Given("^I am on Facebook login page$") 
    /*
    public void goToFacebook() { 
           WebDriver driver = new ChromeDriver();
           driver.get("https://www.facebook.com"); 
           driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
       } */
      
    @Given("^Open the Chrome and launch the application$")              
    public void open_the_Chrome_and_launch_the_application() throws Throwable{
        
        System.out.println("This Step open the Firefox and launch the application.");                   
    }       

    @When("^Enter the Username and Password$")                  
    public void enter_the_Username_and_Password() throws Throwable                          
    {       
       System.out.println("This step enter the Username and Password on the login page.");                  
    }       

    @Then("^Reset the credential$")                 
    public void Reset_the_credential() throws Throwable                             
    {           
        System.out.println("This step click on the Reset button.");                 
    }   
}

I have searched all previous posts in google on java.util.NoSuchElementException. But still I didn't come to webdriver as you have seen above. I did comment it as I have come across this error. I have tried even with WebDriver code above, still I am getting the error. Please help me. I am unable to edit java.base/java.util.ArrayList$Itr.next using next I have seen in google.

Elikill58
  • 4,050
  • 24
  • 23
  • 45
  • I am trying to learn BDD framework and this is my first attempt. Excuse me if I am unable to explain my error in proper order. Thanks – ashok tumuluri Mar 24 '22 at 11:03
  • I am getting error in POM. Appreciate if someone can share one POM with latest dependencies. I have tried a lot with Maven and without Maven, finally ended in errors. I am new. I am unable to post my second question. IT says spam when I am trying to post. Guide me. Thanks – ashok tumuluri Mar 24 '22 at 14:26
  • seems like one of the annotations is throwing this... I would start with a basic tutorial on cucumber. First thing is probably how to setup your IDE and dependencies. https://cucumber.io/docs/guides/10-minute-tutorial/ – pcalkins Mar 24 '22 at 18:57

1 Answers1

0

Thanks God. I found a solution or work around. Here is what I had done.

  1. Had converted the project to Maven project.

  2. I have mentioned latest dependencies

  3. Here is my POM.

    4.0.0 CucumberWithSelenium CucumberWithSelenium 0.0.1-SNAPSHOT src maven-compiler-plugin 3.8.1 17
         <dependency>
             <groupId>io.cucumber</groupId>
             <artifactId>cucumber-java</artifactId>
             <version>7.2.3</version>
         </dependency>
    
         <dependency>
             <groupId>io.cucumber</groupId>
             <artifactId>cucumber-junit</artifactId>
             <version>7.2.3</version>
         </dependency>
    
         <dependency>
             <groupId>io.cucumber</groupId>
             <artifactId>cucumber-jvm-deps</artifactId>
             <version>1.0.6</version>
         </dependency>
    
         <dependency>
             <groupId>net.masterthought</groupId>
             <artifactId>cucumber-reporting</artifactId>
             <version>1.0.0</version>
         </dependency>
    
         <dependency>
             <groupId>io.cucumber</groupId>
             <artifactId>gherkin</artifactId>
             <version>22.0.0</version>
         </dependency>
    
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <version>4.13.2</version>
         </dependency>
    
    
         <dependency>
             <groupId>org.seleniumhq.selenium</groupId>
             <artifactId>selenium-java</artifactId>
             <version>4.1.2</version>
         </dependency>
    
         <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-picocontainer -->
         <dependency>
             <groupId>io.cucumber</groupId>
             <artifactId>cucumber-picocontainer</artifactId>
             <version>7.2.3</version>
         </dependency>
    
    
     </dependencies>