Monday, 18 May 2020

How to log automation execution status to Extent Report? Write the code for Extent Report log execution status? SDET



Details of the methods and class used in the code:

  • public = access modifier
  • void= will not return anything
  • ITestResultorg.testng.ITestResult and it describes result of test
  • getStatus()=to fetch the execution status of test case
  • ExtentReport.extentlog.log=Logs events for the test
  • ExtentReport.extentreport.endTest= Ends and prepares the test to be added to the report on flush()
****************CODE START*********************

public void getResult(ITestResult result) {

        if (result.getStatus() == ITestResult.SUCCESS) {

            ExtentReport.extentlog.log(LogStatus.PASS, "Test case is passed "+ "Test" );

        } else if (result.getStatus() == ITestResult.FAILURE) {
            ExtentReport.extentlog.log(LogStatus.FAIL, "Test case is failed " );
            ExtentReport.extentlog.log(LogStatus.FAIL, "Test case is failed " + result.getThrowable());
        } else if (result.getStatus() == ITestResult.SKIP) {
            ExtentReport.extentlog.log(LogStatus.SKIP, "Test case is Skiped " + result.getName());
        }
        ExtentReport.extentreport.endTest(ExtentReport.extentlog);
    }

***************************CODE END********
Note: If anyone need help in designing framework or virtual support for Automation work then reach out to me @sidharth.shukla19@gmail.com/9619094122
***********************************
For training check the Training link as below:
Training Details
More content for Interview preparation:RestAPI
SQL Query   Cucumber-BDD    Linux Commands    Maven   GIT 

TestNG@after@before
 

*************************************************



Learn (API-Microservice)Testing+(CoreJava+UI)-SDET with Self Paced Videos and one LIVE Doubt Session

TRANING VIDEOS AVAILABLE with Live Doubt Session @4500/-(course-1 below,API TRaining Videos With ClassNotes and Coding Set) and 6500/- (API+UI, both course-1 & 2 below) Check Training Page for Course Content or reach out @whatsapp +91-9619094122

Entire course content can be found below:  COURSE CONTENTCheck below link for question and answers with code:

API Testing Interview Question Set:
https://automationreinvented.blogspot.com/search/label/Rest-API

 
Kubernetes Interview Question Set
https://automationreinvented.blogspot.com/search/label/Kubernetes

 
Docker Interview Question Set
https://automationreinvented.blogspot.com/2020/02/top-18-docker-commands-for-aytomation.html

 
Linux Interview question Set
https://automationreinvented.blogspot.com/search/label/Linux

 
Automation Testing/SDET Framework Design
https://automationreinvented.blogspot.com/search/label/FrameworkDesign


Java Related Interview Question Set

https://automationreinvented.blogspot.com/search/label/Java


GIT Interview Question Set:
https://automationreinvented.blogspot.com/search/label/GIT


Coding Interview Question Set:
https://automationreinvented.blogspot.com/search/label/Coding%20Questions

Sunday, 17 May 2020

How to read properties file and fetch data? Write code to read common.properties file?


  • In below code filepath parameter will contain the path where we will keep the properties file and key parameter is the name of the value which we want fetch.
  • public is the access modifier
  • static  so that we can access the class without creating object
  • String is the return type of propertyReader function

============================
public static String propertyReader(String filePath,String key)

{
        String value = null;
       
        //Inputstream is required while loading into properties
   
       try (InputStream input = new FileInputStream(filePath))
        {
           
           // object creation for Property class
            Properties prop = new Properties();

            // load a properties file
            prop.load(input);

            //getProperty will fetch the value according to the key
            value=prop.getProperty(key);
         

        } catch (IOException ex) {
            ex.printStackTrace();
        }
        return value;
       
    }


Want to learn more about Framework Design, do check out below link :



 

************************************************* 

