Wednesday, July 6, 2016

Performance Testing & Its types

Performance Testing – Definition


Performance testing is a type of testing intended to determine the responsiveness, throughput, reliability, and/or scalability of a system under a given workload. It can also serve to investigate measure, validate or verify other quality attributes of the system, such as resource usage.

Performance testing determines speed, scalability, stability, while focusing on cost, system constraint, user expectation

Performance testing types:-


1.     Load testing

  • Load testing is the simplest form of performance testing.
  • A load test is usually conducted to understand the behaviour of the system under a specific intended/expected/anticipated load.
  • This load can be the expected (already known to user) concurrent number of users on the application performing a specific number of transactions within the set duration.
  • This test will give out the response times of all the important business critical transactions.
  •   If database and/or application server, etc. are also monitored, then this simple test can itself point towards any bottlenecks in the application software.

2.     Stress testing

  • Stress testing is normally used to understand the upper limits of capacity (no. of users) within the system.
  • When user load is greater than the intended load then it is called stress testing.
  • Another condition is when load is negligible but environment under test is with unfavourable/abnormal condition then also it is called stress testing.
  •  This kind of test is done to determine the system's robustness in terms of extreme load and helps application administrators to determine system performance if the current load goes well above the expected maximum.


3.     Spike testing

  • Spike testing is done by suddenly increasing the number of, or load generated by, users by a very large amount and observing the behaviour of the system. The goal is to determine whether performance will suffer, the system will fail, or it will be able to handle dramatic changes in load.
  • Load repeatedly is increased beyond anticipated load for short period of time.


4.     Endurance testing (soak testing)

  • It is a subset of load testing – Intended load is applied for long duration over an extended period.
  • Minimum of 4 hours and maximum can be 1 day or 2 day.
  • Endurance testing is usually done to determine if the system can sustain the continuous expected load.
  • During endurance tests, memory utilization is monitored to detect potential leaks.
  • Also important, but often overlooked is performance degradation. That is, to ensure that the throughput and/or response times after some long period of sustained activity are as good as or better than at the beginning of the test.
  • It essentially involves applying a significant load to a system for an extended, significant period of time. The goal is to discover how the system behaves under sustained use.


5.     Capacity Testing

  •  To check the total workload (increased number of users beyond intended load) a server can handle without violating predetermined key performance acceptance area is called Capacity testing.


6.     Scalability Testing


  • Scalability is the capability to increase resources to yield a linear (ideally) increase in service capacity. The key characteristic of a scalable application is that additional load only requires additional resources rather than extensive modification of the application itself.
  • To check the application's ability to handle additional workload without affecting performance.
  • Scalability testing is an extension of performance testing. The purpose of scalability testing is to identify major workloads and mitigate bottlenecks that can impede the scalability of the application.
  • Don’t confuse scalability with capacity testing. Without upgrading the hardware if testing is done then it is known as capacity testing and if hardware is upgraded then it is known as scalable testing.



7.     Stability testing

  • Determine reliability, robustness, function and data integrity, availability, consistency of responsiveness under variety of expected and unexpected condition. To check the stability of the application, do all kind of performance testing.


8.     Benchmark testing

  • Benchmark testing is the process of load testing a component to determine the performance characteristics of the application.
  • The benchmark test is repeatable in that the performance measurements captured will vary only a few percent each time the test is run. This enables single changes to be made to the application or infrastructure in an attempt to determine if there is a performance improvement or degradation.
  • The goals of benchmark testing typically fall into two categories; 
    • To test the system to measure how a change affects its performance characteristics.
    • To test and tune the system to reach a performance requirement or service level agreement (SLA). In this case a series of benchmark tests are conducted in conjunction with iterative cycles of performance tuning.


9.     Configuration Testing

  • Rather than testing for performance from the perspective of load, tests are created to determine the effects of configuration changes to the system's components on the system's performance and behaviour. A common example would be experimenting with different methods of load-balancing.

