Thursday, April 6, 2017

Parallel execution of scripts with TestNG

Parallel execution of scripts with TestNG


TestNG gives us the facility to execute multiple tests in parallel and two different methods of doing it are:

Method 1: Having multiple test method in one class file

Step 1: Create a class file with name “DummyTest1” and add following code in it.

public class DummyTest1

{

       public WebDriver driver;

  @Test
  public void main()
  {
     driver.findElement(By.name("userName")).sendKeys("mercury");
     driver.findElement(By.name("password")).sendKeys("mercury");
     driver.findElement(By.name("login")).click();
  }
 
  @Test
  public void main1()
  {
     driver.findElement(By.name("userName")).sendKeys("mercury");
     driver.findElement(By.name("password")).sendKeys("mercury");
     driver.findElement(By.name("login")).click();
  }

  @BeforeMethod

  public void beforeMethod()
  {
      driver = new FirefoxDriver();
      driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
      driver.get("http://newtours.demoaut.com/");
  }

  @AfterMethod

  public void afterMethod()
  {
       driver.quit();
  }

}

Step 2: Add following code in testng.xml file. Make sure you add the right class name.

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Parallel test suite" parallel="methods" thread-count="2">
  <test name="Regression 1">
    <classes>
      <class name="AutomationFrameworkForDummy.DummyTest1"/>
    </classes>
  </test>
</suite>


Step 3: Run it and you will see multiple browser window in parallel.

Method 2:  Having two test method in two class file.

Step 1: Create a class file and add following code in it.

public class Chrome_Search {
    WebDriver driver;
    
    @BeforeTest
       @Parameters("browser2")
     public void test1(String browser2)
     {
              if(browser2.equalsIgnoreCase("chrome"))
              {
                     System.setProperty("webdriver.chrome.driver", "E://Rajesh Document//AutomationFrameworks//WordPressAutomation//Drivers//chromedriver.exe");
                       driver =new ChromeDriver();
                       driver.get("www.google.com");
                      
                 } 
              else
              {
                     System.out.println("Google Chrome"); 
              }
         }
  
   }

Step 2: Create another class file and add following code in that class file.

public class Mozilla_OpenAmazon {
    WebDriver driver;
       @BeforeTest
       @Parameters("browser1")
    public void launchbrowser(String browser1)
     {
              if(browser1.equalsIgnoreCase("firefox"))//For Firefox we dont need to download any jar file as we have Inbuilt firefox jar files
              {
                     driver=new FirefoxDriver(); 
                  System.out.println("Hello Google..."); 
                  driver.get("https://www.amazon.com/");
                  driver.findElement(By.id("twotabsearchtextbox")).sendKeys("Dolly");
                                                  
           }
              else
              {
                     System.out.println("Firefox"); 
              }
     }
              @AfterTest
              public void closeBrowser()
              {
                     driver.quit();
              }
}

Step 3: Add following code in testng.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
  <suite name="Suite" parallel="tests">

  <test name="FirefoxTest" >
  <parameter name = "browser1" value="Firefox"/>
  <classes>
  <class name ="AutomationFrameworkForDummy.Mozilla_OpenAmazon"> </class>
  </classes>
  </test>
   
 
  <test name ="Chrome Test">
    <parameter name = "browser2" value="Chrome"/>
   <classes>
  <class name ="AutomationFrameworkForDummy.Chrome_Search"/>
  </classes>
   </test>
   </suite>


Step 4: Now Run it.

Tuesday, April 4, 2017

Installing TestNG in Eclipse and creating first Test

1)       Launch Eclipse > On the menu bar, click Help > Choose the "Eclipse Marketplace..." option 

2)       In the Eclipse Marketplace dialog box, type TestNG in the search box and press the search button
















3)       Click on Install > A new window will open to confirm the options. Don’t make any change and click “Confirm”


4)       Click next on every other window. Accept the license. Restart the eclipse. After the restart, right-click on the project name and check the following two options.










5) Now click “Create TestNG class”to add a new class. And copy the following code

public class DummyTest1

{

   public WebDriver driver;

  @Test