API Testing Interview Question Set:
https://automationreinvented.blogspot.com/search/label/Rest-API

 
Kubernetes Interview Question Set
https://automationreinvented.blogspot.com/search/label/Kubernetes

 
Docker Interview Question Set
https://automationreinvented.blogspot.com/2020/02/top-18-docker-commands-for-aytomation.html

 
Linux Interview question Set
https://automationreinvented.blogspot.com/search/label/Linux

 
Automation Testing/SDET Framework Design 
https://automationreinvented.blogspot.com/search/label/FrameworkDesign


Java Related Interview Question Set

https://automationreinvented.blogspot.com/search/label/Java


GIT Interview Question Set:
https://automationreinvented.blogspot.com/search/label/GIT


Coding Interview Question Set:
https://automationreinvented.blogspot.com/search/label/Coding%20Questions

***********************************
Note: If anyone need help in designing framework or virtual support for Automation work then reach out to me @sidharth.shukla19@gmail.com/9619094122
***********************************
For training check the Training link as below:
Training Details
More content for Interview preparation:
How to add execution status to Extent Report

Friday, 15 May 2020

Automate GET request with Rest Assured? API Automation interview question on Rest Assured?



Requirement:
- Automate GET api for endpoint: /api/users and validate status code as 200

=================CodeStart================
@Test

        //public is access modifier and void as nothing is returned for getusers()

        public void getusers()
   
        {
           
            // resp will contain the response from the api get method for /api/users?page=2
       
            Response resp = given()
                    .when().get("serverURL/api/users?page=2");
           
            //save the actual status code in integer variable, variable name is actualstatuscode

            int actualstatuscode = resp.getStatusCode();
           
            //print the status code in the console
            System.out.println(resp.getStatusCode());

           //print the response body in console
            System.out.println(resp.getBody().asString());
           
            //validating actual status code that we got from API response with the expected status code 200
            assertEquals(200,actualstatuscode);
           
        }

===============CodeEnd================
Note :
Import below in your package before using the code and add rest assured/testng jar:
import static io.restassured.RestAssured.given;
import static org.testng.Assert.assertEquals;
import org.testng.annotations.Test;
import io.restassured.response.Response;
====================================
Note: If anyone need help in designing framework or virtual support for Automation work then reach out to me @sidharth.shukla19@gmail.com/9619094122 
**************************************
For training check the Training link as below:
Training Details
Check below link on top Interview preparation topics:RestAPI
SQL Query   Cucumber-BDD    Linux Commands    Maven   GIT 

TestNG@after@before
 

*************************************************

API Testing Interview Question Set:
https://automationreinvented.blogspot.com/search/label/Rest-API

 
Kubernetes Interview Question Set
https://automationreinvented.blogspot.com/search/label/Kubernetes

 
Docker Interview Question Set
https://automationreinvented.blogspot.com/2020/02/top-18-docker-commands-for-aytomation.html

 
Linux Interview question Set
https://automationreinvented.blogspot.com/search/label/Linux

 
Automation Testing/SDET Framework Design
https://automationreinvented.blogspot.com/search/label/FrameworkDesign


Java Related Interview Question Set

https://automationreinvented.blogspot.com/search/label/Java


GIT Interview Question Set:
https://automationreinvented.blogspot.com/search/label/GIT


Coding Interview Question Set:
https://automationreinvented.blogspot.com/search/label/Coding%20Questions



Wednesday, 6 May 2020

How to extract data from JSON file in Java? Automation/SDET interview question to parse JSON?




Java Interview question Set-1:
SET-01 1-10

Java Interview question Set-2:

SET-02 10-20

Java Interview question Set-3:

SET-03 21-30


Data driven testing for Selenium and Rest Assured with Json file

Learn how to extract data from a JSON file in Java, we will discuss two ways, but any method can be used in your framework, Remember to add it to Utility.
This will help us to perform Data driven testing for Selenium and Rest Assured with Json file.

There are two ways we can fetch data from the JSON file:
- using jsonobject
- using jsonpath

Let's discuss both the approaches.

