• Slider Banner

    Prepare for

    Technical Interview

    Over .1 Million+ Interview Questions for different profiles

    Read More
  • Slider Banner

    Join the

    Programming World

    Learn about top programming languages, tools and frameworks.

    Read More
  • Slider Banner

    Prepare with

    Certification MCQ

    Practice for certification from 1000+ multiple choice questions.

    Read More

What is the purpose of static methods and variables?

The methods or variables defined as static are shared among all the objects of the class. The static is the part of the class and not of the object. The static variables are stored in the class area, and we do not need to create the object to access such variables. Therefore, static is used in the case, where we need to define variables or methods which are common to all the objects of the class.

For example, In the class simulating the collection of the students in a college, the name of the college is the common attribute to all the students. Therefore, the college name will be defined as static.

How to do JSON Schema Validation using Rest Assured?

Use below steps for JSON schema validation using Rest Assured

Step 1: Copy Latest Maven dependency from below link

https://mvnrepository.com/artifact/io.rest-assured/json-schema-validator

Step 2: Get JSON Schema from developer or generate using some tool (Click Here for online Tool) from your api. Use below sample for test (save it with Sample.json):

{
  "$schema": "http://json-schema.org/draft-04/schema",
  "type": "array",
  "items": [
    {
      "type": "object",
      "properties": {
        "postId": {
          "type": "integer"
        },
        "id": {
          "type": "integer"
        },
        "name": {
          "type": "string"
        },
        "email": {
          "type": "string"
        },
        "body": {
          "type": "string"
        }
      },
      "required": [
        "postId",
        "id",
        "name",
        "email",
        "body"
      ]
    },
    {
      "type": "object",
      "properties": {
        "postId": {
          "type": "integer"
        },
        "id": {
          "type": "integer"
        },
        "name": {
          "type": "string"
        },
        "email": {
          "type": "string"
        },
        "body": {
          "type": "string"
        }
      },
      "required": [
        "postId",
        "id",
        "name",
        "email",
        "body"
      ]
    },
    {
      "type": "object",
      "properties": {
        "postId": {
          "type": "integer"
        },
        "id": {
          "type": "integer"
        },
        "name": {
          "type": "string"
        },
        "email": {
          "type": "string"
        },
        "body": {
          "type": "string"
        }
      },
      "required": [
        "postId",
        "id",
        "name",
        "email",
        "body"
      ]
    },
    {
      "type": "object",
      "properties": {
        "postId": {
          "type": "integer"
        },
        "id": {
          "type": "integer"
        },
        "name": {
          "type": "string"
        },
        "email": {
          "type": "string"
        },
        "body": {
          "type": "string"
        }
      },
      "required": [
        "postId",
        "id",
        "name",
        "email",
        "body"
      ]
    },
    {
      "type": "object",
      "properties": {
        "postId": {
          "type": "integer"
        },
        "id": {
          "type": "integer"
        },
        "name": {
          "type": "string"
        },
        "email": {
          "type": "string"
        },
        "body": {
          "type": "string"
        }
      },
      "required": [
        "postId",
        "id",
        "name",
        "email",
        "body"
      ]
    }
  ]
}

Step 3: Create Sample.java file and paste below code

import org.testng.annotations.Test;
import static io.restassured.module.jsv.JsonSchemaValidator.matchesJsonSchemaInClasspath;

import io.restassured.RestAssured;

public class Sample
{
	@Test
	
	public void testJsonSchema()
	{
		RestAssured.given()
			.when()
			.get("https://jsonplaceholder.typicode.com/comments?postId=1")
			.then()
			.assertThat()
			.body(matchesJsonSchemaInClasspath("com/mycompany/api/bl/Sample.json"));
	}
}

Here in get you have to specify your request and in body you have to specify path where your json schema file is.

What is the group index in XPath?

The group index is nothing but writing the XPath as a sequence. For example, XPath provides numbers from 1,2,3... for the element under every parent.

When we use an index, we might get end up having multiple elements when we wanted a particular element.

In such cases, the Group index will be more helpful to the user. Now the Group index numbers the element from 1..., even though element under the different parent.

The index numbers will never be repeated.

How to Select a Checkbox using Protractor?

We need to follow a few steps to make sure that the element is selected or not, Normally when we have this kind of scenario, what we do is, we will use click() method to select the checkbox. After this, we might move on to the next step of the scenario.

Sometimes not selecting will help you; you got to make sure that the checkbox is selected. To verify it we need to use the isSelected() method and get check whether it is really selected.

Subscribe to