Here is the function, useful for extracting strings from xml files:
string ExtractString(string s, string tag)
{
var startTag = "<" + tag + ">";
int startIndex = s.IndexOf(startTag) + startTag.Length;
int endIndex = s.IndexOf("</" + tag + ">", startIndex);
return s.Substring(startIndex, endIndex - startIndex);
}
Example of call:
string initial = "<Create>Text to retrieve</Create>";
textToRetrieve=ExtractString(initial,"Create");
Result:
The value of textToRetrieve will be "Text to retrieve".
Wednesday, July 24, 2013
Tuesday, July 16, 2013
UFT - API Testing save test steps results
In UFT you might need to save the results of a step for further use, or see the results in the generated reports.
Here are some useful options:
1. Write to test Output Properties:
CodeActivity<x>.Output.PropertyName = "string property value";
2. Write to test profile:
CodeActivity<x>.Context.TestProfile.SetVariableValue("variable name","variable value");
3. Write to Output Console:
this.CodeActivity<x>.Context.UserLogger.InfoFormat("some string you want to see");
4. Write to generated Report after Run.
this.CodeActivity<x>.Report("some string you want to see");
Here are some useful options:
1. Write to test Output Properties:
CodeActivity<x>.Output.PropertyName = "string property value";
2. Write to test profile:
CodeActivity<x>.Context.TestProfile.SetVariableValue("variable name","variable value");
3. Write to Output Console:
this.CodeActivity<x>.Context.UserLogger.InfoFormat("some string you want to see");
4. Write to generated Report after Run.
this.CodeActivity<x>.Report("some string you want to see");
Thursday, July 11, 2013
C# - Get Computer Name
string hostName = Environment.MachineName;
string name = System.Net.Dns.GetHostName();
string name1 = System.Windows.Forms.SystemInformation.ComputerName;
string name2 = System.Environment.GetEnvironmentVariable("COMPUTERNAME");
Wednesday, July 10, 2013
UFT - Return formated Date
I needed to get current date in this specific format: 2013-07-10T10:03:45.285+03:00
then, make it available for future activities, so here is what I did:
1. Created a Custom Code activity "GetTodayDate".
2. Added a Result Output Property.
Name: Result
Type: String
3. Go to Events Tab -> Create a default handler... for ExecuteEvent
public void CodeActivity22_OnExecuteEvent(object sender, STActivityBaseEventArgs args)
{
string date = XmlConvert.ToString(DateTime.Now,XmlDateTimeSerializationMode.Local);
CodeActivity22.Output.Result = date;
}
5. Result:
6. Now I can link the Result and use it in future activities.
Friday, July 5, 2013
UFT - Postgres on Windows via ODBC
For API testing in UFT (HP Unified Functional Testing) you might need to connect to a Postgres database.
1. For this you need to get an ODBC driver for Postgres:
http://www.postgresql.org/ftp/odbc/versions/msi/
2. Install it.
3. Go to %systemdrive%\Windows\SysWoW64 and add the Driver.
4. In UFT go to Data pane -> New Data Source -> Database and add database info.
1. For this you need to get an ODBC driver for Postgres:
http://www.postgresql.org/ftp/odbc/versions/msi/
2. Install it.
3. Go to %systemdrive%\Windows\SysWoW64 and add the Driver.
4. In UFT go to Data pane -> New Data Source -> Database and add database info.
Subscribe to:
Posts (Atom)