Wednesday 24 December 2014

Web Service API Functional and Performance Testing using VSTS

Assumptions:

 Below are list of assumptions:
  • Visual Studio Ultimate 2010 is installed.
  • Sql Server Express 2008
  • Minimum 4 GB RAM

Web Service API Functional and Performance Testing using VSTS:

1. Create a Test Method
    Here are the steps to create a test in VSTS:
   • Navigate to “Start-> All Programs ->    Microsoft Visual Studio 2010” and Click “Microsoft Visual Studio 2010”.
   • It will open the VSTS window.

   • Click on “New Project” link.
   • It will open a pop-up to select the project.
    • As I prefer C# so select “Test” in Visual C#.
    • Select “Test Project”.
    • Modify the “Name” say “DummyLearn”. (Whatever “Name” you will give, it keeps the “Solution name” as same.)
   • Provide the “Location” were project will be remaining.
   • Click on “OK”.
   • It will create a “DummyLearn” test project.
   • By Default, It will create a “UnitTest1.cs” file and open it.
   • Right Click on “UnitTest1.cs” file and select "Rename" option.
   • Rename the file as "dummytest" and pop-up window will appear.
   • Click on "Yes".
   • It will update the class name.
   • Make a call to an API and read the response. Refer below code:

   HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strAPIURL);
   request.Method = "GET";
   using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
   {
     if (response.StatusCode == HttpStatusCode.OK)
     {
       using (Stream respStream = response.GetResponseStream())
       {
         StreamReader reader = new StreamReader(respStream, Encoding.UTF8);
         Console.WriteLine(reader.ReadToEnd());
       }
     }
   }

2. Run a Test Method     Here are the steps to run a test method in VSTS:
   • Put the cursor on any point within the Test Method and Right click on it.
   • Select the "Run Tests" option.
   • Execution will be "In-Progress" status and we can view it in "Test Results" section.
   • Once execution is over, we can view the status either "Passed/Failed" in "Test Results" section.
   • Double click on executed method result in "Test Results" section.
   • We can view the API response details.
3. Parameterization
  • Create a folder in project for test data say “TestData”.
  • Copy-paste CSV files which has required data to be parameterize.
  • Right-Click on “TestData” folder. Select “Add->Existing Item..”

  • Select “All Files (*.*) “option at bottom and then select “Data.csv” file which is visible now. 
   • Click on “Add”.
   • It will add the file in the project.
 

  • Add below mentioned TestContext code in the Class to get-set the values.

  private TestContext testContextInstance;
  public TestContext TestContext
  {
    get
    {
      return testContextInstance;
    }
    set
    {
      testContextInstance = value;
    }
  }

  • Add "[DataSource]" to bind the CSV file with a Test Method.
  • Here is the example:
  [DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV",
  "|DataDirectory|\\TestData\\Data.csv",
  "Data#csv", DataAccessMethod.Sequential), DeploymentItem("Data.csv")]

  • Use the CSV column Values in the code and here is the example:
   TestContext.DataRow["Column1Name"] //Default would be string.
   TestContext.DataRow["Column1Name"].ToString() // Convert into string.
   Convert.ToInt32(TestContext.DataRow["Column1Name"]) // Convert into int.
  Note: Add "System.Data" in project "References".
3. Call a Test Method in Load Test
  • Right-Click on “DummyLearn” Project.
  • Navigate and Select “Add > Load Test..".
  • Open a "New Load Test Wizard".
  • Click on "Next".
  • Enter the Scenario Name say "Dummytest" and select "Think time profile" option required for performance run.
  • Click on "Next".
  • Enter the load pattern required for performance run. // I choose step load pattern.
  • Click on "Next".
  • Select the Test Mix that should be considered for performance run.
  • Click on "Next".
  • Section to add test scenario.
  • Click on "Add".
  • Move the Test Method from Available panel to Selected.
  • Click on "Ok".
  • Click on "Next".
  • Set the "Network Mix" settings, if any.
  • Click on "Next".
  • Set the "Counter Sets" settings, if any.
  • Click on "Next".
  • Set the "Run Settings" parameters which specify the length of the load test.
  • Click on "Finish".
  • Load Test is created for the API.
  • Click on "Run Test" to initiate the performance run.

  • Once execution is over analyze the result.

Thursday 21 August 2014

Zephyr Test Management Tool Integration with Telerik Test Studio

Overview:
This article provide the approach to integrate Telerik Test Studio scripts with Zephyr and will perform following activities:
  • Test case script kick-off from Zephyr
  • Test case script result updation in Zephyr

Pre-Requisite:
Below are the pre-requisite:
  • Automated Test case is created in Zephyr. (Note: Test case type will show “A”)
  • Automated Test case is appearing in Zephyr execution panel. (Note: “E” button will appear against the test case to start the execution of script)
  • Zephyr Zbot should be installed, configured and started properly in any machine. (Note: Please contact Zephyr support team for ZBot setup)