How to fetch test data from json file using jsonobject

1. Create a testdata.json file


2. Create a method which will fetch value from json object using key


public static String getTestData(String input) throws IOException, ParseException {
        String testdata;
        return testdata = (String) getJsonData().get(input);//input is the key
       
    }
   

3. Create a method as  getJsonData() with return type as JsonObject


public static JSONObject getJsonData() throws IOException, ParseException  {
       
        //pass the path of the testdata.json file
        File filename = new File("TestData//testdata.json");
        //convert json file into string
        String json = FileUtils.readFileToString(filename, "UTF-8");
        //parse the string into object
        Object obj = new JSONParser().parse(json);
        //give jsonobject o that I can return it to the function everytime it get called
        JSONObject jsonObject = (JSONObject) obj;
        return jsonObject;

    }
To learn more about JSON please refer below link:



How to fetch test data from json file using jsonPath?

    Note: Use https://jsonpath.com/ to write your own jsonpath

    1. Create a testdata.json file


    2. Create a method which will fetch value from json object using key


public static String getdatafromjson(String path) throws IOException {
       
        File f = new File("TestData//testdata.json");
        String json = FileUtils.readFileToString(f, "UTF-8");
        String result;
        return result = JsonPath.read(json, path);
       
    }

There is one more way to do the same which is by using the POJO class, check the post below for all the steps in json to pojo conversion:





Want to learn more about Framework Design, do check out the link below for configuration properties and extent reporting:



Java Interview question Set-1:
SET-01 1-10

Java Interview question Set-2:

SET-02 10-20

Java Interview question Set-3:

SET-03 21-30


Learn (API-Microservice)Testing+(CoreJava+UI)-SDET with Self Paced Videos and one LIVE Doubt Session

TRANING VIDEOS AVAILABLE with Live Doubt Session @4500/-(course-1 below,API TRaining Videos With ClassNotes and Coding Set) and 6500/- (API+UI, both course-1 & 2 below) Check Training Page for Course Content or reach out @whatsapp +91-9619094122
Entire course content can be found below:  COURSE CONTENT

***********************************
Note: If anyone need help in designing framework or virtual support for Automation work then reach out to me @sidharth.shukla19@gmail.com/9619094122
***********************************



*************************************************

SeleniumWebdriver Automation Testing Interview Questions:

API Testing Interview Question Set:
https://automationreinvented.blogspot.com/search/label/Rest-API

 
Kubernetes Interview Question Set
https://automationreinvented.blogspot.com/search/label/Kubernetes

 
Docker Interview Question Set
https://automationreinvented.blogspot.com/2020/02/top-18-docker-commands-for-aytomation.html

 
Linux Interview question Set
https://automationreinvented.blogspot.com/search/label/Linux

 
Automation Testing/SDET Framework Design
https://automationreinvented.blogspot.com/search/label/FrameworkDesign


Java Related Interview Question Set

https://automationreinvented.blogspot.com/search/label/Java


GIT Interview Question Set:
https://automationreinvented.blogspot.com/search/label/GIT


Coding Interview Question Set:
https://automationreinvented.blogspot.com/search/label/Coding%20Questions
Mobile Testing Interview Question Set:
https://automationreinvented.blogspot.com/search/label/Mobile%20Testing

Python Interview Question Set for QAE - SDET - SDE:
https://automationreinvented.blogspot.com/search/label/Python


Tuesday, 5 May 2020

Rest API Post method automation in java with rest Assured ? API automation Interview Question-SDET

       

  











Automate a POST method with REST ASSURED  in 3 different ways

Input Request Body for POST method:
Input format:
=====
{
"FirstName" : "test",

"LastName" : "user",

"UserName" : "userone",

"Password" : "pass@word"

}
=========
Three ways to pass the request body as json for POST method

1.Pass it directly in a string

