Tuesday, February 6, 2018


TestLink Setup for Automation:
1. First you need to enable Automation (API keys) of your test link project.
Open your testlink project, click on check box of “Enable Test Automation (API keys)” and click on save button.

2. Generate Key: This key provide interface between webdriver test scripts and testlink. You must generate this  key. To generate this click on >> My Settings  menu and click on “Generate a new key” button under “API interface” section.


3. Create test link project.
4. Create test link plan and add test plan to created test link project.
5. Create test suite and test cases under created test link project.

Scripts Creation:
1. Download “testlink-api-client.zip “ file and add “testlink-api-client-2.0.jar” , “xmlrpc-common-3.1.jar”, “xmlrpc-client-3.1.jar”,” ws-commons-util-1.0.2.jar” jar file in your webdriver java project class path.
2. Below I have created a sample code for integration of test link with webdriver java script.
package com.test;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import testlink.api.java.client.TestLinkAPIClient;
import testlink.api.java.client.TestLinkAPIException;
import testlink.api.java.client.TestLinkAPIResults;

public class SeleniumTestLinkIntegration {

    private WebDriver driver;
   
    // Substitute your Dev Key Here
    public final String DEV_KEY = "4dec862f7e8045afc9cffd8630fe45c4";

    // Substitute your Server URL Here
    public final String SERVER_URL = "http://localhost/testlink-1.9.7/lib/api/xmlrpc/v1/xmlrpc.php";

   // Substitute your project name Here
    public final String PROJECT_NAME = "SampleProject";

    // Substitute your test plan Here
    public final String PLAN_NAME = "SampleTestPlan";

    // Substitute your build name
    public final String BUILD_NAME = "SampleBuild";

    @BeforeSuite
    public void setUp() throws Exception {
         driver = new FirefoxDriver();              
    }

    @Test
    public void testSearchCountry() throws Exception {
         String result = "";
         String exception = null;
         try {
              driver.navigate().to("http://www.wikipedia.org/wiki/Main_Page");
              result = TestLinkAPIResults.TEST_PASSED;
              updateTestLinkResult("TC001-1", null, result);
         } catch (Exception ex) {
              result = TestLinkAPIResults.TEST_FAILED;
              exception = ex.getMessage();
              updateTestLinkResult("TC001-1", exception, result);
         }
         try {
              driver.findElement(By.id("searchInput")).clear();
              driver.findElement(By.id("searchInput")).sendKeys("India");
              result = TestLinkAPIResults.TEST_PASSED;
              updateTestLinkResult("TC001-2", null, result);
         } catch (Exception ex) {
              result = TestLinkAPIResults.TEST_FAILED;
              exception = ex.getMessage();
              updateTestLinkResult("TC001-2", exception, result);
         }
         try {
             driver.findElement(By.id("searchButton")).click();
             result = TestLinkAPIResults.TEST_PASSED;
             exception = null;
             updateTestLinkResult("TC001-3", null, result);
         }
         catch (Exception ex) {
             result = TestLinkAPIResults.TEST_FAILED;
             exception = ex.getMessage();
             updateTestLinkResult("TC001-3", exception, result);
         }
         String str = driver.findElement(
         By.xpath("//h1[@id='firstHeading']/span")).getText();                               
         Assert.assertTrue(str.contains("India"));
    }


    @AfterSuite
    public void tearDown() throws Exception {
         driver.quit();                                                      
    }
   
    public void updateTestLinkResult(String testCase, String exception, String result)    throws TestLinkAPIException {
         TestLinkAPIClient testlinkAPIClient = new TestLinkAPIClient(DEV_KEY,
                                SERVER_URL);
         testlinkAPIClient.reportTestCaseResult(PROJECT_NAME, PLAN_NAME,
                                testCase, BUILD_NAME, exception, result);
    }
}


Saturday, November 8, 2014

Integration of Selenium Webdriver with Test link

                                        

This Post will describe how to integrate Testlink- Selenium. i.e. executing the test cases and updating the status in the Testlink.

2 Different approaches which we can follow to achieve:
          1)  Using Eclipse-Selenium Web driver.
          2)  Using Jenkins-Selenium Web driver.

Before going to execute the test cases using Jenkins or Eclipse, first thing we need to do some Settings in the TestLink.
Edit config.inc.php file, go to line number 379, and add this line

