Discussion:
[Cucumber] Running multiple stepDefinition and features from a single runner class
(too old to reply)
Priyam Ghosh
2017-11-01 12:24:09 UTC
Permalink
Raw Message
Hi,

I have two step definition files and two feature files. They are as below..

Feature 1:
Feature: Creating Multiple Features and Step Defintions

@Discount
Scenario Outline: Test discount combinations
Given Open browser and start application
When Enter "<weight>" and "<distance>"
Then Validate the output "<message>"

Examples:
| weight | distance | message |
| 100 | 200 |Datax shipping company offers discount|
| 80 | 500 |Datax shipping company offers discount|
| 120 | 520 |Datax shipping company offers discount|
| 300 | 200 |Datax shipping company offers discount|

Feature 2:
Feature: Creating Multiple Features and Step Defintions ND

@Nodiscount
Scenario Outline: Test No-discount combinations
Given Open browser and start application
When Enter "<weight_ND>" and "<distance_ND>"
Then Validate the output "<message_ND>"

Examples:
| weight_ND | distance_ND | message_ND |
| 60 | 110 | Datax shipping offers no discount |
| 50 | 150 | Datax shipping offers no discount |


Below are two Step definition files

Step Definition 1:
package StepDefinition;

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

import cucumber.api.java.After;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

import java.util.concurrent.TimeUnit;

import org.junit.Assert;

public class DiscountStepDefinition

