Monday, May 19, 2025

DefenceNow

 

Some text after the iframe.

Some text after the iframe.

Some text after the iframe.

Some text after the iframe.

Some text after the iframe.

Some text after the iframe.



Thursday, December 8, 2016

Selenium 3 quickStart

                    UI Automation using Selenium 3


Whats in Selenium 3


  • Java 8 Support
  • With Selenium RC APIs removed . So no backward compatibility .
  • Support for Firefox is via Mozilla’s geckodriver
  • Support for for Safari is provided on macOS (Sierra or later) via Apple’s own safaridriver
  • Support for Edge is provided by Microsoft through their webdriver server
  • Only Internet Explorer 9 and above versions are supported. Earlier versions may work, but are no longer supported



What is GeckoDriver?

Gecko is a web browser engine used in many applications developed by Mozilla Foundation and the Mozilla Corporation, most noticeably the Firefox web browser, its mobile version other than iOS devices, their email client Thunderbird and many other open source software projects. You can get more information about Gecko here – https://en.wikipedia.org/wiki/Gecko_(software)

GeckoDriver is a proxy for using W3C WebDriver-compatible clients to interact with Gecko-based browsers i.e. Mozilla Firefox in this case. This program provides the HTTP API described by the WebDriver protocol to communicate with Gecko browsers. It translates calls into the Marionette automation protocol by acting as a proxy between the local and remote ends.

How things worked before GeckoDriver and Selenium 3.0

If you are new to Selenium and you have started directly with Selenium 3.0, you would not know how Firefox was launched with the previous versions of Selenium (version 2.53 and before). It was a pretty straight forward process where you were not required to use GeckoDriver or any other driver. You just write the code to instantiate the WebDriver and open Firefox. 


What happens when you don’t use GeckoDriver with Selenium 3.0

To try this out, all that you need to do is point your JAR files to the latest version of Selenium 3.0 and then run the same code that is given above. You will now notice that Google.com page would not open in a new Firefox window. Instead you will see an error message like the one shown below –

java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/mozilla/geckodriver. The latest version can be downloaded from https://github.com/mozilla/geckodriver/releases


Selenium 3 quick Start


1) download Geko driver 
https://github.com/mozilla/geckodriver/releases

2) Download Selenium 3 files
http://www.seleniumhq.org/download/

3) Download Chrome Driver 
https://sites.google.com/a/chromium.org/chromedriver/

4)Add Maven Info

Create a maven java project and add the below dependencies in POM.xml


dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.0.1</version>
    </dependency>  


<dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-firefox-driver</artifactId>
        <version>3.0.1</version>
    </dependency> 



 <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>htmlunit-driver</artifactId>
        <version>2.23</version>
    </dependency> 



<dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-server</artifactId>
        <version>3.0.1</version>
    </dependency> 


Other dependency http://repo1.maven.org/maven2/org/seleniumhq/selenium/


<dependency>
  <groupId>org.testng</groupId>
  <artifactId>testng</artifactId>
  <version>6.8</version>
  <scope>test</scope>
</dependency>


More info at http://www.seleniumhq.org/download/maven.jsp

Then you can create a java class & run it 


Java class

package com.sel.three.trial;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.*;

public class MyTest {

String driverPath = "C:\\GE\\Tools\\selenium3\\geckodriver11_1\\";
public WebDriver driver;

@BeforeTest
public void launchBrowser() {
System.out.println("launching firefox browser"); 
System.setProperty("webdriver.gecko.driver", driverPath+"geckodriver.exe");
driver = new FirefoxDriver();
}

@Test
public void openApplication() {
driver.navigate().to("http://www.google.com");
}

@AfterTest
public void closeDriver() {
if(driver!=null) {
driver.close();
}
}
}




Friday, November 20, 2015

Automating webServices using Rest Assured


BASICS

Web services are open standard (XML, SOAP, HTTP etc.) based Web applications that interact with other web applications for the purpose of exchanging data.
Web Services can convert your existing applications into Web-applications
Nowadays most of the web services are either SOAP or REST based. This blog is all about REST based API and how to automate those.
REST : REpresentational State Transfer (REST) is the software architectural style of the World Wide Web. 
To do automation testing of REST based APIs, there are many frameworks but my favorite is REST-assured which offers a bunch of nice features like a DSL(domain-specific language)-like syntax, XPath-Validation, Specification Reuse, easy file uploads. It supports POST, GET, PUT, DELETE, OPTIONS, PATCH and HEAD requests and can be used to validate and verify the response of these requests.
JSON and XML are the two markup languages that can be used in restful web API.


HTTP methods supported by REST are:

  • GET: It requests a resource at the request URL. It should not contain a request body as it will be discarded. May be it can be cached locally or on the server.
  • POST: It submits information to the service for processing; it should typically return the modified or new resource
  • PUT: At the request URL it update the resource
  • DELETE: At the request URL it removes the resource
  • OPTIONS: It indicates which techniques are supported
  • HEAD: About the request URL it returns meta information


 PUT vs POST

“PUT”puts a file or resource at a particular URI and exactly at that URI.  If there is already a file or resource at that URI, PUT changes that file or resource.  If there is no resource or file there, PUT makes one


POST sends data to a particular URI and expects the resource at that URI to deal with the request.  The web server at this point can decide what to do with the data in the context of specified resource

Example : To Test Google Map API

Resource Bundle

URI=https://maps.googleapis.com/maps/api/geocode/json?key1=AIzaSyDM6b6oTEPNknlGAk2tZGas3Hkm-ZVRmJA&address=AdithyaFrondoso

