Summary of Web services and API testing using UFT

Summary of Web services and API testing using UFT

 

Web services

 
Demand of Web services is already high in the new internet era since applications are built in different technology / databases and connected through internet. So communication between is only possible through a commonly accepted media which are Web services
 
Web services are XML format based services which use media as HTTP to communicate and it is loosely coupled where there no hard binding with client.
 

WSDL

 
WSDL is a document in XML format which describes a web service and defines which transactions are available and data should be structured to send to those transactions.

WSDL (Web services description language) helps client to initiate the correct web service

Webserver client needs WSDL to initiate Web services and Web server providers generates WSDL.
 

UDDI

UDDI is the online directory which has all the WDSL available and all web services client gets that from UDDI.

Web services has two implementations.
1. SOAP

2. REST

SOAP

 
SOAP is the XML based implementation for web service and it has 3 main components which are
a. Envelope – represents root elements
b. Header – stores authentication, routing id for web service transaction.
c. Body – stores all data which are intended to transfer to webservice client.

SOAP uses HTTP as media for transferring data. Format used in XML.

REST

 
REST is more flexible implementation as it uses text format and media other than HTTP as well.
 

API testing using UFT

 
UFT is a software automation tool. Apart from automation test scenarios it supports API testing. Following AP testing are supported.
 

Web service

REST

 
In UFT user can create a new API project by clicking File > New > Test..
Select the  API Test type
Then navigate to tool box in the left
Click on Network once it’s exploded,
Drag HTTP Request to Test flow
Right click and select the properties
Fill the URL, select HTTP method as GET
Also you can configure the checkpoints.

Maven TestNG framework with reporting features and switching pages

Maven TestNG framework with reporting features and switching pages

 

1.  Setup a Maven project in Eclipse with POM file as below

Refer the Post-Man plugin highlighted below in yellow

Refer the reporting directory path highlighted below in yellow

 

POM file sample as below – you can copy paste this contents for any Maven TestNG project.

 

<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>MavenProject</groupId>

  <artifactId>MavenProject1</artifactId>

  <version>0.0.1-SNAPSHOT</version>

  <dependencies>

       <dependency>

              <groupId>junit</groupId>

              <artifactId>junit</artifactId>

              <version>3.8.1</version>

       </dependency>

       <dependency>

              <groupId>org.testng</groupId>

              <artifactId>testng</artifactId>

              <version>6.8</version>

       </dependency>

         <dependency>

                  <groupId>com.relevantcodes</groupId>

                  <artifactId>extentreports</artifactId>

                  <version>2.41.1</version>

         </dependency>

       <dependency>

              <groupId>org.seleniumhq.selenium</groupId>

              <artifactId>selenium-java</artifactId>

              <version>2.45.0</version>

       </dependency>

 

       <dependency>

              <groupId>net.sourceforge.jexcelapi</groupId>

              <artifactId>jxl</artifactId>

              <version>2.6.12</version>

       </dependency>

       <dependency>

              <groupId>org.apache.poi</groupId>

              <artifactId>poi</artifactId>

              <version>3.17</version>

       </dependency>

  </dependencies>

  <dependencyManagement>

       <dependencies>

              <dependency>

                     <groupId>org.jxl</groupId>

                     <artifactId>jxl</artifactId>

                     <version>2.6</version>

              </dependency>

       </dependencies>

  </dependencyManagement>

 

   <build>

        <plugins>

              <!– Suirefire plugin to run xml files –>

               <plugin>

                     <groupId>org.apache.maven.plugins</groupId>

                     <artifactId>mavensurefireplugin</artifactId>

                     <version>2.18.1</version>

                     <configuration>

                           <suiteXmlFiles>

                                  <!– TestNG suite XML files –>

                                  <suiteXmlFile>testng.xml</suiteXmlFile>

                           </suiteXmlFiles>

                     </configuration>

              </plugin>

       <!– Post-Man plugin –>

              <plugin>

                     <groupId>ch.fortysix</groupId>

                     <artifactId>maven-postman-plugin</artifactId>

                     <executions>

                           <execution>

                          

                           <id>send an email</id>

                           <phase>testEmail</phase>

                           <goals>

                           <goal>send-an-email</goal>

                           </goals>

                           <inherited>true</inherited>

                          

                           <configuration>

                                  <!– From Email address –>

                                  <from>[email protected]</from>

                                 

                                  <!–  Email subject –>

                                  <subject>Test Report</subject>

                                 

                                  <!– Fail the build if the mail doesnt reach –>

                                  <failonerror>true</failonerror>

                                 

                                  <!– host –>

                                  <mailhost>smtp.gmail.com</mailhost>

                                  <!– port of the host –>

                                  <mailport>465</mailport>

                                  <mailssl>true</mailssl>

                                  <mailAltConfig>true</mailAltConfig>

                                 

                                  <!– Email Authentication(USername and Password) –>

                                  <mailuser>[email protected]</mailuser>

                                  <mailpassword>pwd</mailpassword>

                                 

                                  <receivers>

                                         <!– To Email address –>

                                         <receiver>[email protected]</receiver>

                                  </receivers>

                                 

                                  <fileSets>

                                  <fileSet>

                                         <!– Report directory Path –>

                                         <directory>C://Projects//Eclipse//workspace//Mavenproject//Reports</directory>

                                         <includes>

                                                <!– Report file name –>

                                                <include>**/*.html</include>

                                         </includes>

                                         <!—as mentioned above Regular Expression **/*.html to send all the html files reports–>

                                         </fileSet>

                                  </fileSets>                      

                          

                           </configuration>

                           </execution>

                     </executions>

              </plugin>

      

       </plugins>          

  </build>

    

