QTP -Testcomplete-Testing-Loadrunner-Selenium-Blog

Soap UI – Groovy Scripting

Posted in SOAP UI_ GROOVY SCRIPTING by Sandy runner on February 22, 2012

//loads the initial tescase requests from external file.

HomeFolderPath=testRunner.testCase.testSuite.project.getPropertyValue(“HomeFolder”)
import java.io.*;
import java.util.*;
props = new java.util.Properties ()
StepName = testRunner.testCase.getTestSteps()

log.info(“StepNames::”+StepName)
log.info(StepName.get(“PostAuto”))

if(StepName.get(“PingAuto”) && StepName.get(“PostAuto”))
{
log.info(“Group Ping Auto Found”)
targetStep = testRunner.testCase.getTestStepByName(“PingAuto”)
file1 = new File(HomeFolderPath+”TestData\\WebServices_TestProperties\\PingAuto.txt”)//filename
fis1 = new FileInputStream (file1)
props.load (fis1)
LCPID=props.getProperty(“Request”)
if (LCPID == null)
{
log.error(“No Request file found.Please check the test properties file”)
}
targetStep.setPropertyValue(“Request”, LCPID)
log.info(“Group Post Auto Found”)
targetStep = testRunner.testCase.getTestStepByName(“PostAuto”)
filee1 = new File(HomeFolderPath+”TestData\\WebServices_TestProperties\\PostAuto.txt”)//filename
fise1 = new FileInputStream (filee1)
props.load (fise1)
LCPIDe=props.getProperty(“Request”)
if (LCPIDe == null)
{
log.error(“No Request file found.Please check the test properties file”)
}
targetStep.setPropertyValue(“Request”, LCPIDe)
}

else if(StepName.get(“PingAuto”))
{
log.info(“Ping Auto Found”)
targetStep = testRunner.testCase.getTestStepByName(“PingAuto”)
file1 = new File(HomeFolderPath+”TestData\\WebServices_TestProperties\\PingAuto.txt”)//filename
fis1 = new FileInputStream (file1)
props.load (fis1)
LCPID=props.getProperty(“Request”)
if (LCPID == null)
{
log.error(“No Request file found.Please check the test properties file”)
}
targetStep.setPropertyValue(“Request”, LCPID)
}
else if (StepName.get(“PostAuto”))
{
log.info(“Post Auto Found”)
targetStep = testRunner.testCase.getTestStepByName(“PostAuto”)
filee1 = new File(HomeFolderPath+”TestData\\WebServices_TestProperties\\PostAuto.txt”)//filename
fise1 = new FileInputStream (filee1)
props.load (fise1)
LCPIDe=props.getProperty(“Request”)
if (LCPIDe == null)
{
log.error(“No Request file found.Please check the test properties file”)
}
targetStep.setPropertyValue(“Request”, LCPIDe)
}
else if (StepName.get(“DirectPostAuto”))
{
log.info(“DirectPost Auto Found”)
targetStep = testRunner.testCase.getTestStepByName(“DirectPostAuto”)
filee1 = new File(HomeFolderPath+”TestData\\WebServices_TestProperties\\DirectPostAuto.txt”)//filename
fise1 = new FileInputStream (filee1)
props.load (fise1)
LCPIDe=props.getProperty(“Request”)
log.info(LCPIDe)
if (LCPIDe == null)
{
log.error(“No Request file found.Please check the test properties file”)
}
targetStep.setPropertyValue(“Request”, LCPIDe)
}
else    {
log.info(“Not Found”)

}

//loads the initial tescase requests from external file.

HomeFolderPath=testRunner.testCase.testSuite.project.getPropertyValue(“HomeFolder”)
import java.io.*;
import java.util.*;
props = new java.util.Properties ()
StepName = testRunner.testCase.getTestSteps()

log.info(“StepNames::”+StepName)
log.info(StepName.get(“PostAuto”))