$tlCfg->api->enabled = TRUE;

Test link:


1) API access Key-Test link :
This key will provide an interface between selenium web driver  test cases to Test link, to generate this key, go to Test link--> Setting--> API interface Section-- >Click on Generate Key.

2) Enable Test Automation(API Keys) :
     Go to Test link interface and Enable the check box for the Project which we have created for automation.

3) Create a Project in Test link.

4) Create test suite under project and write the Manual test cases and Select Execution type as Automated.

5) Create test plan, build and assign the test cases to the plan.

6) Create a Custom filed in Testlink (Java Class) add it to the project.




                                                 Create Test Plan under the Project.


                                  
                                  Create Custom Fields as “Java Class ” and assigned to the Test Plan.



                                               Add the automated test cases to the Test plan



After configuring all the above in the Testlink write the code into the eclipse using below code.

Eclipse-Selenium Web driver Test cases:

1)      Download Test link-api-client libs:

       Download “testlink-api-client.zip “file and add “testlink-api-client-2.0.jar”, “xmlrpc-common-3.1.jar”, “xmlrpc-client-3.1.jar”, and”ws-commons-util-1.0.2.jar” jar file in your web driver java project class path.  


2)       Write the Program in the eclipse for the test case and Click on execute it. After completion of execution, status will be update in the test link.

package com.sample;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.*;
import testlink.api.java.client.TestLinkAPIClient;
import testlink.api.java.client.TestLinkAPIException;
import testlink.api.java.client.TestLinkAPIResults;

public class seltestlinkinte {

    private WebDriver driver;  
    // Substitute your Dev Key Here
    public final String DEV_KEY = "5hyg785g4y6287hvg8cjjd6903dg85v7";
 
    // Substitute your Server URL Here
    public final String SERVER_URL = "http://localhost/testlink-1.9.10/lib/api/xmlrpc/xmlrpc.php";

   // Substitute your project name Here
    public final String PROJECT_NAME = "SampleProject";

    // Substitute your test plan Here
    public final String PLAN_NAME = "SampleTestPlan";

    // Substitute your build name
    public final String BUILD_NAME = "SampleBuild";

    @BeforeSuite
    public void setUp() throws Exception {
         driver = new FirefoxDriver();             
    }

    @Test
    public void Searchitem() throws Exception {
         String result = "";
         String exception = null;
         try {
              driver.navigate().to("http://url");
              result = TestLinkAPIResults.TEST_PASSED;
              updateTestLinkResult("TC001-1", null, result);
         } catch (Exception ex) {
              result = TestLinkAPIResults.TEST_FAILED;
              exception = ex.getMessage();
              updateTestLinkResult("TC001-1", exception, result);
         }
         try {
              driver.findElement(By.id("searchInput")).clear();
              driver.findElement(By.id("searchInput")).sendKeys("shoes");
              result = TestLinkAPIResults.TEST_PASSED;
              updateTestLinkResult("TC001-2", null, result);
         } catch (Exception ex) {
              result = TestLinkAPIResults.TEST_FAILED;
              exception = ex.getMessage();
              updateTestLinkResult("TC001-2", exception, result);
         }
         try {
             driver.findElement(By.id("searchButton")).click();
             result = TestLinkAPIResults.TEST_PASSED;
             exception = null;
             updateTestLinkResult("TC001-3", null, result);
         }
         catch (Exception ex) {
             result = TestLinkAPIResults.TEST_FAILED;
             exception = ex.getMessage();
             updateTestLinkResult("TC001-3", exception, result);
         }
         String str = driver.findElement(
         By.xpath("//h1[@id='firstHeading']/span")).getText();                              
         Assert.assertTrue(str.contains("shoes"));
    }


    @AfterSuite
    public void tearDown() throws Exception {
         driver.quit();                                                     
    }
  
   public void updateTestLinkResult(String testCase, String exception, String result)throws TestLinkAPIException {
         TestLinkAPIClient testlinkAPIClient = new TestLinkAPIClient(DEV_KEY,
                                SERVER_URL);
         testlinkAPIClient.reportTestCaseResult(PROJECT_NAME, PLAN_NAME,
                                testCase, BUILD_NAME, exception, result);
    }
}