Creation of Java Wrapper:
We have to create a Java wrapper code which will have following features:
  • Read the Telerik result file.
  • Fetch the test case result (either Pass or Fail).
  • Update the status in Zephyr by get the results for “currentTestcaseExecution” and call “scriptUtil.updateTestcaseExecutionResult()” in “public void testcaseExecutionResult()” method.
  • Export the java project in *.jar file.

Deployment of Java Wrapper:
Below are the steps to deploy the Java wrapper:
  1. In $ZBOT_HOME\conf\wrapper.conf, add following entries
  2. wrapper.java.mainclass=com.thed.wrapper.ZephyrWrapperSimpleApp
    wrapper.java.classpath.5=../plugin/ZephyrWrapperCode.jar
    wrapper.java.classpath.6=../lib/ZephyrWrapperCode.jar
  3. Copy jar file to $ZBOT_HOME\lib\
  4. Copy jar file to $ZBOT_HOME\plugin\
  5. Make sure scriptLauncher property is set in $ZBOT_HOME\conf\zbot.properties
  6. scriptLauncher=com.testzip.zip.ZephyrWrapperCode
  7. Restart ZBot

Approach:
  • In Zephyr automation test case “Path” field, we have to provide the parameterize batch file path with parameter value as Telerik web test name so that specific test case script should execute.
  • Eg: In “Path” give value as “C:\TelerikExecution\ZephyrTelerik.bat DummyWebTest”
  • Batch file will have Telerik Project web test execution through command prompt.
  • Click on “E” in Zephyr, select the ZBot and Click on “Run”.
  • Telerik script will be executed through batch file, once execution will over Zephyr wrapper will read the test case test cases result and will update the status in Zephyr.
  • Flow diagram

Thursday 10 April 2014

Web Test using VSTS

Assumptions:

 Below are list of assumptions:
  • Visual Studio Ultimate 2010 is installed.
  • Sql Server Express 2008
  • Minimum 4 GB RAM

Web Performance Test:

1. Record & Play
    Here are the steps to create a web test in VSTS:
   • Navigate to “Start-> All Programs ->    Microsoft Visual Studio 2010” and Click “Microsoft Visual Studio 2010”.
   • It will open the VSTS window.

   • Click on “New Project” link.
   • It will open a pop-up to select the project.
    • As I prefer C# so select “Test” in Visual C#.
    • Select “Test Project”.
    • Modify the “Name” say “DummyLearn”. (Whatever “Name” you will give, it keeps the “Solution name” as same.)
   • Provide the “Location” were project will be remaining.
   • Click on “OK”.
   • It will create a “DummyLearn” test project.
   • By Default, It will create a “UnitTest1.cs” file and open it.
   • As we are doing “Web Test” so we can delete this file.
   • “Close” the open tab window.
   • Right click on “UnitTest1.cs” file and select “Delete” option.
  • Click on “OK”.
  • It will delete the file from the project.
  • Right Click on “DummyLearn” project.
   • Navigate to “Add -> New Test”.
   • Select  “Web Performance Test”.
  • Enter the web Test name say “DummyInfostretch.webtest”.
   • Click on “OK”.
   • It will open an IE browser window for recording with option like Record, Pause, Stop etc.
   • Open the URL in browser and perform recording as per test steps.
   • We have use dummy site for a web step and once recording done click on “Stop”.
   • It will enter the request URL’s in VSTS webtest and add the dynamic parameters which VSTS by default add for the responses of the requests.

2. Execution
  • Click on “Run test” button and it will run the recorded test.

  • Once executed it will show the Test Result in separate tab.

  • We can temporary change the run settings by clicking on “Edit the run settings” and then run by clicking on “Click here to run again”.

  Note: To permanently change the settings, it’s covered in Web Test Settings section. 

3. Parameterization
  • Create a folder in project for test data say “TestData”.
  • Copy-paste CSV files which has required data to be parameterize.
  • Right-Click on “TestData” folder. Select “Add->Existing Item..”

  • Select “All Files (*.*) “option at bottom and then select “Data.csv” file which is visible now. 
   • Click on “Add”.
   • It will add the file in the project.
 

  • Click on “Add Data Source” image of a web test. 
  • Give data source name say “DummyInfoTestData” and select CSV file option.
  • Click on “Next”.
  • Select CSV file from project “TestData” folder.
  • It will show the CSV data there.

  • Click on “Finish”.
  • Data Source will be created in a web test.
  • Select the URL request were data need to be fetched from CSV.
  • View its properties.

  • Click on URL properties and select the data source field column value.
  • It will replace the request URL with CSV value like “DummyInfoTestData.Data#csv.URL”.
  • Let’s say if we have a URL like http://www.google.com/contact-us.php just edit the URL as “{{ DummyInfoTestData.Data#csv.URL }}/contact-us.php”. It will take the value from CSV file.

  • Run the parameterize web test.
 

4. Web Test Settings
  • Navigate to “Test->Edit Test Settings->Local (local.testsettings)”.
  • Click on “Web test” and change the test settings.

  • Click on “Apply” and then click on “Close”.
  • These settings will reflect on all the web test of a project and even will be considered whenever we call the web test in a load test.