if(StepName.get(“PingAuto1”) && StepName.get(“PostAuto1”))
{
log.info(“Group Ping Auto Found”)
targetStep = testRunner.testCase.getTestStepByName(“PingAuto1″)
file1 = new File(HomeFolderPath+”TestData\\WebServices_TestProperties\\PingAuto.txt”)//filename
fis1 = new FileInputStream (file1)
props.load (fis1)
LCPID=props.getProperty(“Request”)
if (LCPID == null)
{
log.error(“No Request file found.Please check the test properties file”)
}
targetStep.setPropertyValue(“Request”, LCPID)
log.info(“Group Post Auto Found”)
targetStep = testRunner.testCase.getTestStepByName(“PostAuto1″)
filee1 = new File(HomeFolderPath+”TestData\\WebServices_TestProperties\\PostAuto.txt”)//filename
fise1 = new FileInputStream (filee1)
props.load (fise1)
LCPIDe=props.getProperty(“Request”)
if (LCPIDe == null)
{
log.error(“No Request file found.Please check the test properties file”)
}
targetStep.setPropertyValue(“Request”, LCPIDe)
}

else if(StepName.get(“PingAuto1”))
{
log.info(“Ping Auto Found”)
targetStep = testRunner.testCase.getTestStepByName(“PingAuto1″)
file1 = new File(HomeFolderPath+”TestData\\WebServices_TestProperties\\PingAuto.txt”)//filename
fis1 = new FileInputStream (file1)
props.load (fis1)
LCPID=props.getProperty(“Request”)
if (LCPID == null)
{
log.error(“No Request file found.Please check the test properties file”)
}
targetStep.setPropertyValue(“Request”, LCPID)
}
else if (StepName.get(“PostAuto”))
{
log.info(“Post Auto Found”)
targetStep = testRunner.testCase.getTestStepByName(“PostAuto1″)
filee1 = new File(HomeFolderPath+”TestData\\WebServices_TestProperties\\PostAuto.txt”)//filename
fise1 = new FileInputStream (filee1)
props.load (fise1)
LCPIDe=props.getProperty(“Request”)
if (LCPIDe == null)
{
log.error(“No Request file found.Please check the test properties file”)
}
targetStep.setPropertyValue(“Request”, LCPIDe)
}
else if (StepName.get(“DirectPostAuto”))
{
log.info(“DirectPost Auto Found”)
targetStep = testRunner.testCase.getTestStepByName(“DirectPostAuto”)
filee1 = new File(HomeFolderPath+”TestData\\WebServices_TestProperties\\DirectPostAuto.txt”)//filename
fise1 = new FileInputStream (filee1)
props.load (fise1)
LCPIDe=props.getProperty(“Request”)
log.info(LCPIDe)
if (LCPIDe == null)
{
log.error(“No Request file found.Please check the test properties file”)
}
targetStep.setPropertyValue(“Request”, LCPIDe)
}
else    {
log.info(“Not Found”)

}

targetStep = testRunner.testCase.getTestStepByName(“TestData”)
groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
props = new java.util.Properties ()
file = new File(HomeFolderPath+”TestData\\Auction_Webservices\\A_Make-Model filter.txt”)
fis = new FileInputStream (file )
props.load (fis)
LCPID=props.getProperty(“LCPID_3715”)
LCPID2=props.getProperty(“LCPID2_3715”)