  public void main()
  {
     driver.findElement(By.name("userName")).sendKeys("mercury");
     driver.findElement(By.name("password")).sendKeys("mercury");
     driver.findElement(By.name("login")).click();
  }

  @BeforeMethod

  public void beforeMethod()
  {
      driver = new FirefoxDriver();
      driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
      driver.get("http://newtours.demoaut.com/");
  }

  @AfterMethod

  public void afterMethod()
  {
       driver.quit();
  }

}

6)       Now click Run > Run as > TestNG Test






Tuesday, March 28, 2017

Integration of selenium Jars and first test case with Selenium

Step 1: Download web driver java client from the location.












Step 2: Extract the zip file, place all the jar files where you want to maintain your test wares.







Step 3: Launch eclipse, create a new workspace, and create a new project









Step 4: Select “Java Project”. Give a project name “AutomationForDummy”.

Step 5: Create a new package and then create a new class.





























Step 6: Add external Jars to java build path

Right click on project > select properties > Java build path > Libraries tab > click “Add External JARs”.
  • Add selenium Java jar
  • Add all other jars in libs folder













Step 7: Add following code in your class

       WebDriver driver = new FirefoxDriver();
             
       //Launch the google search engine
       driver.get("http://www.google.com");

       // Print a Log In message to the screen
       System.out.println("Successfully opened google search page");

       //Wait for 5 sec
             
       Thread.sleep(5);
                          
       // Close the driver
       driver.quit();

Step 8: Right click on the window > Run as > Java Application

See the result.


Monday, March 27, 2017

Eclipse download and installation


Step 1: Goto the following page and select the eclipse version which you want to download.

I will prefer to download Indigo.

Step 2: It is critical to have Java, eclipse and OS should all be of same 64 or 32 bit version.

Step 3: After complete installation, click on eclipse.exe.


Step 4: if you get Exit code 13 with following screen shot.



Try adding following line in your eclipse.ini file

-vm
C:\Program Files\Java\jdk1.7.0_60\bin\javaw.exe

Check the complete path of Javaw.exe and add these two lines just before -vmargs.

Step 5: If path is not correct, you will get following error.


Step 7: Click on Eclipse.exe and you will get following window.


And installation is done. 

Wednesday, July 6, 2016

Performance testing parameters and its relation with performance

1.     Response time (Total turnaround time (TTAT))

  • Always measured in seconds on client side, measured in millisecond for server processing, measured in nanosecond for network.
  • Response time is inversely proportional to performance.

2.     Hit per second (HPS)

  • Request accepted by server, not processed by server
  • It is directly proportional to efficiency of server which might yield to higher performance.
           Case 1:- load is increasing but hit is not increasing -> client side memory leaks,

           Example: IE GUI closed but process running,

           Case 2:- load is in steady state but hit/sec is zero => hits are in queue

3. Throughput


  • For response data, it is measured in bytes per sec. It helps us in analysing the bandwidth, how much data is processed and pushed from server to client.
  • Case1: Hit/sec is decreased, load is increased but throughput is increasing -> memory leak at server side. Unclosed, unattended session at server. Improper handling of sessions.
  • Throughput increases with increasing hits on the web server for a certain range. Generally, it also depends on the bandwidth available. Then at a certain range, the Throughput becomes constant & at this point if hits per sec increases then the throughput decreases.
  • So whenever we derive a relation between Hits per sec & Throughput then within the threshold limits they are directly proportional to each other.


4. Transaction per sec (TPS)

  • Number of transaction of a specific business process has been completed in one second, larger the value higher the efficiency of server and higher the performance.


5. Total transaction per second (TTPS)

  • Total no of transactions completed in one second irrespective of business process. Larger the value of TTPS, higher the efficiency of server.


6. Connection per second (CPS)

  • Number of connection opened per second
  • The number of new connections should be a small fraction of the number of hits per second, because new TCP/IP connections are very expensive in terms of server, router and network resource consumption. Ideally, many HTTP requests should use the same connection, instead of opening a new connection for each request.
  • Exponential directly proportional to load


7. Pages downloaded per second (PDPS)

  • Number of Web pages downloaded from the server during each second of the load test scenario run.

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.