Blog to understand automation concepts in QTP, Selenium Webdriver and Manual Testing concepts

How to Create and execute Runnable JAR file for Java Project from command Prompt/Batch file

In this article, we will discuss steps to create an executable JAR file from a java project. This can be useful for our selenium Project. We are using Eclipse IDE for illustrating the example.


Prerequisite – It is assumed a java project is created.


Steps to create an executable jar file:


 Define the Run Configuration for execution

1.       Navigate to Run>Run Configuration for the Project.

2.       Select Java Application  and click on New launch configuration

3.       Provide the name to configuration and provide the main lass name to run.

4.       You can also define default argument for the execution.

5.       Save the configuration


Creating run configuration
Creating run configuration

 

Export the Project as executable Jar file


1.       Click on Project>Export

2.       Select export destination as Java>Runnable JAR files


Exporting as runnable JAR file
Exporting as runnable JAR file

3.       Select Run Configuration as one defined in step A.


Providing export location and launch configuration
Providing export location and launch configuration

4.       Provide export destination

5.       Click on finish


Run the executable JAR file 


 Through command prompt.


1.       Open command prompt

2.       Navigate to folder in which JAR file is saved.

3.       Run the following command  java -jar driverJAR.jar where driverJAR.jar is the name of JAR file



Double clicking on a batch file 


1.       Create a new text file in the same location as the JAR file.

2.       Rename the file as test.bat, thus creating a batch file.

3.       Add following content in the bat file

@echo "this is for testing the jar file"

java -jar testingJAR.jar

pause


4.       Save the file.

5.       Double click the file, it will run the jar file 



How to use Select Case Statement in VBScript for QTP

What is Select Case Statement in VBScript?

Select Case provides an alternate approach to nested If else loop. In case of multiple condition , it is better idea to read through the code and manage the expected behavior in the specific condition.


Syntax for Select Case Statement is : 


SELECT CASE (operation)

   CASE (expression 1)

      line of Codes

   CASE (expression 2)

      line of Codes

   CASE (expression 3)

      line of Codes

     .............

   CASE (expression n)

      line of Codes

   CASE DEFAULT

      line of Codes

END SELECT


How Select Case Works: 


Let me Explain how select case works. consider the below problem statement to explain this ?

Let us take an example to perform expected action from sum, multiply, subtract, or divide and show the result as output from the function using Select case function

function Perform_arithmetic_Operation(Operation_Name, numA, numB)
Select Case operation_Name
Case "Addition", "Add"
Perform_arithmetic_Operation= numA+numB
Case "Subtraction", "Subtract"
Perform_arithmetic_Operation= numA+numB
msgbox "subtracting numB from numA gives: "& Perform_arithmetic_Operation
Case "Multiply"
Perform_arithmetic_Operation= numA*numB
Case "Divide"
Perform_arithmetic_Operation= numA/numB
case else
Perform_arithmetic_Operation = "Invalid Operation Name"
End Select
End function

This function when called will send the solution as expected based on operation_Name, and value of A and B.

example on calling above function as : 
x = Perform_arithmetic_Operation("Addition", 13, 15)
msgbox x
will show value as 28 in the message box. 

We can also provide multiple value in the expression. In above example ,we have provided multiple expression 
e.g.: Case "Addition", "Add" . therefore the below expression will also add as in above example.

x = Perform_arithmetic_Operation("Add", 13, 15)
msgbox x
will show value as 28 in the message box. 


Manipulating and working with Word document using vbscript in QTP

In this article, we will discuss how to manipulate microsoft word document using QTP and VBScript. Learning working with microsoft word can help the users to generate reports of test results in word document . We will discuss on code for following problems in this article 

a. Creating a new Word document using vbscript in QTP
b. Opening an existing word document
c. Appending at the beginning and end of a word document. 
d. Reading content of a word document.
e. Formatting text of a word document.

We will discuss on capturing images and working with table in MS word using vbscript in some another article: 


Example 1 - Creating a new word document using vbscript. Writing some text in the document and closing the same


' Instantiate an object of word application 
Set objWord = CreateObject("Word.Application")
' Add a new item of word application object
objWord.Documents.Add
' Adding some text in the word document
objWord.Selection.TypeText "testing time"
' Save the document as provided
objWord.ActiveDocument.SaveAs "C:\qtptesting.docx"
' Close instance of word application
objWord.Quit
' Release the object for word document.
Set objWord=Nothing

