1

In our Application, We have webservices which are communicating with the other sub systems We are implementing cucumber BDD framework for testing. We have cucumber feature file, Step def file and Runner class. Currently, in development environment Test cases are running successfully and Test report got generated in target folder. We have used Java along with spring boot to build the project When we are trying to configure the cucumber framework with different environments we are facing difficulty to get the cofig.properties details. Application URL :http://127.0.0.1:8783//plan/apr For different environments we are giving the ipaddress and port as follows DNA : 172.34.56.89:61142

Could you please help us to configure the cucumber test cases in different environments

config.properties file

#DEV DEV.ENV=http://127.0.0.1:8476/plan/apr

#DNA DNA.ENV=http://172.25.193.330:62251/plan/apr

#Model E ModelE.ENV=http://172.25.343.210:62342/plan/apr

#Model B ModelB.ENV=http://172.25.123.234:61234/plan/apr

Properties class :

public class RetriveCucumberProperties { public ExternalUrlPropKeys propKeys;

String baseUrl;
protected static final String URL = ".url";


@Bean
public String RetriveCucumberProperties() {
    
    FeatureFilePropertiesReader featureFilePropertiesReader = SpringContext
            .getBean(FeatureFilePropertiesReader.class);

    if (URL.equals("DEV.ENV")) {
        Properties url = featureFilePropertiesReader.getSubset(URL);
        baseUrl = url.getProperty(URL);
    } else if (URL.equals("DNA.ENV")) {
        Properties url = featureFilePropertiesReader.getSubset(URL);
        baseUrl = url.getProperty(URL);
    } else if (URL.equals("ModelE.ENV")) {
        Properties url = featureFilePropertiesReader.getSubset(URL);
        baseUrl = url.getProperty(URL);
    } else if (URL.equals("ModelB.ENV")) {
        Properties url = featureFilePropertiesReader.getSubset(URL);
        baseUrl = url.getProperty(URL);
    }
    return baseUrl;
}

}

Step def class :

@Given("the user is on the login page") public void the_user_is_on_the_login_page() throws IOException {

        ObjectMapper objectMapper = new ObjectMapper();
         JsonNode jsonNode = objectMapper.readTree(new File(".\\JSON\\Cardplanning.json"));
         String user = jsonNode.get("LOGIN").get("LOGIN_URL").asText();
        
    }
    @SuppressWarnings("deprecation")
    @When("the user enters valid  {string} and {string}")
    public void the_user_enters_valid_and(String username, String password) throws IOException {
       
        RestAssured.baseURI = retriveCucumberProperties.RetriveCucumberProperties()+"/login";
        RequestSpecification http = RestAssured.given();
      

        ObjectMapper objectMapper = new ObjectMapper();
        JsonNode jsonNode = objectMapper.readTree(new File(".\\JSON\\Cardplanning.json"));
         String user = jsonNode.get("LOGIN").get("username").asText();
         String pass = jsonNode.get("LOGIN").get("password").asText();
         
         http.header("Content-Type" , "application/json");
         http.body(jsonNode.toString());
         Response response = http.request(Method.POST,"/login");
         String resposebj = response.getBody().asString();
         ResponseBody body = response.body();
         String bodyobj = body.asString();
         Assert.assertEquals(bodyobj.contains(username), false);
         Assert.assertEquals(bodyobj.contains(password), false);
        
         int statuscode = response.getStatusCode();
         Assert.assertEquals(statuscode, 404);  
    }
    

I have tried the way you have explained but unable to to retrive the URL.

  1. How I can get URL in step def file according to the selection is URL based on env
  2. How I can integrate with maven properties, so that i can test from the maven commands like mvn test -Dtest=dev

Could you please help on this.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.