Main Class

 import static com.jayway.restassured.RestAssured.given;  
 import com.jayway.restassured.RestAssured;  
 import com.jayway.restassured.response.Response;  
 public class GoogleMapAPI extends BaseClass{  
  public GoogleMapAPI(String url){  
  RestAssured.baseURI=url;  
 }  
  public Response getAddressResponse(String url)  
  { Response response=given().that().contentType( "application/json").when().get(url);  
  return response; }  
 }  




Test Class
 import static com.jayway.restassured.RestAssured.given;  
 import static org.testng.Assert.*;  
 import java.util.ResourceBundle;  
 import org.testng.annotations.BeforeClass;  
 import org.testng.annotations.Test;  
 import com.google.map.api.util.BaseClass;  
 import com.google.map.api.util.GoogleMapAPI;  
 import com.jayway.restassured.response.Response;  
 public class TestGoogleMapApi extends BaseClass{  
  GoogleMapAPI object;  
  ResourceBundle bundle;  
  String caseId;  
  String app_id;   
  String url;  
  @BeforeClass  
  public void doSetUp()  
  {     
  bundle=ResourceBundle.getBundle("resource");  
   url = bundle.getString("URI");  
  object= new GoogleMapAPI(url) ;   
  }  
  @Test  
  public void testFindresponse()  
  {  
  System.out.println("===============Executing the TCs : Test testFindresponse ======================");  
  System.out.println("===============Executing the Method : testFindresponse ======================");  
  try{  
   Response response=object.getAddressResponse(url+"Patna");   
   System.out.println("The Response is "+response.asString());  
   assertNotNull(response);  
   System.out.println("===============Completed the Method : testFindresponse ======================");  
  }  
  catch(Exception Ex)  
  {  
   Ex.printStackTrace();  
   logger.error("==========================testFindresponse Method Failed==================");  
  }   
  }   
 }  



BASE CLASS
 import org.apache.log4j.Logger;  
 public class BaseClass {  
  protected final Logger logger = Logger.getLogger(this.getClass());  
 }  


Also the pom.xml should contain below dependencies "

 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  
  <modelVersion>4.0.0</modelVersion>  
  <groupId>GoogleMapRestTest</groupId>  
  <artifactId>GoogleMapRestTest</artifactId>  
  <version>0.0.1-SNAPSHOT</version>  
  <name>GoogleMapRestTest</name>  
  <description>GoogleMapRestTest</description>  
  <properties>  
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
  </properties>  
  <dependencies>  
  <dependency>  
   <groupId>com.jayway.restassured</groupId>  
   <artifactId>rest-assured</artifactId>  
   <version>2.4.0</version>  
  </dependency>  
  <dependency>  
   <groupId>log4j</groupId>  
   <artifactId>log4j</artifactId>  
   <version>1.2.17</version>  
  </dependency>  
  <dependency>  
   <groupId>org.testng</groupId>  
   <artifactId>testng</artifactId>  
   <version>6.3.1</version>  
   <scope>test</scope>  
  </dependency>  
  <dependency>  
   <groupId>org.seleniumhq.selenium</groupId>  
   <artifactId>selenium-java</artifactId>  
   <version>2.39.0</version>  
   <scope>compile</scope>  
  </dependency>  
  </dependencies>  
  <build>  
  <testSourceDirectory>src/test/java</testSourceDirectory>  
  <testResources>  
   <testResource>  
   <directory>src/test/resources/properties</directory>  
   <includes>  
    <include>**/*</include>  
   </includes>  
   </testResource>  
  </testResources>  
  <plugins>  
   <plugin>  
   <groupId>org.apache.maven.plugins</groupId>  
   <artifactId>maven-compiler-plugin</artifactId>  
   <version>3.0</version>  
   <configuration>  
    <fork>true</fork>  
    <source>1.7</source>  
    <target>1.7</target>  
   </configuration>  
   </plugin>  
   <plugin>  
   <groupId>org.apache.maven.plugins</groupId>  
   <artifactId>maven-surefire-plugin</artifactId>  
   <version>2.19</version>  
   <configuration>  
    <forkMode>always</forkMode>  
    <testFailureIgnore>true</testFailureIgnore>  
    <suiteXmlFiles>  
    <suiteXmlFile>${suiteName}.xml</suiteXmlFile>  
    </suiteXmlFiles>  
   </configuration>  
   </plugin>  
  </plugins>  
  </build>  
  <profiles>  
  <profile>  
   <id>google_testng</id>  
   <properties>  
   <suiteName>google_testng</suiteName>  
   </properties>  
  </profile>  
  </profiles>  
  <repositories>  
  <repository>  
   <id>sonatype</id>  
   <url>https://oss.sonatype.org/content/repositories/snapshots/</url>  
   <snapshots />  
  </repository>  
  <repository>  
   <id>central</id>  
   <name>Central</name>  
   <url>http://repo.maven.apache.org/maven2</url>  
  </repository>  
  </repositories>  
 </project>  

And a TestNG.xml
=============
 <?xml version="1.0" encoding="UTF-8"?>  
 <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">  
 <suite name="Suite" parallel="none">  
  <test name="Test">  
   <classes>  
    <class name="com.google.map.api.test.TestGoogleMapApi"/>  
   </classes>  
  </test> <!-- Test -->  
 </suite> <!-- Suite -->  
Run As 
======
C:\Users\sjyetki\workspaceMars\GoogleMapRestTest>mvn test -P google_testng