Thursday, February 28, 2013

VB & QTP : Fetching Data from DB and putting it into a 2D array

Fetching Data from DB and putting it into a 2D array






Public Function Func_GetQueryResult(sQuery)

Dim con,rs ,loopCounter,var,counter
counter=0
Dim resArr()

Set con=CreateObject("ADODB.Connection")
Set rs=CreateObject("ADODB.recordset")

con.open"provider=SQLOLEDB;Server=servername;Databae=dbname;Userid= ;Password= :"
rs.open sQuery,con

While not rs.EOF 'Count no of rows in your result
 loopCounter=loopCounter+1
 rs.MoveNext
Wend

If loopCounter = 0 Then
 Reporter.ReportEvent micWarning,"Empty Result Set","Query is: " & sQuery
 Func_GetQueryResult=False
 Exit Function
End If

rs.MoveFirst 'move the recordset object to first row again

ReDim resArr(loopCounter,rs.fields.count-1)

Do until rs.EOF 'Rows
  For var=0 to rs.fields.count-1 'cols
    If counter=0 Then
     resArr(counter,var) =rs.fields(var).name
     else
     resArr(counter,var) =rs.fields(var).value
    end if
  Next
 rs.MoveNext
 counter=counter+1
Loop

rs.Close
con.Close

Func_GetQueryResult=resArr

End Function



'////Connection string can also be -"DRIVER=SQL Server; DATABASE=" & DBName & ";APP=QuickTest Professional;SERVER=" & DBServer &";Description=Testconnection"

VBS :Ubound

Ubound


ubound method is used to count the length of array. It returns the highest index number of the array.
But remember, the actual size of the array is highest index number plus one!! 

Eg : Dim myArray(4)
       msgbox ubound(myArray)   '4
       msgbox "size="&ubound(myArray)+1      'size=5


Eg: Dim myArray(4,6)
msgbox ubound(myArray, 1) ' highest index of the first dimension - 4
msgbox ubound(myArray, 2) ' highest index of the second dimension - 6

Wednesday, February 27, 2013

QTP :Schema of Framework by Actions

Schema of Framework by Operations performed by various Actions


1. Action 0
  •    excel open     //Action of test case given by QC
2. Calling_action
  •  Clean up 
  • Open Fresh app
  • Timer 

3. Start_execution
  • Create Time stamp folder
  • Create a duplicate Test_Data.xls file.
  • (In our case we will have our "local excel open" to be commented )   
  • Create QTP object -to grab the path of the Testcase name from the environment variable  and compare it with the name given as input ,this to avoid multiple excel use when test case has similar name in QC.
  • Traversing to find matching test case name in excel with that of env varible or check whether "execute " is YES.
  •  Extract the Keyword sheet.
  • Goto 2nd Sheet get the corresponding data of that keyword
  • Put the data in global sheet
  • Rest of the Actions are nothing but representation of modules of application.We use Select-Case inside a for loop to go to the particular action where actual execution takesplace. 
 Example:
Keyword_A---TestCase1
Keyword_B---TestCase2
Keyword_C---TestCase3
Keyword_D---TestCase4

For i=1 to end_of_excelsheet

if testcasename_Excel =Testcase_from_environment variable OR "yes" then
Grab_keyword=Corresponding_keyword_from_excel;
end if

Grab_Data=Corresponding_data of Grab_keyword in sheet2 of inputsheet;
global_sheet=grab_data;

Select Case grab_keyword
Case Keyword_A ,Keyword_C
goto action"gui_db";

Case Keyword_B ,Keyword_D
goto action"Some othe action";
end select
Next

---------------------------Action gui_db---------------------------
Option explicit
variables here

Select Case grab_keyword
Case Keyword_A
do these ;
reporter
set obj=nothing;
return pass or fail status to start execution
exitAction;

Case Keyword_C
do these;
reporter
set obj=nothing;
return pass or fail status to start execution
exitAction;
End select
--------------------------------------------------------------------------
To update status of the test case executed into the excel sheet.




QTP : Adding Recovery Scenario

