Showing posts with label Batch Runner. Show all posts
Showing posts with label Batch Runner. Show all posts

Sunday, March 3, 2013

QTP :Batch Runner / Suite Trigger VBS

Batch Runner / Suite Trigger VBS

Dim qtp_test,url,function_lib,object_repository
qtp_test= "C:\Program Files\Mercury Interactive\QuickTest Professional\Tests\google -description programming"
url="www.google.com"
function_lib="C:\Testing\vbs\REGEX.vbs"
object_repository="C:\Program Files\Mercury Interactive\QuickTest Professional\CodeSamplesPlus\Flight_Samples\SOR.tsr"

'-------------------------------------------------------------
Set qtp=createobject("quicktest.application")

Call addins()
Call global_settings()
set ie=aut()

Set xl=createobject("excel.application")
xl.visible=true
Set wb=xl.workbooks.add
Set ws=wb.worksheets("Sheet1")

For i=1 to 3 step 1
with ws.cells(i,1)
.value=i
.font.colorindex=(i*10)
.font.size=i+5
.font.bold=true
.font.name="Arial"

.interior.colorindex=(i+2)*2
end with
Next
msgbox "excel rows "&ws.usedrange.rows.count
msgbox "excel columns "&ws.usedrange.columns.count

qtp.open qtp_test

Call local_settings()
res= fire_app()
msgbox "testscript results "&res
Call fire_app()
Call db_clean()
Call time_stamp()
Call send_mail()
Call read_mail()
ie.close
'---------------------------------------------------------------------
Function addins()
a=array("web")
qtp.setactiveaddins a
qtp.visible=true
qtp.launch
End Function

Function global_settings()
with qtp.options.run
.runmode="Fast"
.viewresults=false
.imagecapturefortestresults="Never"
.moviecapturefortestresults="Never"
end with
qtp.folders.removeall
qtp.folders.Add"c:\"
End Function

Function aut()
Set ie=createobject("internetexplorer.application")
ie.visible=true
ie.navigate url
Set aut=ie
End Function

Function local_settings()
with qtp.test.settings.run
.iterationmode="oneIteration"
.disablesmartidentification=true
.objectsynctimeout=10000
end with
qtp.test.settings.resources.libraries.removeall
qtp.test.settings.resources.libraries.add function_lib
For i=1 to qtp.test.actions.count
qtp.test.actions.item(i).objectrepositories.removeall
qtp.test.actions.item(i).objectrepositories.add object_repository
Next
End Function

Function fire_app()
qtp.test.run
fire_app=qtp.test.lastrunresults.status
End Function

Function db_clean()
Set db=createobject("adodb.connection")
db.open"actitime"
Set rs=db.execute("select * from at_user")
msgbox "checking db "&rs(0).value
msgbox "checking db "&rs(1).value
rs.movenext
msgbox "checking db "&rs(0).value
End Function


Function time_stamp()
ts=replace(now,":","_")
ts=replace(ts,"/","_")
wb.saveas "C:\"&ts&".xls"
wb.close
xl.quit
End Function

Function send_mail()
Set ol=createobject("outlook.application")
Set mail=ol.createitem(0)
mail.to="j.t@gmail.com"
mail.cc="j.t@gmail.com"
mail.subject="test_autoation"
mail.body="body"
'mail.attachments.add""
mail.Send
ol.quit
End Function


Function read_mail()
Set ol=createobject("outlook.application")
Set ol_ns=ol.getnamespace("Mapi")
set ol_obj=ol_ns=getdefaultfolder(6)
'msgbox ol_obj.items.count
For each item in ol_obj.items
If item.unread Then
a=item.subject
If a= "test_autoation"Then
msgbox "reading email "&"a o k"
End If
End If
Next
ol.quit
End Function

Wednesday, February 27, 2013

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.