Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help with this Cucumber Scenario?? #54

Closed
DThomas221 opened this issue Nov 23, 2020 · 7 comments
Closed

Help with this Cucumber Scenario?? #54

DThomas221 opened this issue Nov 23, 2020 · 7 comments

Comments

@DThomas221
Copy link

DThomas221 commented Nov 23, 2020

Hi, I'm a newbie who's been trying for hours to get cucumber scenario but I keep getting an error is my Scenario?

Step 1
Feature: Final Bill Calculation
@ScenarioOutlineExample
Scenario Outline: Customer Bill Amount Calculation
Given I have a Customer
And user enters intial bill amount as
And Sales Tax Rate is Percent
Then final bill amount calculated is

Examples: 
  | IntitialBillAmount | TaxRate | CalculatedBillAmount |
  |                100 |      10 |                  110 |
  |                200 |       8 |                  216 |
  |                100 |    1.55 |               101.55 |

Step 2

package stepdefinitions;

import static org.junit.Assert.assertTrue;

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

import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import linkedinlearning.cucumbercourse.BillCalculationHelper;

public class ScenarioOutlineSteps {

int InitalBillAmount;
double TaxRate;

@Given("I have a Customer")
public void i_have_a_Customer() {
	
}

@Given("user enters intial bill amount as {int}")
public void user_enters_intial_bill_amount_as(Integer initialBillAmount) {
    this.InitalBillAmount = initialBillAmount;
    System.out.println("InitialBillAmount: " + initialBillAmount);
}

@Given("Sales Tax Rate is {int} Percent")
public void sales_Tax_Rate_is_Percent(Integer taxRate) {
    // Write code here that turns the phrase above into concrete actions
   this.TaxRate = taxRate;
   System.out.println("Tax Rate: " + taxRate);
}

@Then("final bill amount calculated is {int}")
public void final_bill_amount_calculate_is(Integer expectedValue) {
	double SystemCalcValue = 
			  BillCalculationHelper.CalculateBillForCustomer(this.InitalBillAmount, this.TaxRate);
	  System.out.println("Expected Value: " + expectedValue);
	  System.out.println("Calculated Value: " + SystemCalcValue);
	  assertTrue(expectedValue == SystemCalcValue);

}

@Given("Sales Tax Rate is {double} Percent")
public void sales_Tax_Rate_is_Percent(Double taxRate) {
    this.TaxRate = taxRate;
    System.out.println("Tax Rate: " + taxRate);
}




private void invokeWebPage(Double expectedValue) {
	System.setProperty("webdriver.chrome.driver", "C:\\ChromeDriver\\chromedriver.exe");
	
	ChromeDriver driver = new ChromeDriver();
	
	driver.get("http://localhost:8080/BasicWebsite/Index.jsp");
	
	WebElement BillAmountTextBox = driver.findElement(By.id("billamount"));
	
	WebElement TaxRateTextBox = driver.findElement(By.id("taxrate"));
	
	WebElement Button = driver.findElement(By.id("mybutton"));
	
	BillAmountTextBox.sendKeys(Integer.toString(InitalBillAmount));
	
	TaxRateTextBox.sendKeys(Double.toString(TaxRate));
	
	Button.click();
	
	WebElement Header1Element = driver.findElementByXPath("//h1");
	
	System.out.println(Header1Element.getText());
	
	boolean Matched = Header1Element.getText().contains("Final Bill Amount is: $" + expectedValue.toString());
	
	System.out.println(Matched);
	

}

@Then("final bill amount calculated is {double}")
public void final_bill_amount_calculate_is(Double expectedValue) {
  double SystemCalcValue = 
		  BillCalculationHelper.CalculateBillForCustomer(this.InitalBillAmount, this.TaxRate);
  System.out.println("Expected Value: " + expectedValue);
  System.out.println("Calculated Value: " + SystemCalcValue);
  assertTrue(expectedValue == SystemCalcValue);	
  invokeWebPage(expectedValue);

}

}

Step 3

package testrunners;

import org.junit.runner.RunWith;

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

@RunWith(Cucumber.class)
@CucumberOptions(
features= {"src/test/java/linkedinlearning/cucumbercourse/features"},
glue = {"stepdefinitions"},
plugin= {"pretty",
"html:target/SystemTestReports/html",
"json:target/SystemTestReports/json/report.json",
"junit:target/SystemTestReports/junit/report.xml"},
tags = "@ScenarioOutlineExample",
dryRun = false,
monochrome = true
)
public class MenuManagementTest {

}

And I keep getting this answer:

