With below code we can split any data based on separator.
string path="C:\\test\\file\\TestResults";
int a = path.IndexOf("\\TestResults");
string ss = path.Substring(0, a - 1);
MessageBox.Show(ss);
Output Result:- C:\\test\\file
or
we can do split data with below code also
string path="C:\\test\\file\\TestResults";
string[] ss = new string[] { "\\TestResults" };
string[] st1 = path.Split(ss, StringSplitOptions.RemoveEmptyEntries);
MessageBox.Show(""+st1[0]);
Tuesday, November 16, 2010
How to create data driven test using Web Performance test?
Once developed web performance test with CS file, In CS file calling test do below settings for data driven test.
Click on Test Menu
Click on Edit Test Testings and click on Local (local.testsettings) menu item in sub menu items -->
In Test settings window select Web Test and displayed Web Test pane turn on “One run per data source row” radio button
Click on Save As button and click on save button in save as window.
Then script will execute based on how many rows of data is exist in the data source file (CSV).
Click on Test Menu
Click on Edit Test Testings and click on Local (local.testsettings) menu item in sub menu items -->
In Test settings window select Web Test and displayed Web Test pane turn on “One run per data source row” radio button
Click on Save As button and click on save button in save as window.
Then script will execute based on how many rows of data is exist in the data source file (CSV).
How to add the References to projects ?
Each Built in or User defined Name Space contains few methods, if we want to use those methods first have to add reference to References and add using statement to the code before using Name spacing containing methods in the code.
Below one is the reference adding navigation:-
In the solution Under the specified project right click on “References” node
Click on “Add Reference…”
Click on Browse tab in “Add Reference” window
Select required path in look in like C:\Program Files\Reference Assemblies\Microsoft\Framework\.NetFramework\v4.0 and select required DLL and click on “OK” button
Then it displays DLL name under References folder.
In the code under namespace add this DLL name with “using” statement.
Below one is the reference adding navigation:-
In the solution Under the specified project right click on “References” node
Click on “Add Reference…”
Click on Browse tab in “Add Reference” window
Select required path in look in like C:\Program Files\Reference Assemblies\Microsoft\Framework\.NetFramework\v4.0 and select required DLL and click on “OK” button
Then it displays DLL name under References folder.
In the code under namespace add this DLL name with “using” statement.
Monday, November 15, 2010
How to send Fail Message to Results with C sharp code?
Whenever application behavior is not expected, have to fail report to the test result, report same with below code.
throw new Exception(" Fail message to result");
throw new Exception(" Fail message to result");
Data Base Automation with C Sharp code in VSTS 2010 or TFS 2010
SQL Server Data base connection code:-
// Create object for SqlConnection
SqlConnection con=new SqlConnection(@”Network Library=DBMSSOCN;Data Source=XXXX; database=XXXXX;User id=XXXX;Password=XXXX;");
//Connect the SQL Server
con.Open();
// create object for query execution
SqlCommand dbcommand = con.CreateCommand();
dbcommand.CommandText = "Select * from tablename";
//For data reading from query result table create data reader
SqlDataReader dbReader = dbcommand.ExecuteReader();
//get the columns count from query table
int fieldcount = dbReader.FieldCount;
// There is no direct command for record count but with below code find query result table having one or more records.
Boolean result = dbReader.HasRows;
// Close the reader object
dbReader.Close();
//get the DB column Data from reader :-
dbReader[“Field Name”]
// Create object for SqlConnection
SqlConnection con=new SqlConnection(@”Network Library=DBMSSOCN;Data Source=XXXX; database=XXXXX;User id=XXXX;Password=XXXX;");
//Connect the SQL Server
con.Open();
// create object for query execution
SqlCommand dbcommand = con.CreateCommand();
dbcommand.CommandText = "Select * from tablename";
//For data reading from query result table create data reader
SqlDataReader dbReader = dbcommand.ExecuteReader();
//get the columns count from query table
int fieldcount = dbReader.FieldCount;
// There is no direct command for record count but with below code find query result table having one or more records.
Boolean result = dbReader.HasRows;
// Close the reader object
dbReader.Close();
//get the DB column Data from reader :-
dbReader[“Field Name”]
How to capture the Response in Web Performance test with C Sharp Code?
Use the “Extractvalues” method before “Yield return rquest1” statement in the generate .CS file and then define method with object and ExtractionEventArgs orguments like below .
Below statement add before the “Yield return rquest1” statement
Request1.ExtractValues +=new EventHandle (request1_ExtractValues);
Method definication :--
Void request1_ExtractValues(object sender,ExtractionEventArgs e)
{
// with below statement capture the response
var response=e.Response.BodyString;
// save the response with below code
XmlDocument doc=new XmlDocument();
doc.LoadXml( response);
// Get the value from required node
XmlNodeList var1=doc.GetElementsByTagName(“Node Name”)
// Get the nodes count
int NodeCount=var1.Count;
// for value capture code
Nodevalue=Var1[0].InnerText;
Below statement add before the “Yield return rquest1” statement
Request1.ExtractValues +=new EventHandle
Method definication :--
Void request1_ExtractValues(object sender,ExtractionEventArgs e)
{
// with below statement capture the response
var response=e.Response.BodyString;
// save the response with below code
XmlDocument doc=new XmlDocument();
doc.LoadXml( response);
// Get the value from required node
XmlNodeList var1=doc.GetElementsByTagName(“Node Name”)
// Get the nodes count
int NodeCount=var1.Count;
// for value capture code
Nodevalue=Var1[0].InnerText;
Send XML Request to Web service in Web Performance Test
In webservice send request three ways.
1. with variables
2. Array format
3. Xml Foramt
Below code using for send XML Request to web service
1. Load XML schema file to reference with below navigation
a. Right click on Project
b. click on Add
c. Click on New Item
d. in “Add New Item - “ window Select on Resource File and give the name and click on ADD button
e. It adds “Resources” folder and “ Name.resx” file to the Project
f. Click on “ .resx” file and in open window Click on beside “Add Resource” arrow and click on “Add Existing File…” menu
g. Select the required file path in “Add existing file to resources” window and click on “Open”
h. It add to the project and displays under Resources folder
2. In the .CS file code add below code for xml request file
XmlDocument RequestXMLFile=new XmlDocument();
XmlDocument xmlDoc=new XmlDocument();
// get the file from resource folder
String xmlData=resource.xmlfile name;
// Load the xml file
xmlDoc.LoadXml(xmlData);
//Messagebox.Show(xmlDoc.InnerXml);
// below code for xml node names naming space handling purpose
XmlNameTable xnt= xmlDoc.NameTable;
XmlNameSpaceManager nm=new XmlNameSpaceManager(xnt);
Nm.AddNamespace(“var1”,”http;//url”);
// assign the value for xpath
XmlNode nodevar=xmldoc.SelectSingleNode(“/var1:xmlnode1/var1:xmlnode2”,nm);
Nodevar.InnerText=this.Context[“DataSource1.csvfile#csv.columnname”].ToString();
Request1Body.BodyString=xmldoc.InnerXml;
Request1.Body=request1Body;
1. with variables
2. Array format
3. Xml Foramt
Below code using for send XML Request to web service
1. Load XML schema file to reference with below navigation
a. Right click on Project
b. click on Add
c. Click on New Item
d. in “Add New Item - “ window Select on Resource File and give the name and click on ADD button
e. It adds “Resources” folder and “ Name.resx” file to the Project
f. Click on “ .resx” file and in open window Click on beside “Add Resource” arrow and click on “Add Existing File…” menu
g. Select the required file path in “Add existing file to resources” window and click on “Open”
h. It add to the project and displays under Resources folder
2. In the .CS file code add below code for xml request file
XmlDocument RequestXMLFile=new XmlDocument();
XmlDocument xmlDoc=new XmlDocument();
// get the file from resource folder
String xmlData=resource.xmlfile name;
// Load the xml file
xmlDoc.LoadXml(xmlData);
//Messagebox.Show(xmlDoc.InnerXml);
// below code for xml node names naming space handling purpose
XmlNameTable xnt= xmlDoc.NameTable;
XmlNameSpaceManager nm=new XmlNameSpaceManager(xnt);
Nm.AddNamespace(“var1”,”http;//url”);
// assign the value for xpath
XmlNode nodevar=xmldoc.SelectSingleNode(“/var1:xmlnode1/var1:xmlnode2”,nm);
Nodevar.InnerText=this.Context[“DataSource1.csvfile#csv.columnname”].ToString();
Request1Body.BodyString=xmldoc.InnerXml;
Request1.Body=request1Body;
Friday, November 12, 2010
Web Services automation steps using Web Performace Test Template in TFS 2010
In VSTS 2010 for Web services automation use the Web Performance test template and follow below steps.
1. Open the VSTS 2010 and click on Test New Test
2. In “Add New Test” Window in Templates list select “Web Performance Test” Enter Test name in Test name edit box (ex:-Name.WebTest) Select one of the among the displayed test project technology ( Create a new Visual C# test Project …/ Create a New Visual basic test Project…/ Create a new Visual C++ test Project … or if any Project is existed, if we want select existing project) in “ Add to Test Project:” combo box Click on OK
3. It prompts New Test Project Popup enter a name for new project and click on “Create” button. Then it creates new solution with one project and then open browser with “Record”, “Pause” and ”Stop” buttons.
4. Click on “Stop” button It creates ”Name.WebTest” file with given Web test name node
5. Right Click on Web Test name node and click on “ Add Web service Request” , then it create “http://localhost/ “ - -> “String Body” Sub nodes under Test Node name
6. Right click on “http://localhost/” node or select “http://localhost/” and press F4, it opens “Properties” pane in right hand side of the screen.
7. In Properties pane enter the WSDL (Web services define language) in URL column. WSDL is just like URL.
8. Same way open the “String Body” node Properties, Select “text/xml” in the content Type combo box and enter Web method Request in the String Body edit box
9. Right Click on “http://localhost/” node and click on “Add Header” in the drop down menu
10. Under “Headers” Node select displayed “[Enter Name]=[Enter Value]” node and open properties Pressing F4 and then Select “SoapAction” in the Name combo box and in Value edit box enter “Soap Header”. Note:- Each web service is having its own Soap Header, This value we can get from developer or in SoapUI tool in Request pane get the soap header from request XML format pane.
11. Do You want to parameterize WSDL and Soap Action Header values follow below steps
a. Right click on Web test name node (Root or Parent node) and click on “Add Data Source” item in the drop down menu
b. Select type of “Data Source Type” like CSV file or XML File or Data base and Proceed with display wizards and click on Finish button in final wizard.
c. In hard coded fields values parameterize with data source coulumns
12. Run the test and analyze the result, After successfully script executed, click on Generate code link , It prompts dialog for file name and generates the below code in “.CS” file
13. Capture the Response with “Extractvalues” event handler Add below line of code before Yield statement in the “.CS” File
Request1.ExtractValues +=new EventHandler(Request1_ExtractValues);
14. Define the Request1_ExtractValues method Like below
public void request1_Extractvalues(Object sender, ExtractionEventArgs extract)
{
var xmlResponse = extract.Response.BodyString;
XmlDocument stringxmlDocument = new XmlDocument();
stringxmlDocument.LoadXml(xmlResponse);
XmlNodeList storeVal= doc1.GetElementsByTagName("NodeName ");
}
15. Add Data base and Validation code
16. Do the build and create new web performance test following the first 4 steps for CS file execution.
17. Right click on test name node and click on “Add Call to Web Test” and Select “.CS” file in Choose Window
18. Do the build and click on “Run Test” icon
19. For Data driven test follow the below :- Test à Edit Test Settings à Local settings à In Test Settings window click on Web Test à Turn on “One run for data source row” Radio button and click on Apply à Click on “Save As” Button and save the settings with overwriting the existing file.
20. Run the test and analyze the Results
1. Open the VSTS 2010 and click on Test New Test
2. In “Add New Test” Window in Templates list select “Web Performance Test” Enter Test name in Test name edit box (ex:-Name.WebTest) Select one of the among the displayed test project technology ( Create a new Visual C# test Project …/ Create a New Visual basic test Project…/ Create a new Visual C++ test Project … or if any Project is existed, if we want select existing project) in “ Add to Test Project:” combo box Click on OK
3. It prompts New Test Project Popup enter a name for new project and click on “Create” button. Then it creates new solution with one project and then open browser with “Record”, “Pause” and ”Stop” buttons.
4. Click on “Stop” button It creates ”Name.WebTest” file with given Web test name node
5. Right Click on Web Test name node and click on “ Add Web service Request” , then it create “http://localhost/ “ - -> “String Body” Sub nodes under Test Node name
6. Right click on “http://localhost/” node or select “http://localhost/” and press F4, it opens “Properties” pane in right hand side of the screen.
7. In Properties pane enter the WSDL (Web services define language) in URL column. WSDL is just like URL.
8. Same way open the “String Body” node Properties, Select “text/xml” in the content Type combo box and enter Web method Request in the String Body edit box
9. Right Click on “http://localhost/” node and click on “Add Header” in the drop down menu
10. Under “Headers” Node select displayed “[Enter Name]=[Enter Value]” node and open properties Pressing F4 and then Select “SoapAction” in the Name combo box and in Value edit box enter “Soap Header”. Note:- Each web service is having its own Soap Header, This value we can get from developer or in SoapUI tool in Request pane get the soap header from request XML format pane.
11. Do You want to parameterize WSDL and Soap Action Header values follow below steps
a. Right click on Web test name node (Root or Parent node) and click on “Add Data Source” item in the drop down menu
b. Select type of “Data Source Type” like CSV file or XML File or Data base and Proceed with display wizards and click on Finish button in final wizard.
c. In hard coded fields values parameterize with data source coulumns
12. Run the test and analyze the result, After successfully script executed, click on Generate code link , It prompts dialog for file name and generates the below code in “.CS” file
13. Capture the Response with “Extractvalues” event handler Add below line of code before Yield statement in the “.CS” File
Request1.ExtractValues +=new EventHandler
14. Define the Request1_ExtractValues method Like below
public void request1_Extractvalues(Object sender, ExtractionEventArgs extract)
{
var xmlResponse = extract.Response.BodyString;
XmlDocument stringxmlDocument = new XmlDocument();
stringxmlDocument.LoadXml(xmlResponse);
XmlNodeList storeVal= doc1.GetElementsByTagName("NodeName ");
}
15. Add Data base and Validation code
16. Do the build and create new web performance test following the first 4 steps for CS file execution.
17. Right click on test name node and click on “Add Call to Web Test” and Select “.CS” file in Choose Window
18. Do the build and click on “Run Test” icon
19. For Data driven test follow the below :- Test à Edit Test Settings à Local settings à In Test Settings window click on Web Test à Turn on “One run for data source row” Radio button and click on Apply à Click on “Save As” Button and save the settings with overwriting the existing file.
20. Run the test and analyze the Results
Subscribe to:
Comments (Atom)