Recovery Scenario

 [http://www.qualitycenterstepbystep.com/2012/dcefining-a-recovery-scenario/]

To associate a Recovery Scenario to a test:
  1. Select File ==> Settings. The Setting Dialog opens.
  2. Select the Recovery node on the left.
  3. Click the “+” sign in the scenario frame at the top right. The ADD RECOVERY SCENARIO dialog opens.
  4. Browse to the location of the .qrs file.
  5. Click the Add Scenario button. The ADD RECOVERY SCENARIO dialog closes.
  6. Click the OK button in. The TEST SETTINGS dialog closes.

QTP :Associating a Function Library

Associating a Function Library

[http://www.qualitycenterstepbystep.com/2012/associating-a-function-library-with-qtp-test/]

After creating the function library, it can be saved as a .txt file. The next step is to associate that file and procedure it contains to the test. This is done in the Test Setting.
 To associate a Function Library to a test:
  1. Select File ==> Settings. The Setting Dialog opens.
  2. Select the Resource node on the left.
  3. Click the “+” sign in the Associated Function Libraries at the top right. The ASSOCIATE FUNCTION LIBRARY dialog opens.
  4. Browse to the location of the Function Library file.
  5. Click the Open button. The ASSOCIATE FUNCTION LIBRARY dialog closes.
  6. Click the OK button in. The TEST SETTINGS dialog closes.

QTP :Reusable Actions in a QTP Test

Reusable Actions in a QTP Test


Actions that are market as reusable in QTP may be called by multiple tests

Viewing a Reusable Action

Select Edit > Action > Action Properties…

alternatively you can do right click on the Login Action to open Action Properties window.

In Action Properties windows check Reusable Action in the button left corner.


QTP :Global and Local Sheet

Global and Local Sheet

Defining the QTP Data Table – Global

The Global Data Sheet can be used to supply or store data used by the entire test, regardless of the action. By default, the global sheet will iterate the entire test once for each row. The number of iterations id defined in the Test Settings.

Defining the QTP Data Table – Local

A Local data sheet exists for each action in a test. The tab name of the local data sheet is the same name as the action name. By default, the local data table iterates once. This is defined in the Action Call Properties

QC :Connecting QTP to Quality Center

Connecting QTP with QC 


Note :QC plugin should be installed to QTP corresponding to the version.
Similarly for QC ,QTP addin should be installed .Which can be found in the help button at the extreme right side inside QC.

When you are connected from QC from QTP, there are several advantages:

1. You can utilize the QCUtil object in your test and function libraries. This provides you with full functionality of the OTA.
2. Check whether integration between QC and QTP is working.

Connecting QTP to QC – Server URL

To connect QTP to QC:
1. Select File –> Quality Center Connection…

A Quality Center Connection – Server Connection Dialog box opens.

2. Enter the QC Server URL in the Server URL field.
3. Check the Reconnect To Server On StartUp checkbox to connect QTP to QC each time

4. Click the Connect Button. The QC Connection Dialog opens.

Connecting QTP to QC – Authentication


5. Enter your QC User Name and password in Step2: Authenticate User Information section.
6. Click the AUTHENTICATE button.
7. Check the Authenticate on StartUp checkbox, if available, to automatically authenticate to QC Server when you invoke QTP.

Connecting QTP to QC – project


8. Select the desired Domain and Project in Step 3: Login to Project section.
9. Click the Login button.
10. Check the Login to Project on StartUp checkbox, if available, to automatically log into the selected project when you invoke QTP.
11. Click the Close button. The QC Connection dialog closes.
Note: Verify that you are connected to QC by viewing the QTP status bar. A QC icon will appear. Hoover over the icon to display the tooltip, which displays the server and the project to which QTP is connected.


QC : Running QTP Automated test cases inside QC

Running QTP Test Cases in QC














The Test Lab module in QC enables you to control the execution of the tests.

1. Select the Test Lab tab in QC
2. Right click on the folder tree and Create New Test set
2. Click on "Select Test" button
3. On the left hand side list of test scripts appear
4. Drag and drop each of the test script of each scenario into the test set
5. Select all of them from the test set
6. Click on Run button
7. Another dialog box opens, Click on "Run All" button in that dialog box

QC : Converting manual Test Case into QTP test Case

Converting manual Test Case into QTP test Case



Note : QC -QTP addin should have been installed in QC .If you have not installed then go to QC>Help>Addins and Select the version of QTP you are working on .




1. In the test plan tree, select the manual test that you want to automate.
2. Click the Design Steps tab > click the Generate Script button.

3. Choose an automated test type to : QUICKTEST_TEST  . Now the manual test case is converted into QTP test .

4. Click on tab Test Script, any text that appeared in the steps of the manual test is listed as comments in the generated test script. (If the manual test has parameters, they are also listed as comment text)

5. Launch QTP tool by clicking QTP icon, it will launch QTP and open current test script in expert view.
6. Write and save test script, changes would be saved in QC in Test Plan module.

Or we can export test Script from QTP to QC. For that you need to first establish QTP-QC connection

1. In QTP, Open the File you want to save > Quality Center Connection (QC connection setup should be installed ,the QC connection  setup can be found in QTP setup folder ).
2. Enter QC URL project name/domain/username/password and click on Login. QTP is now connected to QC.


3. Next you can select the save the QTP Script in QC.
4. In QTP, Select File Menu > Save As > Save in QC
5. Select the Folder in QC where you want to save the QTP Script
6. Click OK to Save.

Selenium : TestNG vs Junit


                                                    TestNG vs Junit



Test NG
JUNIT
Easy to Configure
Complex
Parameterization is Simple
Complex
Reporting is simple and Crisp
Not very presentable
Assersion needs Listeners
Assersion needs a) try-catch
b)ErrorCollector