Change your json body to escaped string using online converter:
"https://www.freeformatter.com/json-escape.html#ad-output"

        //pass the escaped string in a string variable

             String jsonBody = "{\r\n\"FirstName\" : \"trsrsrstsdfadf\",\r\n\r\n\"LastName\" : \"sfsgfsgfs\",\r\n\r\n\"UserName\" : \"hgshgshgs\",\r\n\r\n\"Password\" : \"ytytytytyttyty\"\r\n\r\n}";

            Response resp = given().header("Content-Type", "application/json")
                    .body(jsonBody)
                    .when().post("URL");
       
//validate the status code of the response
                assertEquals(resp.getStatusCode(),200);

2.Create jsonobject


pass all the parameter in put method for the object created class JsonObject

//create a object for class jsonobject and add all the json key value into hashmap with put method

JSONObject requestParams = new JSONObject();
            requestParams.put("key1", "trsrsrstsdfadf");
            requestParams.put("key2", "sfsgfsgfs");
            requestParams.put("key3", "hgshgshgs");
            requestParams.put("key4", "ytytytytyttyty");

           //pass the object as input after converting it to string
         
            Response resp = given().header("Content-Type","application/json").
                        body(requestParams.toString()). 
                when().
                        post("URL");
       
               //validate status code

                assertEquals(resp.getStatusCode(),200);

3. Create a json file, parse it and send it as request body

Copy paste your request body in a json file and save it with .json extension: for eg: testdataPost.json

//Fetch the json file which contains the request body in json format
//System.getProperty("user.dir")+"\\TestData\\testdataPost.json"==> path where we keep our json with request body

FileInputStream file = new FileInputStream(new File(System.getProperty("user.dir")+"\\TestData\\testdataPost.json"));

//use IOUtils to convert your input stream into string

            Response resp = given().header("Content-Type", "application/json")
                    .body(IOUtils.toString(file,"UTF-8"))
                    .when().post("pass URL");
               
                assertEquals(resp.getStatusCode(),200);

***********************************
Note: If anyone need help in designing framework or virtual support for Automation work then reach out to me @sidharth.shukla19@gmail.com/9619094122
***********************************
Check below link on top Interview preparation:RestAPI

SQL Query   Cucumber-BDD    Linux Commands    Maven   GIT 

TestNG@after@before
 

*************************************************

API Testing Interview Question Set:
https://automationreinvented.blogspot.com/search/label/Rest-API

 
Kubernetes Interview Question Set
https://automationreinvented.blogspot.com/search/label/Kubernetes

 
Docker Interview Question Set
https://automationreinvented.blogspot.com/2020/02/top-18-docker-commands-for-aytomation.html

 
Linux Interview question Set
https://automationreinvented.blogspot.com/search/label/Linux

 
Automation Testing/SDET Framework Design
https://automationreinvented.blogspot.com/search/label/FrameworkDesign


Java Related Interview Question Set

https://automationreinvented.blogspot.com/search/label/Java


GIT Interview Question Set:
https://automationreinvented.blogspot.com/search/label/GIT


Coding Interview Question Set:
https://automationreinvented.blogspot.com/search/label/Coding%20Questions



All Time Popular Posts

Most Featured Post

𝗦𝘁𝗶𝗹𝗹 𝘀𝘁𝗿𝘂𝗴𝗴𝗹𝗶𝗻𝗴 𝘄𝗶𝘁𝗵 𝗝𝗮𝘃𝗮 𝗰𝗼𝗱𝗶𝗻𝗴 𝗿𝗼𝘂𝗻𝗱𝘀?

❓ 𝗦𝘁𝗶𝗹𝗹 𝘀𝘁𝗿𝘂𝗴𝗴𝗹𝗶𝗻𝗴 𝘄𝗶𝘁𝗵 𝗝𝗮𝘃𝗮 𝗰𝗼𝗱𝗶𝗻𝗴 𝗿𝗼𝘂𝗻𝗱𝘀? The issue isn’t your logic—it’s the lack of pattern recogniti...