Example 2 - The above was example of adding a new document in case we wish to update an existing document, we can use the below code:


' Instantiate an object of word application 
Set objWord = CreateObject("Word.Application")
' Open an existing word document
objWord.Documents.open "C:\qtptesting.docx"
' Adding some text in the word document
objWord.Selection.TypeText "testing time 2"
' Save the document as provided
objWord.ActiveDocument.Save
' Close instance of word application
objWord.Quit
'Release the object for word document.
Set objWord=Nothing


Example 3 : Now we have seen the text in above example 2 writes "testing time 2" just before testingtime. Suppose we want to write the text testing 2 in a new line after text testing, we can write the code as



Set objWord = CreateObject("Word.Application")
objWord.Documents.open "C:\qtptesting.docx"

' Adding some text in the word document at the end of document:
objWord.Selection.EndKey 6,0
objWord.Selection.TypeText vbCrLf & "testing time 3"

objWord.ActiveDocument.Save
' Close instance of word application
objWord.Quit
'Release the object for word document.
Set objWord=Nothing

Example 4 : Next we want to format the text in the word document.


Set objWord = CreateObject("Word.Application")
objWord.Documents.open "C:\qtptesting.docx"
' Adding formatting to the object, there will be lot of method to format , can refer to reference vbscript in QTP or word.
objWord.Selection.Font.Size ="18"
objWord.Selection.Font.Name ="18"
objWord.Selection.Font.bold = true
objWord.Selection.EndKey 6,0
' formatting changes in the code completes
objWord.Selection.TypeText vbCrLf & "testing time 3"
objWord.ActiveDocument.Save
' Close instance of word application
objWord.Quit
' Release the object for word document.
Set objWord=Nothing

Example 5: Reading content of a word document and storing in a string


Set objWord = CreateObject("Word.Application")
objWord.Documents.open "C:\qtptesting.docx"
set objdoc = objWord.Activedocument
strWordtext = ""

' read the number of words in the document and loop through the number of characters
iWordCnt= objdoc.Words.count
For i = 1 to iWordCnt
strWordtext = strWordtext + objdoc.Words(i)
Next
msgbox strWordtext
' specific changes in the code completes

objWord.Quit
'Release the object for word document.
Set objWord=Nothing

Similarities and Difference between SOAP and REST

In this article, we will try to understand what SOAP and Rest Services are discussing the similarities and differences in between the two. I have tried to consolidate the basic concept to understand what are SOAP and rest services.

Working for the Same Cause - SOAP and Rest both are used to access Web Services.

What do they stand for?

SOAP - Simple Object Access Protocol
REST - REpresentational State Transfer


What do they mean?

SOAP

  • SOAP is a standards-based Web services access protocol.
  • SOAP relies exclusively on XML to provide messaging services.
  • SOAP was developed by Microsoft.
  • SOAP is a standardized format and has defined various standards for messaging, security, metadata exchange specification and so on.
  • SOAP is highly extensible and also flexible enough to use only those standards which are required for the web services. E.g.: for a web service free to public, it is not required to define the security and authentication for web service.
  • SOAP Based Web Services are defined in WSDL(Web Services Description Language)
  • In case of invalid request, SOAP Response provides details of the error with error code, which helps user to identify the error in the request and correct the same.
  • SOAP client is tightly coupled to the server with rigid contract between client and server, Changes in either of client or server side needs to be communicated to counterparty for web services to work.

REST

  • REST uses URL instead of using XML to make request. Since REST uses URL, REST client is more like a browser.
  • REST uses GET, POST, PUT, and DELETE to perform tasks.
  • We can have the response in required format for e.g. in CSV, JSON, plain text, and XML format while using REST 
  • WADL is the REST equivalent of SOAP's Web Services Description Language (WSDL)
  • REST does not have large number of standards like SOAP.
  • REST is not a protocol but an architectural style.
  • A representation of a resource must be stateless, cacheable.
  • REST requires less bandwidth and resource than SOAP.

SOAP Advantage over REST

  •  REST services inherit security measures from the underlying transport whereas we can define our own security in SOAP. In terms of security, SOAP is assumed to be more safe compared to REST Works well in distributed enterprise environments
  • Is more standardized and has higher extensibility in form of WS* Standard.
  • Allows better error handling in the response from server.


