2
votes

When I try to run the TestRunner.java then I see the following error:

initializationError(0.000s)

java.lang.IllegalArgumentException: baseDir must exist: C:\com\newtours\qa\features at io.cucumber.core.resource.PathScanner.findResourcesForPath(PathScanner.java:42) at io.cucumber.core.resource.PathScanner.findResourcesForUri(PathScanner.java:26) at io.cucumber.core.resource.ResourceScanner.findResourcesForUri(ResourceScanner.java:111) at io.cucumber.core.resource.ResourceScanner.scanForResourcesUri(ResourceScanner.java:88) at io.cucumber.core.runtime.FeaturePathFeatureSupplier.loadFeatures(FeaturePathFeatureSupplier.java:62) at io.cucumber.core.runtime.FeaturePathFeatureSupplier.get(FeaturePathFeatureSupplier.java:46) at io.cucumber.junit.Cucumber.(Cucumber.java:156) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500) at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481) 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:59) at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26) at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59) at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33) 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:525) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)

I tried giving the full path of both feature file as well as step definition but still same issue occur.

Following are the files which are in use:

1. Login.java

package com.newtours.qa.stepdefinition;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import io.cucumber.java.en.And;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.When;

public class Login
{
    WebDriver driver;
    String expectedTitle = "ToolsQA – Demo Website to Practice Automation – Demo Website to Practice Automation";

    @Given("user is already on login page")
    public void user_is_already_on_login_page() throws Throwable
    {
        System.setProperty("webdriver.chrome.driver", "..\\CucumberMavenProject\\Drivers\\chromedriver.exe");
        driver = new ChromeDriver();
        driver.manage().window().maximize();
        driver.get("https://www.phptravels.org/clientarea.php");
        System.out.println("User navigates to URL");
        throw new io.cucumber.java.PendingException();
    }

    @And("username and password are entered")
    public void username_and_password_are_entered() throws Throwable
    {
        //String actualtitle = driver.getTitle();
        driver.findElement(By.cssSelector("#inputEmail")).sendKeys("abe");
        driver.findElement(By.cssSelector("#inputPassword")).sendKeys("aaa");
        System.out.println("User enters login details ");
        throw new io.cucumber.java.PendingException();  
    }
    @When("user clicks on signin button")
    public void user_clicks_on_signin_button() throws Throwable
    {

        driver.findElement(By.cssSelector("#login")).click();
        System.out.println("User clicks login button");
        throw new io.cucumber.java.PendingException();
    }
}

2. Login.feature

Feature: Demo Tours Test

@SmokeTest
Scenario: Demo Tours Login with valid credentials

Given user is already on login page
And username and password are entered
When user clicks on signin button
Then user should see home page

3. TestRunner.java

package com.newtours.qa.runner;

import org.junit.runner.RunWith;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;

@RunWith(Cucumber.class)

@CucumberOptions
(
        strict = true,
        dryRun = false,
        monochrome = true,
        features = "\\com\\newtours\\qa\\features",
        glue    = "\\com\\newtours\\qa\\stepdefinition"
)

public class TestRunner
{

}

Project Structure:

[]

3

3 Answers

2
votes

The path to the features should be relative and what you have there seems to be from root. It is looking for C:\com\newtours\qa\features instead of looking at the folder where you actually have the com/newtours/qa/features.

Therefore I suggest you use relative path like: src/main/java/com/newtours/qa/features. Similarly do this for the glue.

1
votes

Path looks incorrect. Try

features = "src/main/java/com/newtours/qa/features",
glue = "com.newtours.qa.stepdefinition"
0
votes

In runner file:

features = "absolute path to feature file or package name of feature file"
glue = "package name of step definition"
  • path to feature file can be absolute path in case there are multiple feature files (C:\Users\CucumberMavenProject\src\main\java\com\newtours\qa\features\login.feature) or just package name ("src/main/java/com/newtours/qa/features")

  • in glue give the package name where the step definition is stored. You cannot have multiple step definition files under the step definition package. You need to create new step definition package for each feature file - "com.newtours.qa.stepdefinition"