@ScenarioOutlineExample
Scenario Outline: Customer Bill Amount Calculation # src/test/java/linkedinlearning/cucumbercourse/features/ScenarioOutlineExample.feature:12
Given I have a Customer # stepdefinitions.ScenarioOutlineSteps.i_have_a_Customer()
InitialBillAmount: 100
And user enters intial bill amount as 100 # stepdefinitions.ScenarioOutlineSteps.user_enters_intial_bill_amount_as(java.lang.Integer)
And Sales Tax Rate is 10 Percent # null
io.cucumber.core.runner.AmbiguousStepDefinitionsException: "Sales Tax Rate is 10 Percent" matches more than one step definition:
"Sales Tax Rate is {double} Percent" in stepdefinitions.ScenarioOutlineSteps.sales_Tax_Rate_is_Percent(java.lang.Double)
"Sales Tax Rate is {int} Percent" in stepdefinitions.ScenarioOutlineSteps.sales_Tax_Rate_is_Percent(java.lang.Integer)
at io.cucumber.core.runner.CachingGlue.findStepDefinitionMatch(CachingGlue.java:373)
at io.cucumber.core.runner.CachingGlue.stepDefinitionMatch(CachingGlue.java:341)
at io.cucumber.core.runner.Runner.matchStepToStepDefinition(Runner.java:146)
at io.cucumber.core.runner.Runner.createTestStepsForPickleSteps(Runner.java:126)
at io.cucumber.core.runner.Runner.createTestCaseForPickle(Runner.java:109)
at io.cucumber.core.runner.Runner.runPickle(Runner.java:70)
at io.cucumber.junit.PickleRunners$NoStepDescriptions.run(PickleRunners.java:151)
at io.cucumber.junit.FeatureRunner.runChild(FeatureRunner.java:135)
at io.cucumber.junit.FeatureRunner.runChild(FeatureRunner.java:27)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at io.cucumber.junit.Cucumber.runChild(Cucumber.java:199)
at io.cucumber.junit.Cucumber.runChild(Cucumber.java:90)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at io.cucumber.junit.Cucumber$RunCucumber.evaluate(Cucumber.java:234)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:542)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:770)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:464)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)

Then final bill amount calculate is 110 # null

@ScenarioOutlineExample
Scenario Outline: Customer Bill Amount Calculation # src/test/java/linkedinlearning/cucumbercourse/features/ScenarioOutlineExample.feature:13
Given I have a Customer # stepdefinitions.ScenarioOutlineSteps.i_have_a_Customer()
InitialBillAmount: 200
And user enters intial bill amount as 200 # stepdefinitions.ScenarioOutlineSteps.user_enters_intial_bill_amount_as(java.lang.Integer)
And Sales Tax Rate is 8 Percent # null
io.cucumber.core.runner.AmbiguousStepDefinitionsException: "Sales Tax Rate is 8 Percent" matches more than one step definition:
"Sales Tax Rate is {double} Percent" in stepdefinitions.ScenarioOutlineSteps.sales_Tax_Rate_is_Percent(java.lang.Double)
"Sales Tax Rate is {int} Percent" in stepdefinitions.ScenarioOutlineSteps.sales_Tax_Rate_is_Percent(java.lang.Integer)
at io.cucumber.core.runner.CachingGlue.findStepDefinitionMatch(CachingGlue.java:373)
at io.cucumber.core.runner.CachingGlue.stepDefinitionMatch(CachingGlue.java:341)
at io.cucumber.core.runner.Runner.matchStepToStepDefinition(Runner.java:146)
at io.cucumber.core.runner.Runner.createTestStepsForPickleSteps(Runner.java:126)
at io.cucumber.core.runner.Runner.createTestCaseForPickle(Runner.java:109)
at io.cucumber.core.runner.Runner.runPickle(Runner.java:70)
at io.cucumber.junit.PickleRunners$NoStepDescriptions.run(PickleRunners.java:151)
at io.cucumber.junit.FeatureRunner.runChild(FeatureRunner.java:135)
at io.cucumber.junit.FeatureRunner.runChild(FeatureRunner.java:27)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at io.cucumber.junit.Cucumber.runChild(Cucumber.java:199)
at io.cucumber.junit.Cucumber.runChild(Cucumber.java:90)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at io.cucumber.junit.Cucumber$RunCucumber.evaluate(Cucumber.java:234)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:542)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:770)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:464)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)

Then final bill amount calculate is 216 # null

@ScenarioOutlineExample
Scenario Outline: Customer Bill Amount Calculation # src/test/java/linkedinlearning/cucumbercourse/features/ScenarioOutlineExample.feature:14
Given I have a Customer # stepdefinitions.ScenarioOutlineSteps.i_have_a_Customer()
InitialBillAmount: 100
And user enters intial bill amount as 100 # stepdefinitions.ScenarioOutlineSteps.user_enters_intial_bill_amount_as(java.lang.Integer)
Tax Rate: 1.55
And Sales Tax Rate is 1.55 Percent # stepdefinitions.ScenarioOutlineSteps.sales_Tax_Rate_is_Percent(java.lang.Double)
Then final bill amount calculate is 101.55 # null