{
WebDriver driver;

@Given("^Open browser and start application$")
public void setUp()
{
System.setProperty("webdriver.chrome.driver",
"C:\\Users\\377098\\Downloads\\chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("http://apps.qa2qe.cognizant.e-box.co.in/CompanyOffersDiscount/");

}

@When("^Enter \"([^\"]*)\" and \"([^\"]*)\"$")
public void testNodiscount(String weight, String distance)
{
driver.findElement(By.id("weight")).sendKeys(weight);
driver.findElement(By.id("distance")).sendKeys(distance);
driver.findElement(By.id("submit")).click();
}

@Then("^Validate the output \"([^\"]*)\"$")
public void validateResult(String Msg)
{
String expected_msg="Datax shipping company offers discount";
Assert.assertEquals(expected_msg, Msg);
}

@After
public void close_browser()
{
driver.quit();
}
}

Step Definition 2:
package StepDefinition;

import org.junit.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

public class NodiscountStepDefinition

{
WebDriver driver;
@When("^Enter \"([^\"]*)\" and \"([^\"]*)\"$")
public void Enter_and(String weight_ND, String distance_ND)
{
driver.findElement(By.id("weight")).sendKeys(weight_ND);
driver.findElement(By.id("distance")).sendKeys(distance_ND);
driver.findElement(By.id("submit")).click();
}

@Then("^Validate the output \"([^\"]*)\"$")
public void validateResult_ND(String message_ND)
{
String expected_msg=driver.findElement(By.id("Datax shipping offers no
discount")).getText();
Assert.assertEquals(expected_msg, message_ND);
}
}

Runner is as below:

package Runner;

import org.junit.runner.RunWith;

import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@Cucumber.Options(features = "Feature", glue={"StepDefinition"}, tags =
{"@Discount, @Nodiscount"})
public class CompanyJunit
{

}

But it is showing me that the 2nd feature is failing. I'm not sure what is
the problem. Can anybody help.

Regards,
Priyam
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Andrew Premdas
2017-11-01 19:07:22 UTC
Permalink
Raw Message
Priyam,

This is not a good way to ask for help. Some tips

- Get to the point quickly and show the error and its error message
- Link code rather than embed directly in your mail message
- Ideally link a sample project

So you could rewrite your message something like

-------------------

I have a sample project (link to project) which I have some issues with.

When I run

# command you use to start cucumber

I get

# output from command, ideally truncated to show just the important bit
of the error.

Any help much appreciated.

------------------

Its a good idea to read your mail before sending it and think 'Could I
answer this request for help?'

Please try again Priyam and maybe someone will be able to help you

All best

Andrew (mailing list moderator)
Post by Priyam Ghosh
Hi,
I have two step definition files and two feature files. They are as below..
Feature: Creating Multiple Features and Step Defintions
@Discount
Scenario Outline: Test discount combinations
Given Open browser and start application
When Enter "<weight>" and "<distance>"
Then Validate the output "<message>"
| weight | distance | message |
| 100 | 200 |Datax shipping company offers discount|
| 80 | 500 |Datax shipping company offers discount|
| 120 | 520 |Datax shipping company offers discount|
| 300 | 200 |Datax shipping company offers discount|
Feature: Creating Multiple Features and Step Defintions ND
@Nodiscount
Scenario Outline: Test No-discount combinations
Given Open browser and start application
When Enter "<weight_ND>" and "<distance_ND>"
Then Validate the output "<message_ND>"
| weight_ND | distance_ND | message_ND |
| 60 | 110 | Datax shipping offers no discount |
| 50 | 150 | Datax shipping offers no discount |
Below are two Step definition files
package StepDefinition;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import cucumber.api.java.After;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import java.util.concurrent.TimeUnit;
import org.junit.Assert;
public class DiscountStepDefinition
{
WebDriver driver;
@Given("^Open browser and start application$")
public void setUp()
{
System.setProperty("webdriver.chrome.driver",
"C:\\Users\\377098\\Downloads\\chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("http://apps.qa2qe.cognizant.e-box.co.in/
CompanyOffersDiscount/");
}
@When("^Enter \"([^\"]*)\" and \"([^\"]*)\"$")
public void testNodiscount(String weight, String distance)
{
driver.findElement(By.id("weight")).sendKeys(weight);
driver.findElement(By.id("distance")).sendKeys(distance);
driver.findElement(By.id("submit")).click();
}
@Then("^Validate the output \"([^\"]*)\"$")
public void validateResult(String Msg)
{
String expected_msg="Datax shipping company offers discount";
Assert.assertEquals(expected_msg, Msg);
}
@After
public void close_browser()
{
driver.quit();
}
}
package StepDefinition;
import org.junit.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
public class NodiscountStepDefinition
{
WebDriver driver;
@When("^Enter \"([^\"]*)\" and \"([^\"]*)\"$")
public void Enter_and(String weight_ND, String distance_ND)
{
driver.findElement(By.id("weight")).sendKeys(weight_ND);
driver.findElement(By.id("distance")).sendKeys(distance_ND);
driver.findElement(By.id("submit")).click();
}
@Then("^Validate the output \"([^\"]*)\"$")
public void validateResult_ND(String message_ND)
{
String expected_msg=driver.findElement(By.id("Datax shipping offers no
discount")).getText();
Assert.assertEquals(expected_msg, message_ND);
}
}
package Runner;
import org.junit.runner.RunWith;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@Cucumber.Options(features = "Feature", glue={"StepDefinition"}, tags =
public class CompanyJunit
{
}
But it is showing me that the 2nd feature is failing. I'm not sure what is
the problem. Can anybody help.
Regards,
Priyam
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
------------------------
Andrew Premdas
blog.andrew.premdas.org
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Chuck van der Linden
2017-11-02 16:48:12 UTC
Permalink
Raw Message
Post by Priyam Ghosh
Hi,
I have two step definition files and two feature files. They are as below..
Feature: Creating Multiple Features and Step Defintions
@Discount
Scenario Outline: Test discount combinations
Given Open browser and start application
When Enter "<weight>" and "<distance>"
Then Validate the output "<message>"
| weight | distance | message |
| 100 | 200 |Datax shipping company offers discount|
| 80 | 500 |Datax shipping company offers discount|
| 120 | 520 |Datax shipping company offers discount|
| 300 | 200 |Datax shipping company offers discount|
Feature: Creating Multiple Features and Step Defintions ND
@Nodiscount
Scenario Outline: Test No-discount combinations
Given Open browser and start application
When Enter "<weight_ND>" and "<distance_ND>"
Then Validate the output "<message_ND>"
| weight_ND | distance_ND | message_ND |
| 60 | 110 | Datax shipping offers no discount |
| 50 | 150 | Datax shipping offers no discount |
Below are two Step definition files
package StepDefinition;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import cucumber.api.java.After;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import java.util.concurrent.TimeUnit;
import org.junit.Assert;
public class DiscountStepDefinition
{
WebDriver driver;
@Given("^Open browser and start application$")
public void setUp()
{
System.setProperty("webdriver.chrome.driver",
"C:\\Users\\377098\\Downloads\\chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("
http://apps.qa2qe.cognizant.e-box.co.in/CompanyOffersDiscount/");
}
@When("^Enter \"([^\"]*)\" and \"([^\"]*)\"$")
public void testNodiscount(String weight, String distance)
{
driver.findElement(By.id("weight")).sendKeys(weight);
driver.findElement(By.id("distance")).sendKeys(distance);
driver.findElement(By.id("submit")).click();
}
@Then("^Validate the output \"([^\"]*)\"$")
public void validateResult(String Msg)
{
String expected_msg="Datax shipping company offers discount";
Assert.assertEquals(expected_msg, Msg);
}
@After
public void close_browser()
{
driver.quit();
}
}
package StepDefinition;
import org.junit.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
public class NodiscountStepDefinition
{
WebDriver driver;
@When("^Enter \"([^\"]*)\" and \"([^\"]*)\"$")
public void Enter_and(String weight_ND, String distance_ND)
{
driver.findElement(By.id("weight")).sendKeys(weight_ND);
driver.findElement(By.id("distance")).sendKeys(distance_ND);
driver.findElement(By.id("submit")).click();
}
@Then("^Validate the output \"([^\"]*)\"$")
public void validateResult_ND(String message_ND)
{
String expected_msg=driver.findElement(By.id("Datax shipping offers no
discount")).getText();
Assert.assertEquals(expected_msg, message_ND);
}
}
package Runner;
import org.junit.runner.RunWith;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@Cucumber.Options(features = "Feature", glue={"StepDefinition"}, tags =
public class CompanyJunit
{
}
But it is showing me that the 2nd feature is failing. I'm not sure what is
the problem. Can anybody help.
Regards,
Priyam
1) do not duplicate step definitions as you have done, a single step
definition for a given regex is sufficient, that's kinda the point of being
able to re-use your steps.

2) your first validation stepdef is useless as it never examines the
application, and just validates that the string passed in via the regex
equals a fixed string in the stepdef.. So it's never validating the
application, will always pass if the text passed into the step matches the
fixed text, always fail if it does not, regardless of if the application is
working properly or not.

3) The second validation stepdef is a better attempt, but I'm pretty sure
it will never find the element you are looking for as you have said to look
by ID, but the value you give has spaces and would not be a valid ID value
in HTML

4) what apremdas said about how to ask.

--Chuck
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...