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

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 



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.