REST Advantage over SOAP

  • REST is protocol independent.
  • While SOAP only supports XML, REST supports different format like text, JSON, XML.
  • REST requires less bandwidth and resource than SOAP.
  • Rest is more lightweight

Building base in WebServices – Questions and Answers

In last few articles, we discussed about the challenges inIntegration testing and have briefed the concept of web services.

In this article, we will explain how web services are used for integration testing. I will break this article in short questions and answers to easily understand the concepts:

  • What is Integration testing? – Validating Integration or connection between multiple components, modules or systems

  • What are the different architecture options available for Integration? – The common architecture options are using SOA, ESB or EAI architecture.

  • What are web services?  - A Web service is a URL-addressable resource returning information in response to client requests. Web services allow data exchange between applications in a platform independent manner. SOA are developed on web services using standard description (WSDL), discovery (UDDI) and messaging (SOAP).

  • How are Web Services useful for Integration testing? - Web Services are services used to have seamless and smooth integration of one software with software over intranet or intranet. Web Services uses SOAP Protocol to communicate between the software which is XML over http protocol.

  • What is WSDL? – Operations in a web services are described in XML format with the Web Service Description Language (WSDL). The WSDL consists of the URL for the web service, the methods in the web services, input parameter types and the return types of the web service methods.

  • What is UDDI?  - Web services can be published and located using the Universal Description, Discovery and Integration (UDDI) based registry of services.

  • What is SOAP? – SOAP stands for Standard Object Access Protocol. SOAP is used as messaging standard for communicating with the web service. Wrapped in a SOAP Envelope, Message can be delivered across network using different protocols.

  • What are top Challenges in testing web services?  - The major challenges in testing web services are:

o   Absence of a user Interface – Testing web services manually is a difficult task due to absence of user interface. To work with and testing web service, tester needs to have knowledge of specific tool .e.g.: Soap UI or jmeter and coding knowledge , e.g.: Groovy script
o   Actual Size of end User(s) for Internet Web Services – Performance testing should be done as early to validate proper response on soap request is received with varying load on web services. This again requires technical as well as tool knowledge and also identifying the expected load on web services is challenging.
o   Another challenge is maintaining different versions of Web Services as the old version of API are consumed. 

  • What are the different testing tools to test web services? Some of the  testing tools to test web services are :

o   Jmeter
o   SOAP UI
o   Examine

Six challenges in Software Integration testing:

Integration testing has been changing over the time with the development of web services and change from integrating large application to smaller sets of application. In this article, we will focus on the major challenges in the system integration testing.

1.     Perception for Integration testing


The perception that Integration testing is testing the integration points between two units or system and verifying if the systems are working properly. This can actually cause issues when the actual user s) uses the application. Integration between different systems should not be oversimplified and should follow by an exhaustive testing considering collection of Systems integrated together as an environment focusing on different sets of inputs and corresponding outputs from other system.

2.     Our Individual systems are perfect, but together teamwork is missing.


Let us consider a banking system. There are multiple layers  Individual systems) for Front Office, middle Office and back office. While delivering the system, there may be possibility for systems developed by different parties. The integration testing should be done in a manner that the integration testing suite should be minimal impacted by change in other third party systems. While Creating individual systems, we should keep in mind, possible integrations with other software systems with which the software will interact, so as to minimize efforts and seamless integration of software with other soft wares

3.     Are we following the standards


 Consider transfer of banking instruction across the globe in the form of Swift messages? Suppose different banks have different messaging format, it would have been very difficult to integrate between different bank and virtually impossible to create an interconnected network between systems. Similar to this, we can follow standards of messages in the form of web services with predefined set of request and response messages. Use of Web Services also helps in integrating systems developed by different teams

4.  Complexity in managing Systems Integration


Test includes factor like Application, Platforms, Environments, data and resource availability for different application.

5.  Most of the legacy systems were isolated system with lot of functionality


Integration of new systems with the legacy system or between two different legacy systems requires a lot of changes in both the systems.

6.   In earlier systems, there was relatively small number of large application as compared to new system which focuses on large number of small applications. 

This results in changing approach for Integration testing with time.