fig: 1

fig:2 (PASS)

fig:3(Fail)

Figure 1,2  & 3 are after executing the test cases




       
Configuration in Jenkins for Testlink automation

Monday, May 19, 2014

Selenium Integration With Jmeter...

Is Jmeter capable of doing Performance testing of an application with Selenium Scripts..?
Answer is yes, this is possible with Jmeter and Selenium Scripts written over in Junit.
  • Jmeter is having set of samplers of doing Different operations. For Integration we have sampler Known as "Junit Request", this can be used to execute tests written in Junit 3 or junit4 (Selenium)
  • A test Script written junit4 uses Junit annotations, below is the example of the Scripts which is written in Selenium Junit 4


For Total Script click on this Link....... Selenium_JunitScript

Once the Scripting is done , Export them as jar files .To export to jar files right click on the project folder -> select Export-> Expand Java folder -> Click on Jar files -> Click next -> select the resources to export -> check the option “Export java source files and resources”-> Choose destination -> finish



Copy the Jar file and paste it in the Junit folder under lib folder of Jmeter. Here is the path in my system “D:\apache-jmeter-2.9\lib\Junit”.

Before proceeding further, Download Selenium Standalone Server at this location “https://code.google.com/p/selenium/downloads/detail?name=selenium-server-standalone-2.39.0.jar”
  • Copy the Selenium Standalone server jar file to the lib folder of Jmeter
  • Now open Jmeter, Create a Thread group{right click on testplan-> Select ADD-> Select Thread(users)-> Select Thread Group}
  • Create a "junit Request"{Right click on Thread Group-> Select Add-> Select Sampler-> Select Junit Request}
In the two drop downs (Marked as red) one could be the tests that are created using Junit4 i.e. by extending the Test Case class (Classname)

-          In order to see the tests that are created using Junit annotations, just check the check box “Search for Junit4 annotations” and drop downs would populated accordingly
-          Add the listeners to see the results{Right click on Thread group->Select Add-> Select Listener}
-          Select the test method we want to execute from the “Test Method” drop down and run the test(press Ctrl+R)
-          It will launch the browser and perform the actions as per the test scripts.
-          And finally we can view the results in the listeners. “View result tree in Table” and standard Deviation, Throughput, Mean, Average, Minimum and Maximum time that the samples took to execute could be noted from the “Summary/ Aggregate” reports.

The results are looks like below.........    :)




Saturday, April 12, 2014

Wait for the element Present in Selenium WebDriver(Explicit Wait)



In General , in Slenium Webdriver we have  two types of wait commands are available. implicit wait and explicit wait. 

 implicit wait :
It's global setting applicable for all elements and if element appear before specified time than script will start executing otherwise script will throw NoSuchElementException.  

    Thread.sleep() - It will sleep time for script, not good way to use in script as it's sleep without condition.

driver.manage().timeouts().implicitlyWait(120,TimeUnit.SECONDS)


explicit wait:  Wait for the element to be present

WebDriverWait explicit=new WebDriverWait(driver, 10);   // 10 in secs 

explicit.until(ExpectedConditions.visibilityOfElementLocated(By.id("element id"))).click();

Friday, March 21, 2014

Scroll Bar navigation in Selenium WebDriver

This Script can use  for  Scroll bar navigation in a  page


for (int second = 0;; second++) {
           if(second >=30){
               break;
           }
               ((RemoteWebDriver) Driver.driver).executeScript("window.scrollBy(0,200)", "");
               Thread.sleep(3000);
           }

Selenium WebDriver... Multiple Windows(Child Window and Parent Window)

For Navigating to child window form parent window, can use below command...


String Parent_Window = Driver.driver.getWindowHandle();
  for (String Child_Window : Driver.driver.getWindowHandles()) {

   Driver.driver.switchTo().window(Child_Window);
  }


Wednesday, October 16, 2013

Jmeter Non GUI mode with HTML Reports

Running JMeter in command line mode is an option to carry out high number of concurrent users and obtain results.

STEP 1:
Go to bin folder of your JMeter installation from command prompt and type the following command:


        jmeter -n -t my-Scrtip.jmx -l sample.jtl -j <smaple.log>

