Error – Test class not found in selected project in cucumber

I am new to cucumber. I followed your whole cucumber tutorial step by step. I f I run the selenium test it runs successfully. But When I run TestRunner class, it shows this error for Login Functionality, when double clicked.

For code, its same whats on your website. Please help …

Error - Test class not found in selected project in cucumber

Add Comment
  • 4 Answer(s)

    The element that you are trying to locate has invalid xpath. Can you recheck the xpath of the element and use the correct one. Try firebug to find the xpath. Here is the tutorial
    http://toolsqa.com/selenium-webdriver/xpath-firebug-firepath/

    Professor Answered on January 5, 2016.
    Add Comment

    Thanks virender for your reply.

    The reason this error is coming is : there is no login page.

    According to the code for cucumber tutorial, first my account button should be clicked, the login credentials should be entered and then after successful login you should logout.

    Now If I run selenium test this functionality is working. But with test runner class……. it is just opening the demo website in browser, not clicking on it.
    And it is directly going to the logout scenario. That y the error is there, as there is no logout button on the browser.

    So, my problem is why it is not entering into Given scenario.

    Thanks,
    Manasi

    Train Answered on January 5, 2016.
    Add Comment

    It seems that you are missing a step in step definition file. Can you please do two things
    – Share the feature file and the step definitions
    – Point me to the tutorial URL from where you have picked this up on ToolsQA. I will try to reproduce it.

    Thanks
    Virender

    Professor Answered on January 6, 2016.
    Add Comment

    Virender,

    Please find below the codes for festures file , step definition & test runner file.

    feature file

    
    Feature: Login Action
    Scenario: Successful Login with Valid Credentials
    
    Given User is on Home Page
    
    When User Navigate to LogIn Page
    
    And User enters UserName and Password
    
    Then Message displayed Login Successfully
    Scenario: Successful LogOut
    
    When User LogOut from the Application
    
    Then Message displayed LogOut Successfully
    

    Step Definition

    
    package stepDefinition;
    import java.util.concurrent.TimeUnit;
    import org.junit.rules.Timeout;
    
    import org.openqa.selenium.By;
    
    import org.openqa.selenium.WebDriver;
    
    import org.openqa.selenium.firefox.FirefoxDriver;
    import cucumber.api.PendingException;
    
    import cucumber.api.java.en.Given;
    
    import cucumber.api.java.en.Then;
    
    import cucumber.api.java.en.When;
    public class Test_Steps
    
    {
    
    public static WebDriver driver;
    @Given("^User is on Home Page$")
    
    public void user_is_on_Home_Page() throws Throwable
    
    {
    
    driver = new FirefoxDriver();
    
    driver.manage().window().maximize();
    
    driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
    
    driver.get("http://www.store.demoqa.com");
    
    throw new PendingException();
    
    }
    @When("^User Navigate to LogIn Page$")
    
    public void user_Navigate_to_LogIn_Page() throws Throwable
    
    {
    
    driver.findElement(By.xpath(".//*[@id='account']/a")).click();
    
    throw new PendingException();
    
    }
    @When("^User enters UserName and Password$")
    
    public void user_enters_UserName_and_Password() throws Throwable
    
    {
    
    driver.findElement(By.id("log")).sendKeys("abcdefg");
    
    driver.findElement(By.id("pwd")).sendKeys("123456789");
    
    driver.findElement(By.id("login")).click();
    
    throw new PendingException();
    
    }
    @Then("^Message displayed Login Successfully$")
    
    public void message_displayed_Login_Successfully() throws Throwable
    
    {
    
    System.out.println("Login Successfully");
    
    throw new PendingException();
    
    }
    @When("^User LogOut from the Application$")
    
    public void user_LogOut_from_the_Application() throws Throwable
    
    {
    
    driver.findElement (By.xpath(".//*[@id='account_logout']/a")).click();
    
    throw new PendingException();
    
    }
    @Then("^Message displayed LogOut Successfully$")
    
    public void message_displayed_LogOut_Successfully() throws Throwable
    
    {
    
    System.out.println("LogOut Successfully");
    
    driver.close();
    
    throw new PendingException();
    
    }
    
    }
    


    Test Runner

    package cucumberTest;
    import org.junit.runner.RunWith;
    
    import cucumber.api.CucumberOptions;
    
    import cucumber.api.junit.Cucumber;
    @RunWith(Cucumber.class)
    
    @CucumberOptions(
    
    features = "Feature",
    
    glue = {"stepDefinition"}
    
    )
    public class TestRunner {
    }
    

    Below hers is the link :

    http://toolsqa.com/cucumber/first-cucumber-selenium-java-test/

    Thanks,
    Manasi

    Train Answered on January 11, 2016.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.