This could be one of the most boring posts that I’ve ever done, or you might love it. It might be exactly what you’ve been looking for. It could be what you are looking for if you have done a lot of regression testing using OATs. Have not? Oh well.
I’ve been helping the team record 80 business scenarios in OATS for automated regression testing. This is a cool service that will test tools releases and ESU’s and give the business a level of confidence that the changes are working without involving the business. This is going to be more important with the proliferation of SaaS, but let’s deal with that in another post.
I have a team of people recording the scripts and using OATS. They’ve done a great job, but as teams are – they are using databanks (sometimes up to 4) and are using the same data banks in multiple scripts. Also, they are expecting that the current record (for the current iteration) is passed between the scripts. Oh dear, I need to invent some magic that can make this happen.
Actually this is a large gap I see with the automated regression in OATS, I want to be able to save off the “latest” number or unique identifier or what-ever… I want to save off the last PO # I created and read it back next time the script runs.
So, I’ve put together a couple of simple scripts (functions) that will write and read values to a properties file. Therefore, I can save off the current pointers to data bank iteration values, or I can save any script related data for next time, nice.
public int OATSWriteEntry(String KeyToWrite, String ValueToWrite )
{
Properties prop = new Properties();
OutputStream output = null;
try {
//load the poperties file first
FileInputStream in = new FileInputStream("\\\\vlneoats\\OatsTests\\GenericCounters.properties") ;
prop.load(in);
in.close();
// set the properties value
int i;
output = new FileOutputStream("\\\\vlneoats\\OatsTests\\GenericCounters.properties");
prop.setProperty(KeyToWrite, ValueToWrite);
// save properties to project root folder
prop.store(output, null);
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (output != null) {
try {
output.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return 0;
}
and Read\
public String OATSReadEntry(String KeyToRead) throws Exception
{
Properties prop = new Properties();
InputStream input = null;
try {
input = new FileInputStream("\\\\vlneoats\\OatsTests\\GenericCounters.properties");
// load a properties file
prop.load(input);
// get the property value and print it out
return prop.getProperty(KeyToRead);
} catch (IOException io) {
io.printStackTrace();
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return "ERROR";
}
I created these in a separate project and called this from all my scripts.
I called it with code like the following, when I wanted to iterate the script counter:
String szTempValue="";
szTempValue = getScript("ShannonScratch").callFunction("OATSReadEntry", "0501Equipment_Counter").toString();
getVariables().set("CurrentScriptCounter", szTempValue, Variables.Scope.GLOBAL);
getVariables().set("OriginalScriptCounter", szTempValue, Variables.Scope.GLOBAL);
info("Have read value {{CurrentScriptCounter}} as iteration point");
getDatabank("0501VCAMCreatinganEquipmentMasterRecord").getRecord(Integer.parseInt(getVariables().get("CurrentScriptCounter")));
//getDatabank("0501VCAMCreatinganEquipmentMasterRecord").getRecord(13);
/*
* incrementing counter
*/
int tempCounter=Integer.parseInt(szTempValue);
tempCounter++;
getScript("ShannonScratch").callFunction("OATSWriteEntry", "0501Equipment_Counter", Integer.toString(tempCounter));
getVariables().set("CurrentScriptCounter", Integer.toString(tempCounter), Variables.Scope.GLOBAL);
info("Setting current iteration to {{ScurrentScriptCounter}}");
//original script
getDatabank("LoginCredentials").getRecord(2);
getVariables().set("Todays Date", "{{@today(dd/MM/yyyy)}}",
Variables.Scope.GLOBAL);
Apologies for my dodgy java code, this is based upon desperation, not skill (as you can tell).
The above is reading an entry from the properties file (0501Equipment_Counter), increments it and then writes the new value back for next time. Nice that you see my library is “ShannonScratch”.
My properties file looks like this:
#Sun Dec 11 12:36:06 EST 2016
0501Equipment_Counter=27
APCustomer_Counter=24
CustomerAddressNumberCreation_Counter=24
0701_Counter=26
APSupplier_Counter=24
0502_Counter=26
ARReceiptNumber_Counter=24
PO1CreateaNonStockPurchaseOrder_Counter=34
CustomerInvoiceNumber_Counter=24
0506MeterReadings_Counter=17
0503_Counter=25
So now I can schedule my OATS scripts using OTM, and they remember where they are up to.
No comments:
Post a Comment