</project>

 

2.      Setup a Page factory package where all the object locators are stored. E.g. code like this below.

 

package ProjectPageFactory;

 

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.FileReader;

import java.util.Iterator;

import java.util.List;

import java.util.NoSuchElementException;

import static org.testng.AssertJUnit.assertEquals;

import java.io.FileInputStream;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.openqa.selenium.ie.InternetExplorerDriver;

import org.openqa.selenium.support.CacheLookup;

import org.openqa.selenium.support.FindBy;

import org.openqa.selenium.support.PageFactory;

import org.openqa.selenium.support.ui.Select;

import org.testng.annotations.BeforeSuite;

import org.testng.annotations.BeforeTest;

import org.testng.annotations.Test;

import org.openqa.selenium.support.ui.WebDriverWait;

import org.testng.annotations.Test;

 

 

public class yourFirstpageofApplication {  // this is were you can build the locators repository.

               

                WebDriver driver;

                               

                @FindBy(linkText=”LocatorHyperlinkTextName”)  // type the Locator Hyperlink Text Name

                @CacheLookup  // use CacheLookup for any non dynamic objects , this will improve exection performance.

                WebElement Hyperlink1;

               

                @FindBy(xpath=”html/body/form/divXXXXXXX/xxxx”)

                // @CacheLookup – do not use CacheLookup for any dynamic objects

                WebElement objectName1;

 

2.   Setup a test script code that communicates to Pageobject repository

 

public class applicationPageName extends initialiseDriver  // refer step 3 for initialiseDriver example.

{

      

       //WebDriver driver;

       yourFirstpageofApplication AppObj;

 

       @Test(priority = 1)

       public void Excel() throws Exception

       {

                    

              AppObj = new yourFirstpageofApplication(driver);

              AppObj.ordinqclick();  // this will navigate to PageObject repository code and do action on application.

 

          Note: Basically both classes (Test scripts and Pageobject repository script) will communicate.

 

3.   Reporting code

 

package TestscriptProject;

 

import java.io.File;

import java.io.FileInputStream;

import java.util.List;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.ie.InternetExplorerDriver;

import org.openqa.selenium.support.ui.Select;

import org.openqa.selenium.WebDriver;

import org.testng.annotations.AfterClass;

import org.testng.annotations.AfterTest;

import org.testng.annotations.BeforeTest;

import org.testng.annotations.Test;

import org.testng.asserts.SoftAssert;

 

import com.relevantcodes.extentreports.ExtentReports;

import com.relevantcodes.extentreports.ExtentTest;

import com.relevantcodes.extentreports.LogStatus;

 

import org.apache.poi.hssf.usermodel.HSSFRow;

import org.apache.poi.hssf.usermodel.HSSFSheet;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;

 

 

import PageFactoryProject.ApplicatonPageScriptClass;  // make sure you import that to this class

 

public class orderInquiryPage extends driverInitialise

{

      

       //WebDriver driver;

       yourFirstpageofApplication AppObj;

                     ExtentReports report;

              ExtentTest logger;

 

       @Test(priority = 1)

       public void Excel() throws Exception

       {

                     report = new ExtentReports(“./Reports/OrderInquiryReport.html”);

                     logger = report.startTest(“csvFile”);

              logger.log(LogStatus.INFO, ” test case started”);

      

             

                     //Pass the test in to report

                     logger.log(LogStatus.PASS,”Test verified Pass for particular functionality”);

                          

                     //End of the test

                     report.endTest(logger);

                                        

                     //clear the data in report

              report.flush();

 

4.   Switching between child window/page and parent window/page

 

To switch to a child window or page

public void childWindowHandle()

{

       childHandle = driver.getWindowHandles().toArray()[y].toString();   // y = 1

       driver.switchTo().window(childHandle);

}

 

To switch to a parent window or page

 

public void parentWindowHandle()

{     

       parentHandle = driver.getWindowHandles().toArray()[x].toString(); // x = 0

       driver.switchTo().window(parentHandle);

}

Cucumber Scenario data table and Scenario Outline data table

4 Dimensional Arrays in Java