How to Call a Python Script with Arguments from Java class

 In this post you will learn How to Call a Python Script with Arguments from Java class , pass arguments using ProcessBuilder class, using process builder class we can execute python file and provide multiple arguments in string format.

How to Call a Python Script with Arguments from Java class

To run ProcessBuilder class will use Process interface with start method.

Using sys library we can save arguments into String array in python file and get arguments into python file with the help of index based like sys.argv[0],sys.argv[1] and sys.argv[2].

You can get python script lines using Bufferedreader class using process.getinputstream() method .


Java ProcessBuilder not able to run Python script

Using ProcessBuilder to execute a python script with arguments

Run external python file with arguments from Java

Selenium Java Cucumber BDD Framework from Scratch

Selenium Java Cucumber BDD Framework from Scratch,Cucumber supports Behavior Driven Development (BDD) ,Cucumber reads executable plain text specifications which is written in Gherkin language in the form of Given, Then, And, But etc keywords.

Step Definitions connects Gherkin steps to programming the code and try to execute the step definitions as mentioned in Feature Files.

Cucumber Selenium Framework from Scratch helps to create Selenium framework using Maven project ,user able to create Feature files based on scenarios. Able to run selenium test scripts with test runner class.

Selenium Cucumber project gives you flavors of 

1.Set Up maven dependency

2.Write User acceptance test cases.

3.Able to create Junit reports

4.Able to map Step definitions to Cucumber glue

5.User can run multiple feature files from runner class.



How to Make a POST Request with Rest Assured?

In previous post you've learned Rest API Testing using Rest Assured and in this below post you will learn How to Make a POST Request with Rest Assured library.In this below code uses requestSpecBuilder to make a post request. Parameter descriptions are listed below.

restAPIURL – URL of the Rest API
APIBody – Body of the Rest API. Example: {"key1":"value1","key2":"value2"}
setContentType() – Pass the "application/json", "application/xml" or "text/html" etc. headers to setContenType() method.
Authentication credentials – Pass the username and password to the basic() method or if there is no authentication leave them blank basic("","")

How to Make a POST Request with Rest Assured


public class RestAssured {


 @Test
 public void httpPostMethodTest() throws JSONException, InterruptedException {

  //Rest API's URL
  String restAPIUrl = "http://{RestAPIURL}";

  //API Body
  String apiBody = "{\"key1\":\"value1\",\"key2\":\"value2\",\"key3\":\"value3\"}";

  // Building request by using requestSpecBuilder
  RequestSpecBuilder builder = new RequestSpecBuilder();

  //Set API's Body
  builder.setBody(apiBody);

  //Setting content type as application/json
  builder.setContentType("application/json; charset=UTF-8");

  RequestSpecification requestSpec = builder.build();

  //Making post request with authentication or leave blank if you don't have credentials like: basic("","")
  Response response = given().authentication().preemptive().basic({
    username
   }, {
    password
   })
   .spec(requestSpec).when().post(restAPIUrl);

  JSONObject JSONResponseBody = new JSONObject(response.body().asString());

  //Get the desired value of a parameter
  String result = JSONResponseBody.getString({
   key
  });

  //Check the Result
  Assert.assertEquals(result, "{expectedValue}");

 }
}