Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 98819

Cucumber not able to read the definition file

$
0
0

I am a beginner in Cucumber and i have written a basic tests for login and going to the homepage using in a maven project. I suspect there is some consistency issue with POM.xml.

Please find below the files I have tried with multiple combinations for the dependencies in pom file but seems the issue persists.

1) stepdefination file

package StepDefinition;

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


public class loginStepDefinition {

    WebDriver driver;


@Given("^User is already on login page$")
  public void user_already_on_login_page(){
    System.setProperty("webdriver.chrome.driver","/Users/nilesh.gupta/Desktop/chromedriver" );
    driver = new ChromeDriver();
    driver.get("https://classic.crmpro.com");

   }
@When("^Tittle of login page is Free CRM$")
public void tittle_login_page_is_Free_CRM() {
    String tittle = driver.getTitle();
    System.out.println("tittle is : " + tittle);
    Assert.assertEquals("#1 Free CRM for Any Business: Online Customer Relationship Software", tittle);
}
@Then("^User enters username and password$")
public void user_enters_username_and_password() {
    driver.findElement(By.xpath("/html/body/div[2]/div/div[3]/form/div/input[1]\n" )).sendKeys("naveenk");
    driver.findElement(By.xpath("/html/body/div[2]/div/div[3]/form/div/input[2]\n" )).sendKeys("test@123");
}

@Then("^User clicks on login button$")
public void user_clicks_on_login_button() {
     driver.findElement(By.className("btn btn-small")).click();
}

@Then("^User is on Home Page$")
public void user_is_on_Home_Page() {
   String tittle= driver.getTitle();
   System.out.println("tittle is : " + tittle );
   Assert.assertEquals("CRMPRO", tittle);
}

}

  1. login.feature
Feature: Free CRM Login Feature

  Scenario: Free CRM Login Test Scenario

    Given User is already on login page
    When  Tittle of login page is Free CRM
    Then  User enters username and password
    Then  User clicks on login button
    Then User is on Home Page



  1. testrunner.java
package MyRunner;

import org.junit.runner.RunWith;

import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;

@RunWith(Cucumber.class)
@CucumberOptions(
        features = "/Users/nilesh.gupta/eclipse-workspace/CucumberBDD/src/main/java/Features/login.feature",
        glue={"stepDefinition"}
        /*format={"pretty","html:test-output"}*/
)
public class testRunner {
}

  1. pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>CucumberBDD</groupId>
  <artifactId>CucumberBDD</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>CucumberBDD</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <cucumber.version>4.8.0</cucumber.version>
    <selenium.version>3.5.3</selenium.version>
  </properties>

  <dependencies>

       <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>${cucumber.version}</version>
        </dependency>

      <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>${cucumber.version}</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>${selenium.version}</version>
        </dependency>
  </dependencies>
</project>

  1. Output

There were undefined steps. You can implement missing steps with the snippets below:

@Given("User is already on login page")
public void user_is_already_on_login_page() {
    // Write code here that turns the phrase above into concrete actions
    throw new cucumber.api.PendingException();
}

@When("Tittle of login page is Free CRM")
public void tittle_of_login_page_is_Free_CRM() {
    // Write code here that turns the phrase above into concrete actions
    throw new cucumber.api.PendingException();
}

@Then("User enters username and password")
public void user_enters_username_and_password() {
    // Write code here that turns the phrase above into concrete actions
    throw new cucumber.api.PendingException();
}

@Then("User clicks on login button")
public void user_clicks_on_login_button() {
    // Write code here that turns the phrase above into concrete actions
    throw new cucumber.api.PendingException();
}

@Then("User is on Home Page")
public void user_is_on_Home_Page() {
    // Write code here that turns the phrase above into concrete actions
    throw new cucumber.api.PendingException();
}


Viewing all articles
Browse latest Browse all 98819

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>