Also

cumcuber

cumcuber2

Please help me tell me what I did wrong??

@aslakhellesoy
Copy link
Contributor

So you have a step:

And Sales Tax Rate is 10 Percent

which has the following step text: Sales Tax Rate is 10 Percent

You have defined two step definitions:

@Given("Sales Tax Rate is {int} Percent")
public void sales_Tax_Rate_is_Percent(Integer taxRate) {
    // Write code here that turns the phrase above into concrete actions
   this.TaxRate = taxRate;
   System.out.println("Tax Rate: " + taxRate);
}

@Given("Sales Tax Rate is {double} Percent")
public void sales_Tax_Rate_is_Percent(Double taxRate) {
    this.TaxRate = taxRate;
    System.out.println("Tax Rate: " + taxRate);
}

Their expressions both match the step text, so Cucumber cannot determine which one you want to run. You have to remove the ambiguity. It's a bit like defining the same method twice. It's a kind of compile error.

I suggest you remove the first one and try again.

@DThomas221 DThomas221 changed the title Help with this Help with this Cucumber Scenario?? Nov 23, 2020
@DThomas221
Copy link
Author

Hey aslakhellesoy,

I also add a few more information

@aslakhellesoy
Copy link
Contributor

I assume you are happy with this answer. If not, please reopen.

@DThomas221
Copy link
Author

No, how do I reopen this question

@DThomas221
Copy link
Author

What about the multiple markers at this line??

@aslakhellesoy
Copy link
Contributor

Multiple markers at what line??

Please use the support forums for questions and discussions. We use GitHub issues to track bugs and contributions exclusively.

@DThomas221
Copy link
Author

100019209-437b3800-2da3-11eb-8b3e-5ccfcaf0637f
100019241-51c95400-2da3-11eb-91d9-513e852396a5

int InitalBillAmount;
double TaxRate;

@given("I have a Customer")
public void i_have_a_Customer() {

}

@given("user enters intial bill amount as {int}")
public void user_enters_intial_bill_amount_as(Integer initialBillAmount) {
this.InitalBillAmount = initialBillAmount;
System.out.println("InitialBillAmount: " + initialBillAmount);
}

@given("Sales Tax Rate is {int} Percent")
public void sales_Tax_Rate_is_Percent(Integer taxRate) {
// Write code here that turns the phrase above into concrete actions
this.TaxRate = taxRate;
System.out.println("Tax Rate: " + taxRate);
}

@then("final bill amount calculated is {int}")
public void final_bill_amount_calculate_is(Integer expectedValue) {
double SystemCalcValue =
BillCalculationHelper.CalculateBillForCustomer(this.InitalBillAmount, this.TaxRate);
System.out.println("Expected Value: " + expectedValue);
System.out.println("Calculated Value: " + SystemCalcValue);
assertTrue(expectedValue == SystemCalcValue);

}

@given("Sales Tax Rate is {double} Percent")
public void sales_Tax_Rate_is_Percent(Double taxRate) {
this.TaxRate = taxRate;
System.out.println("Tax Rate: " + taxRate);
}

private void invokeWebPage(Double expectedValue) {
System.setProperty("webdriver.chrome.driver", "C:\ChromeDriver\chromedriver.exe");

ChromeDriver driver = new ChromeDriver();

driver.get("http://localhost:8080/BasicWebsite/Index.jsp");

WebElement BillAmountTextBox = driver.findElement(By.id("billamount"));

WebElement TaxRateTextBox = driver.findElement(By.id("taxrate"));

WebElement Button = driver.findElement(By.id("mybutton"));

BillAmountTextBox.sendKeys(Integer.toString(InitalBillAmount));

TaxRateTextBox.sendKeys(Double.toString(TaxRate));

Button.click();

WebElement Header1Element = driver.findElementByXPath("//h1");

System.out.println(Header1Element.getText());

boolean Matched = Header1Element.getText().contains("Final Bill Amount is: $" + expectedValue.toString());

System.out.println(Matched);

}

@then("final bill amount calculated is {double}")
public void final_bill_amount_calculate_is(Double expectedValue) {
double SystemCalcValue =
BillCalculationHelper.CalculateBillForCustomer(this.InitalBillAmount, this.TaxRate);
System.out.println("Expected Value: " + expectedValue);
System.out.println("Calculated Value: " + SystemCalcValue);
assertTrue(expectedValue == SystemCalcValue);
invokeWebPage(expectedValue);

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants