Monday, August 4, 2014

Testing rest api's using Rest-Assured

1. Add the following dependencies in your pom.xml
<dependency>
      <groupId>com.jayway.restassured</groupId>
      <artifactId>rest-assured</artifactId>
      <version>2.3.1</version>
      <scope>test</scope>
</dependency>
<dependency>
      <groupId>com.jayway.restassured</groupId>
      <artifactId>json-path</artifactId>
      <version>2.3.1</version>
</dependency>
<dependency>
      <groupId>com.jayway.restassured</groupId>
      <artifactId>json-schema-validator</artifactId>
      <version>2.3.1</version>
      <scope>test</scope>
</dependency>
2. Set the baseURI in @BeforeMethod
RestAssured.baseURI = "http://yoururl.com"; 
RestAssured.port = 80;
3.  In @Test add the following code to get the response from the api
Response response = get("/api/xxx/xxxx");   
          JsonPath jsonpath = new JsonPath(response.asString());
          String ca_id = jsonpath.getString("id");          // id will get all the values from json response and returns a json string. You could validate whatever you are looking for here.

Happy Testing!!!!

Sunday, August 3, 2014

Chrome driver initialization in Webdriver

Follow to below steps to work with Chrome 

1. Download the chrome driver 2.41.0
        Those who use maven, you could copy paste this dependency in your pom.xml
<dependency><groupId>org.seleniumhq.selenium</groupId><artifactId>selenium-chrome-driver</artifactId><version>2.41.0</version></dependency>
2.    If you work in mac machine, download chromedriver unix executable. If you work in windows machine, download chromedriver.exe
You could get it here
3. Save the chromedriver in your project path.

4. Refer the below code and initialize your chrome driver.
    String path_to_chromedriver_executable = System.getProperty("user.dir")+"/src/test/resources/chromedriver";  //mention the location where you kept your chromedriver unix executable or chromedriver.exe
         
System.setProperty("webdriver.chrome.driver", path_to_chromedriver_executable);
            ChromeOptions options = new ChromeOptions();
            options.addArguments ("--test-type" );
        driver = new ChromeDriver(options);

5. You are ready to launch chrome browser. Happy Testing!!!!!