Ex: jmeter -n -t D:\sampleScripts\script.jmx -l D:\sampleScripts\scriptresults.jtl

-n ------> Specifies Jmeter is to run in non GUI mode, 

-t ------> name of your test script jmx file (If you want u can Specify jmx file with location)
 -l------> name of jtl  
-j ----->  generate the log file for the execution

STEP 2 :

  after getting the JTL file , use the below command to generate the HTML report

    jmeter -g <sample.jtl> -o <folderpath>


After executing the above command, it will generate the HTML  in the desired path.. You can now view the results.......... :) 

Tuesday, October 8, 2013

Simultaneous & Concurrent Users......

These are the 2 terms which is often used in Performance Testing... 

Simultaneous users are the users who have a valid session in the server. Each of the users would be performing different actions like one doing login , other viewing the reports, etc.


Concurrent users are the users who have a valid session in the server & they are performing the same operation at any point of time. All the concurrent users would perform login, reports download, etc at the same point of time.


Example:
Hence for a web site, the number of simultaneous users would be always greater than the concurrent users. For example; a banking web site has the workload of about 30000 simultaneous users & 5000 concurrent users.

Knowing the correct figures of simultaneous & concurrent users is very vital in order to perform performance testing of an application.

Saturday, October 5, 2013

java.lang.OutOfMemoryError in jmeter......?



A java.lang.OutOfMemoryError is a subclass of java.lang.VirtualMachineError that is thrown when the Java Virtual Machine is broken or has run out of resources that are necessary to continue the operation of the Java Virtual Machine. Obviously, memory is the exhausted resource for a java.lang.OutOfMemoryError, which is thrown when the Java Virtual Machine cannot allocate an object due to memory constraints.


To overcome this issues while Jmeter Execution, increase heap memory of Jmeter, modify the line of code in jmeter.bat file.

Right Click on jmeter.bat file click on Edit 
and modify the line  
orginal :set HEAP=-Xms512m -Xmx512m 
modified : set HEAP=-Xms512m -Xmx1250m (For 32 Bit OS)

for 64 bit OS,the value wil change upto 102400,   

FYI: need to install jre for 64 bit in the system..

90% line in JMeter aggregate report....!


The 90th percentile response time value is the value for which 90% of the data points are smaller and 10% are bigger.

To calculate the 90th percentile value:
1.Sort the transaction instances by their value.
2.Remove the top 10% instances.
3.The highest value left is the 90th percentile.
Consider the below example:

There are 10 instances(response time) of transaction “sampler10” with the values


10Sec,5Sec,3Sec,9Sec,4Sec,3Sec,1Sec,7Sec,2Sec

Sort values from best to worst:

1 sec,2 sec,3 sec,4 sec,5 sec,6 sec,7 sec,8 sec,9 sec,10 sec

Remove top 10%, in our case i.e. value “10 sec”

1 sec,2 sec,3 sec,4 sec,5 sec,6 sec,7 sec,8 sec,9 sec

The highest value left is the 90th percentile value i.e. “9 sec” is the 90th percentile value.

Monday, July 8, 2013

Rendezvous Point In jmeter?



Rendezvous Point: Rendezvous point instruct VUsers to wait during test execution for multiple VUsers to arrive at a certain point, in order that they may simultaneously perform a task.

Rendezvous Point In jmeter:
By Using “Synchronizing Timer” we can overcome this problem.

Ex: We have a Scenario like Login into the Site doing some actions like booking the tickets and Sign-out from the site. So we want hit the Sever with large no.of Users at this Point “Booking the tickets”. We need to add “Synchronizing Timer” before the request. So that it will capture all the users at this point and released that users simultaneously on the Server. 

Process of adding Rendezvous Point in J meter: 

·         Add the Thread group to your Test plan mention Vuser count as”100”.


·         Add HTTP Request – Let’s hit http://www.google.com with 100 users.


·         Synchronizing Timer - Add this timer and enter '25' as the number of virtual users we want to send request to the server simultaneously.

·         View Result Tree - Use this listener to monitor the performance of the application.

·         Aggregate Report - Use this listener to see the overall performance.

        
     NOTE:Number of threads in the Thread Group should always be greater than the 'Number of Simultaneous Users to Group By' to make sure that Jmeter doesn't throw any unhandled exception.