Example :

Public Class Class_name
{
@Rule
public ErrorCollector errCollector =new ErrorCollector();
@test
p v T1test()
{
try
{
Assert.assertEquals(10,20);
}Catch (Throwable t)
{
s . o .println(“error”);
errcollector.addError(t);
}
}



Selenium : TestNG XSLT Report .

TestNG XSLT Report

 Refer the link below to generate better looking reports from TestNG

http://qtpselenium.com/selenium-tutorial/testng-selenium-training-part-3/

Selenium : Batch Execution in TestNG

Batch Execution in TestNG

I will be discussing on a Simple partial framework in using Eclipse Helios.

Pre-Requistes:
  1. You should have Eclipse Helios.
  2. TestNg plug-in should be installed to Eclipse.

Step 1. Framework skeleton

  1. Create a project with any name inside eclipse.
  2. Inside that project create a package by name "package_name" .
  3. Inside "package_name" create 3 Java files (Class Files) of the following names :- a) Initial  b) Sample  c) Sample2

Step 2 .Create "testng.xml"

Here is a code that you use :- 

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="Can Be any name" verbose="1" parallel="false" >

<test name="Test name is Some Name">
<classes>
<class name="package_name.Initial" />
</classes>
</test>


<test name="Test name is Some Other Name">
<classes>
<class name="package_name.Sample" />
</classes>
</test>


<test name="Test name is Another Name">
<classes>
<class name="package_name.Sample2" />
</classes>
</test>

</suite>

  1.  Paste this code in text file.
  2. Save as "testng.xml".
  3. Drag and Drop this file in the project you created in Eclipse.

 

Step 3   Code in a) Initial  b) Sample  c) Sample2

Copy paste the following codes in each of the files .

----------------------------Initial.Jar ----------------------------------------
package package_name;

import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;

public class Initial
{

@BeforeSuite//Can only be used 1 Time in the Suite ,executes the very first
public void Initialization()
{
System.out.println("-----------@BEFORESUITE---------------\n");
}

@AfterSuite//Can only be used 1 Time in the Suite ,executes the very end
public void Destroy()
{
}
}


---------------------------------------Sample.jar---------------------------------------------------
package package_name;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class Sample
{
@BeforeTest //BEFORE TEST
public void SampleBeforeTest()//Executed only 1 at the beginning of the file
{
System.out.println(" BeforeTest--Sample ");
}
@BeforeMethod //BEFORE METHOD
public void SampleBeforeMethod()//, Executed each time before test
{
System.out.println("BeforeMethod--Sample ");
}

@Test (dataProvider = "registerData")//Parameterized data
public void SampleTest1A(String Some_Data)
{
System.out.println(Some_Data);

}
@DataProvider //Parameterization
public Object[][] registerData()
{
Object[][] Data=new Object[2][1];// execute 2 times , 1 data each time
//Rows = No of times test should be repeated
//Columns = No of data
Data[0][0]="SampleTest1A--Sample , Parameterized !!";
Data[1][0]="SampleTest1B--Sample , Parameterized !!";
return Data;
}

@AfterTest //AFTER TEST
public void SampleAfterTest()//Executed only once in this file after this file is completed
{
System.out.println(" AfterTest--Sample \n");

}
@AfterMethod //AFTER METHOD
public void SampleAfterMethod()//, Executed each time after every test is executed
{
System.out.println("AfterMethod--Sample \n");
}
}

---------------------------------------------Sample2.jar--------------------------------------------

package package_name;
import org.testng.Assert;
import org.testng.SkipException;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class Sample2
{
@BeforeTest //@BeforeTest runs only 1 time before test
public void SampleBeforeTest2()
{
System.out.println(" BeforeTest--Sample2\n");
//throw new SkipExecution("Skipping test");
}
@BeforeMethod //@BeforeMethod runs each time before @test
public void SampleBeforeMethod2()
{
System.out.println("BeforeMethod--Sample2");
}
@Test // @Test runs only once
public void SampleTest2A()
{
System.out.println("SampleTest2A--Sample2 ");
}
@Test //@Test runs only once
public void SampleTest2B()
{
System.out.println("SampleTest2B--Sample2");
throw new SkipException("Skipping test -- SampleTest2B");
}
@AfterTest //@AfterTest runs only 1 time at the end .
public void SampleAfterTest2()
{
System.out.println(" AfterTest--Sample2\n");
System.out.println(" ---Over of Sample2--- \n");
}
@AfterMethod //@AfterMethod runs each time After @test
public void SampleAfterMethod2()
{
System.out.println("AfterMethod--Sample2 \n");
}
}


Step 4 Run the Skeleton.

  1. Right click on the testng.xml file and  Runas>TestNG test.
  2. Press f5 (Refresh) or Right click on Package Explorer>Refresh
  3. You should be able to see "test-output" folder
  4. " test-output>index.html " gives result in html format.