0

Details:

We currently use Mockito/ Wiremock (in different teams), Junit and Cucumber in our test procedure.

And test cases are functional, but we want to extend them with regard to post procedures.

Currently we have a test case that asks for the customer ID (used here is Mockito + Wiremock + Junit 4 different Teams) this test should now in a further step use the customer ID (that he has determined) to create another test case based on the determined customer ID.

Source:

Feature File Information: (Working Scenario), in the Give part we only start Mockito or Wiremock

Feature File Example:

When <headerName_PropFile> and <headerValue_PropFile> is added to request
When POST request for <JsonRequest> is sent
Then response code is the <StatusCode>
Then Validate Responses <expectedValue1>
Then Validate Response <expectedValue2>
Then Validate against Swagger

In the further course we have of course adapted the API according to Cucumber, there given,when, then formulated, but we are missing a possibility how we could use the step definition results like a determined customer ID in further steps.

Example for API + Cucumber

      @When("^PATCH request for (.+) is sent")
      public void sendPatchRequestF3(String requestBodyFile) throws Throwable {​​​​
      //GenerateReport.stepName = "When PATCH request is sent with request body";
      Object requestBody = setDataInJSON(getValue(requestBodyFile));
      request.body(requestBody.toString());
      FilterableRequestSpecification httpRequest = (FilterableRequestSpecification) request;

      Reporter.addStepLog("Request URL : " + httpRequest.getURI());
      sendRequest("PATCH");
      Reporter.addStepLog("Response Body: " + response.prettyPrint());
      //GenerateReport.reportStepStatus("pass", "Response body: " + response.prettyPrint());
      }​​​​

Questions:

  • How can we integrate values determined in further steps into the feature file in such a way that the new values are integrated accordingly, thus creating new test queries?
5
  • 1
    Did you do any research? Have you read e.g. stackoverflow.com/q/43067617/3001761? – jonrsharpe Nov 24 '20 at 12:12
  • yes but i use other search string ;) Thank´s for the informations, i will take a look on it. Maybe my answer is special? – Mornon Nov 24 '20 at 12:13
  • 1
    FWIW I searched for google.com/search?q=cucumber+use+value+returned+from+step and got a lot of results. If your specific context is special, edit to clarify. – jonrsharpe Nov 24 '20 at 12:15
  • Many thanks for your help. I think I found what I was looking for, you were right about the search. Should I remove the post again, or leave it for now? or do you want to write an answer that I and others can rate? – Mornon Nov 24 '20 at 12:40
  • I don't think it would be appropriate to copy across someone else's post. It doesn't seem like there's a discoverability problem, I'd suggest deleting. – jonrsharpe Nov 24 '20 at 12:50
1

You can simply use a global variable. Save it in a base class that you inherit or you can import a helper class/file in your test.

// DataFile.java
class DataFile {
    string myVar;
}
// Test1.java
import DataFile;
...
@Then("I get and save my response") {
    DataFile.myVar = thing1.value;
}

// Test2.java
import DataFile;
...
@When("I submit my new code") {
     string thing1 = DataFile.myVar;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.