'Is there a way to concatenate data from a cucumber feature file and a base class?

I can pass data to my test through parameters from a cucumber feature file, for example, an API URL https://gorest.co.in/public/v1/users.

@get-request
Feature: Get Request

  Scenario: Send GET request
    When I send a valid GET request to 'https://gorest.co.in/public/v1/users'

Another option is to fetch the data from a util class, instead of fetching it from the feature file:

@Data
public class RestUtil {

  private String url = "https://gorest.co.in/public/v1/users";
 
}

I can then pass the URL data to my test like this:

public class MyClass{

  private static Response response;
  RestUtil restUtil = new RestUtil();


  public void sendGetRequestT{
    RequestSpecification httpRequest = given()
            .header("Content-Type", "application/json");

    response = httpRequest
            .when()
            .get(restUtil.getUrl()).andReturn(); //the full URL is passed here
  }

What I am curious to know is if it's possible to get the baseURI from a util class and the endpoint from the feature file, so that concatenating the two would give me the full API URL. Something like this:

Passing only endpoint in the feature file

@get-request
Feature: Get Request

  Scenario: Send GET request
    When I send a valid GET request to 'public/v1/users' //pass endpoint only

Passing only the baseUri in the util class:

@Data
public class RestUtil {

  private String baseUri = "https://gorest.co.in"; //pass the baseUri onlu
 
}

I would like to concatenate the baseUri from util and the endpoint from the feature file, so that I can the full URL to pass in my test.

Is this possible or am I expecting too much from Cucumber-Java?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source