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

How to use err object to continue test execution in VBSript and QTP


''Err object holds the information for last runtime error that occurred in the test execution


'' In the piece of code, we can add on error resume next to continue with execution . It will not abort the execution but will store the information of the error.


'' Once a new runtime error occur, in that case , the err object stores the information of new error. So handle must be taken to add reporting in test and clearing the error


''Methods for err object are err.raise and err.clear


'' On error Resume next will continue with execution. try to comment the On error resume next , and then see what happens in case on error resume next statement is not provided.


On Error Resume Next 

'' Err.raise <number> will generate err object for err number provided. At runtime as an error is encountered, err object populates the information of error. 

Err.Raise 9err_number= Err.number 

'' Using err.description, we can extract information about the error

err_description= Err.description 

'' In case no error is encountered in the execution , the err. number has number as 0. Therefore we can use If else loop based on value of err.num and report to the QTP Report.

If numerr <> 0 Then 

 ''Reporter.Reportevent ........

msgbox (numerr & " Some error in application")

Else

''Reporter.reportevent ........

End If



'' Once we have validated a piece of code, we should clear the err using err.clear

err.clear

msgbox err.number



''you will see msgbox will display value as 0 now. 



How to create array from string separated by delimiter using vbscript split function


Suppose we have a string with value as : stringA = "nitin>joshi>qa>qtp>automation"

'' We can create an array using split function


Strarray = Split(StringA, ">")
'' we can loop through the array element using:

 intPropSet = Ubound(Strarray)  ''this gives the length or upper bound index of array.

  for i = 0 to intPropSet

      msgbox strarray(i)

  Next


''This can be useful to loop in validating multiple values ''e.g : Validating existence of multiple links with name as nitin or joshi or qtp or automation


''We can combine the values in an array using join statement


If (IsArray(Strarray)) then

   stringB = Join(Strarray, ">")

   msgbox "array with text: " + stringB

Else

   msgbox "not an array"

End If


So while understanding How to create array from string separated by delimiter using vbscript split function, we have now understanding of Join, split, IsArray,Ubound and lbound also


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