10.   Volume Testing

  • Volume testing is done against the efficiency of the application. Huge amount of data is processed through the application (which is being tested) in order to check the extreme limitations of the system whether no. of users are 1 or 2 or 10. Standard is 10
  • Such systems can be transactions processing systems capturing real time sales or could be database updates and or data retrieval.
  • Volume testing will seek to verify the physical and logical limits to a system’s capacity and ascertain whether such limits are acceptable to meet the projected capacity of the organization’s business processing

11.  Component Testing

  • Component test is any performance test that targets a single architectural component of the application.
  • Commonly tested components include servers, DB, networks, Firewalls, storage device.

Monday, September 21, 2015

Handle Popup dialog boxes using Selenium (C#) webdriver

Closing popup is what a tester need so many times in automation. See how we can do it.

Step 1: Create a new project and add a new item “Basic Unit Test”.

Step 2: Click on the project name -> Add new item -> Select “Basic Unit Test” -> Click ok

Step 3: Add following code in your CS file

using OpenQA.Selenium.Interactions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using System.Collections.ObjectModel;


namespace WordPressAutomation.RegressionTests
{
    [TestClass]
    public class Window_Handle_Class
    {
        [TestMethod]
        public void Window_Handle()
        {
            FirefoxDriver driver = new FirefoxDriver();
            driver.Navigate().GoToUrl("http://www.naukri.com/");
            string existingWindowHandle = driver.CurrentWindowHandle;
            driver.Manage().Window.Maximize();
           
           string NewWindowHandle = string.Empty;
            ReadOnlyCollection<string> windowHandles = driver.WindowHandles;
          

            foreach (string handle in windowHandles)
            {

                if (handle != existingWindowHandle)
                {
                    NewWindowHandle = handle;
                    //switch to new window
                    driver.SwitchTo().Window(NewWindowHandle);
                    //close the new window 
                    driver.Close();
                }
             }
            //switch back to original window
            driver.SwitchTo().Window(existingWindowHandle);
        }
    }
}


Step 4: It is done. Execute the code. 

Sunday, September 20, 2015

Drag and Drop using Selenium Webdriver


A tester need to drag an object and drop it somewhere on the UI and through automation it is also achievable with the help of Action class. Let’s try it.

Step 1: Create a new project and add a new item “Basic Unit Test”.

Step2:  Add the following code into it.

using OpenQA.Selenium.Interactions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;

namespace WordPressAutomation.RegressionTests
{
    [TestClass]
    public class DragAndDrops
    {
        [TestMethod]
        public void Drag_and_drop()
        {
            FirefoxDriver driver = new FirefoxDriver();
            driver.Navigate().GoToUrl("http://jqueryui.com/droppable/#default&rdquo");
            driver.Manage().Window.Maximize();

            Actions act = new Actions(driver);

            // Script for dragging an element and dropping it in another place
            IWebElement iFrame = driver.FindElement(By.TagName("iframe"));
            driver.SwitchTo().Frame(iFrame);
            IWebElement From = driver.FindElement(By.Id("draggable"));
            IWebElement To = driver.FindElement(By.Id("droppable"));
            act.DragAndDrop(From, To).Build().Perform();
           
            driver.Close();
        }
    }
}






Step 3: Execute it and it is done.

Friday, September 18, 2015

Mouse Hover Actions in Selenium Webdriver

Sometimes a tester wants to mouse hover on an object instead of clicking it. It can be done with the help of Action class. Let’s try it.

Step 1: Create a new project and add a new item “Basic Unit Test”.

Step2:  Add the following code into it.

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Interactions;
using OpenQA.Selenium;
using System.Threading;

namespace UnitTestProject2
{
    [TestClass]
    public class ActionClass
    {
        [TestMethod]
        public void Test_Action()
            {
               
                FirefoxDriver driver = new FirefoxDriver();
                driver.Navigate().GoToUrl("http://www.snapdeal.com/");
                driver.Manage().Window.Maximize();

                Actions a1 = new Actions(driver);
                a1.MoveToElement(driver.FindElement(By.XPath(".//*[@id='leftNavNemu']/div/div[1]/ul/li[3]/a/span[1]"))).Build().Perform();
                Thread.Sleep(3000);
              
           
                Actions a2 = new Actions(driver);
                a2.MoveToElement(driver.FindElement(By.XPath(".//*[@id='leftNavNemu']/div/div[1]/ul/li[3]/div/ul/li[3]/a/span[1]"))).Build().Perform();
                Thread.Sleep(3000);

                Actions a3 = new Actions(driver);
                a3.MoveToElement(driver.FindElement(By.XPath(".//*[@id='leftNavNemu']/div/div[1]/ul/li[3]/div/ul/li[3]/div/div/ul/li/div[1]/div/form/div[1]/p[2]/a"))).Click().Perform();
                Thread.Sleep(3000);

            }
    }
}

Step 3: Execute it and it is done.

Data driven test method using selenium (C#)

Test methods which need to be executed with different set of data are very common in testing and the best approach for this type of test is to create a CSV file with all set of test data and call it in your test. See how we can do it using C#

Step 1: Create a new project and add a new item “text file” and name it as testdata.csv.

Step 2: Add following code in this test data file

SiNo,Client,Client_Initials,Run
1,DemoClient1,DemoClient1,Yes
2,DemoClient2,DemoClient2,Yes
3,DemoClient3,DemoClient3,Yes
4,DemoClient4,DemoClient4,Yes

Step 3: Click on the project name -> Add new item -> Select “Basic Unit Test” -> Click ok

Step 4: Add following code in your CS file

using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Data;
using System;

namespace WordPressAutomation.SmokeTest
{
    [TestClass()]
    public class BankAccountTest
    {
        private TestContext testContextInstance;
        public TestContext TestContext
        {
            get { return testContextInstance; }
            set { testContextInstance = value; }
        }

        [TestMethod]
        [DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "C:\\Users\\DemoUser\\Documents\Visual Studio 2013\\Projects\\UnitTestProject2\\UnitTestProject2\\testdata.csv", "TestData#csv", DataAccessMethod.Sequential)]
        public void DebitTest()
        {

            Console.WriteLine(testContextInstance.DataRow["Client"]);
            Console.WriteLine(testContextInstance.DataRow["Client_Initials"]);
            Console.WriteLine(testContextInstance.DataRow["Run"]);
        }
   }
}

Step 5: Click on “Reference” -> Add Reference - > Select system.data -> Click ok


Step 6: It is done. Execute it and see all test data mentioned in CSV file will be executed. 

Thursday, September 17, 2015

How to use App.Config for configuration variables in selenium (C#) test

Sometimes in your framework, you are required to define some variables (custom information) that you have to use throughout your framework. For such variables we use, app.config file.

Step 1: Create a new visual studio project.

Step 2: In the Add New Item list, click to select XML File.

Step 3: In the Name text box, type App.config(Don’t add “.xml” in the filename), and then click Add.

Step 4: Add following code in your app.config file.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <appSettings>

    <!--Browser Information-->
    <add key="Browser Name" value="Firefox"/>

    <!--Environments URLs-->
    <add key="POS Upload url" value="http://testing.apps.eco.com/StagingPOSUpload/"/>
    <add key="Salesforce url" value="https://test.salesforce.com/"/>

    <!--Environments Credentials-->
    <add key="POS Username" value="azunjurwad"/>

  </appSettings>
</configuration>

Step 5: Add a new item “Unit test” in the project and add following code to access the variables defined in App.config file

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Configuration;

namespace UnitTestProject2
{
    [TestClass]
    public class UnitTest3
    {
        [TestMethod]
        public void TestMethod1()
        {
            Console.WriteLine(ConfigurationManager.AppSettings["Browser Name"]);
            Console.WriteLine(ConfigurationManager.AppSettings["POS Upload url"]);
            Console.WriteLine(ConfigurationManager.AppSettings["Salesforce url"]);
            Console.WriteLine(ConfigurationManager.AppSettings["POS Username"]);
        }
    }
}

Step 6: Click on references -> Add reference - > Select “System.configuration” and click ok.

Step 7: Execute this test method and it is done.