Make1=props.getProperty(“Make1_3715”)
Model1=props.getProperty(“Model1_3715”)
Make2=props.getProperty(“Make2_3715”)
Model2=props.getProperty(“Model2_3715”)
Zipcode1=props.getProperty(“Zipcode1_3715”)
CampaignName=props.getProperty (“CampaignName_3715”)
targetStep.setPropertyValue(“LCPID”, LCPID)
targetStep.setPropertyValue(“LCPID2”, LCPID2)
targetStep.setPropertyValue(“Make1”, Make1)
targetStep.setPropertyValue(“Model1”, Model1)
targetStep.setPropertyValue(“Zipcode1”, Zipcode1)
targetStep.setPropertyValue(“CampaignName”, CampaignName)
//===========================================================================================
//===========================================================================================
holder = groovyUtils.getXmlHolder( “PingAuto#Request” )
holder.namespaces[“req”] = “http://XXXXXXXXXXXXXXXX.Ping.ServiceContracts/2007/10/ServiceContracts
holder.setNodeValue(‘//req:LCPId’,LCPID)
holder.setNodeValue(‘//req:Model’,Model1)
holder.setNodeValue(‘//req:Make’,Make1)
holder.setNodeValue(‘//req:Zipcode’,Zipcode1)

holder.updateProperty()

//log.info(holder.getNodeValue(‘//req:LCPId’))
Postholder = groovyUtils.getXmlHolder( “PostAuto#Request” )
Postholder.namespaces[“req”] = “http://XXXXXXXXX.XXXXXXXXXviceContracts/2007/10/PostMessageTypes
Postholder.setNodeValue(‘//req:LCPId’,LCPID)
Postholder.setNodeValue(‘//req:Model’,Model1)
Postholder.setNodeValue(‘//req:Make’,Make1)
Postholder.setNodeValue(‘//req:Zipcode’,Zipcode1)
Postholder.updateProperty()
//log.info(Postholder.getNodeValue(‘//req:LCPId’))
//===========================================================================================
//===========================================================================================
holder = groovyUtils.getXmlHolder( “PingAuto1#Request” )
holder.namespaces[“req”] = “http://XXXXXXXXXXXXXXServices.Ping.ServiceContracts/2007/10/ServiceContracts
holder.setNodeValue(‘//req:LCPId’,LCPID2)
holder.setNodeValue(‘//req:Model’,Model2)
holder.setNodeValue(‘//req:Make’,Make2)
holder.setNodeValue(‘//req:Zipcode’,Zipcode1)
holder.updateProperty()
log.info(holder.getNodeValue(‘//req:LCPId’))
Postholder = groovyUtils.getXmlHolder( “PostAuto1#Request” )
Postholder.namespaces[“req”] = “http:XXXXXXXXXXXXXXXXXXXXXX.Post.ServiceContracts/2007/10/PostMessageTypes
Postholder.setNodeValue(‘//req:LCPId’,LCPID2)
Postholder.setNodeValue(‘//req:Model’,Model2)
Postholder.setNodeValue(‘//req:Make’,Make2)
Postholder.setNodeValue(‘//req:Zipcode’,Zipcode1)
Postholder.updateProperty()

====================================================

import java.sql.*
import groovy.sql.Sql
import java.util.ArrayList
import java.util.Iterator

groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)

Postholder = groovyUtils.getXmlHolder(“Post Request Choice 2#Response” )
Postholder.namespaces[“resp”] = ‘http://XXXXXXXXXXXXXXXXXXXXXrviceContracts/2007/10/PostMessageTypes‘;
LeadNo2=Postholder.getNodeValue(‘//resp:LeadId’);

targetStep = testRunner.testCase.getTestStepByName(“TestData”)

driver = Class.forName(“com.microsoft.sqlserver.jdbc.SQLServerDriver”).newInstance();
Connection conn = DriverManager.getConnection(“jdbc:sqlserver://sqltest1.replydev.net:1433;”+ “user=XXXXX;password=XXXXX;database=XXXXXX”);
log.info(“First Connection is set”)
DatabaseMetaData meta = conn.getMetaData();
log.info(meta.getDatabaseProductName())
ArrayList<String> al = new ArrayList<String>();
Statement sta = conn.createStatement();

ResultSet res = sta.executeQuery(“select c.CampaignName from Auction a (nolock) join AuctionHistory ah on ah.AuctionID = a.AuctionID join CampaignBid cb on ah.CampaignBidID = cb.CampaignBidid join Campaign c on cb.CampaignID = c.CampaignID where a.LeadID =”+LeadNo2);
while (res.next())
{
name = res.getString(1);
al.add(name)
}
Iterator itr = al.iterator();
String strVal=””;
while(itr.hasNext())
{
strVal+= itr.next().toString()+”,”;
System.out.println(strVal);
}
int lastIndex = strVal.lastIndexOf(“,”);
if(lastIndex == -1)
{
log.error(“Error::No return Value”);
strVal = null;
}
else
{
strVal = strVal.substring(0,lastIndex);
}
log.info(“Final String::”+strVal)
strCampaign=targetStep.getPropertyValue(“CampaignName”)

assert strCampaign.equals(strVal)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: