Automated test case generation tool for WSO2 products-GSOC

  1. Introduction

  2. org.wso2.carbon.automation.tools is the component for the WSO2 Test automation framewrok. It let developed and specially for non-technical people to test the WSO2 Carbon based product. It used the natural language instead java or other Programming language.

  3. Project Architecture

  4.  

    Component Diagram

    Main Library

    • Main Library is responsible to provide the frequently use functions to the test cases. This component is contain the libraries that can be used in test cases. In the this Library it provide Authentication, axis client as libraries.
    • Also it provides the libraries that can be used to assert the expected outcomes and Object creating libraries.

    Properties

    • It provide the configuration data to the Libraries. Configurations are store in in the context.xml file.

    Library Generator

    • Library generator is responsible to generate Client libraries. libraries need to be generated should be include in the service.xml file based on the stub information.
    • It use service.xml and extract the stub information to retrieve the service operation and service related information from the related WSDL file.
    • Generator use the predefined template to generate the libraries. For that template is defined using java String Template[1] group file.

    Robot Library

  5. How to install tool

    • Download the latest version of the tool from Git hub https://github.com/ruks/org.wso2.carbon.automation.tools
    • Before you build the tool you have to install maven dependencies.
    • Simply go to the tool directory and run sh mvn-setup.sh on Linux or mvn-setup.bat on windows.
    • Next in the tool root directory run mvn clean install
    • After the successful build tool will install to the local maven repository.
  6. Create integration test module

  7. Test module structure is as below and should define configuration files as below.

     

                  
    module
        src
            java
                resources
                	automation.xml
                	log.properties
                	service.xml
                	templateR.stg
            test
                main
                resources
                    robotframework
                        libraries
                        tests
        pom.xml
    
    

    pom.xml

    Define the parent integrate test module pom file
    • Identify the parent pom file and add the parent definition and project definition as follow

     

                  
    <parent>
    	<groupId>org.wso2.appserver</groupId>
    	<artifactId>integration-appSever</artifactId>
    	<version>5.3.0-SNAPSHOT</version>
    	<relativePath>../../pom.xml</relativePath>
    </parent>
              
    <modelVersion>4.0.0</modelVersion>
    <groupId>Auto-TAF-Sample-Robot-Test-AS</groupId>
    <artifactId>Auto-TAF-Sample-Robot-Test-AS</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>WSO2 Carbon - Robot  test module for AS</name>
    <url>http://wso2.org</url>

    Define the robot maven plugin
    • Then define the robot maven plugin as below
                            
    <plugin>
    	<groupId>com.googlecode.robotframework-maven-plugin</groupId>
    	<artifactId>robotframework-maven-plugin</artifactId>
    	<version>1.1.2</version>

    <executions> <execution> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin>

    Add the dependency tool
    • Next you have to add the  tool as dependency.
    • After you build the tool, find the correct dependency details like version.
    • Then add the definition as follow.
                            
    <dependency>
    	<groupId>org.wso2.carbon.automation</groupId>
    	<artifactId>org.wso2.carbon.automation.tools</artifactId>
    	<version>1.0.0</version>
    </dependency>

     

    Example pom file is here.

    Automation.xml

    • It contain the server configuration details.
                  
    <automation>
        <robotconfig>
            <project>
    	        <location>~/Desktop/product-esb/modules/integration/tests-integration
                        /Sample-Robot-Test  </location>
            </project>
            
            <product>
    	        <location>~/wso2esb-4.8.1</location>
        	    <host>localhost</host>
            	<port>9443</port>
            </product>
            
            <server>
    	        <axis2>http://localhost:9763/services</axis2>
            </server>
        </robotconfig>
    </automation>

    • example Automation.xml for AS is here.

    log.properties

    • Define the logger properties.

    service.xml

    • It contain the details of the wso2 carbon admin services.
    • But it not required unless use add new admin services.
    • It contain the service elements with format
    •               
                  <service  stub=”” name=”” wsdl=”” lib=”” />
                  
    • Also you can get the latest service.xml file from here.

    templateR.stg

    • It the template file to generate Library for admin services.
    • It is not required unless you generate libraries.
    • Also you can get the latest templateR.stg file from here.
  8. How to add test cases

  9.  

    • Test cases are written in natural language and it should be .txt files (tested only on .txt).
    • All the .txt text cases are should be inside the  “test/main/resources/robotframwork/libraries/tests”.
    • Test cases related libraries should be kept inside “test/main/resources/robotframework/libraries” folder.
    • “taflibrary.txt” is default library for every test case written in this tool.
    • Latest taflibrary.txt is available on this link.
    • It should be kept inside the library folder.

    Format and structure of the robot script

    • Robot script is written in natural language and it should be standard text(.txt) file. Test script have several region to provide space to specify keyword and write testing keyword. most common region are as below,

    *** Settings ***

    1. setting region is used to import libraries into the robot script. there is two keyword that can used to import libraries.
    2. using Library keyword
      • can import library by specifying library name
      • Library should be inside the test/main/resources/robotframework/libraries Directory
      • ex:  Library      Selenium2Library
    3. using Resource keyword
      • can import resources into the test scripts.
      • Resources could be any test script file, Libraries or keyword libraries
      • ex:  Resource taflibrary.txt

    *** Variables ***

    • In this region users can define the variables
    • variable declaration format is as ${variable-name}=[tab]value
    • ex:  ${brower}=           firefox
    • Any way variable can be declare at any point of the script

    *** Test Cases ***

    • In this region where implement test cases
    • Use keywords, Variables to implement test cases

    *** Keywords ***

    • Use this region to define custom Keywords
    • Can use existing keywords and external libraries keywords

    How to write test cases

    • Create a .txt file inside the testes folder
    • Before you start the test cases you have to import default library first as “Resource  taflibrary.txt”.
    • Then you can define the test method.
    • Just after the test method name define the your command
    • Note that command should start after the tab space.

    How to run the test cases.

    • Start the testing product (ex. ESB, AS)
    • Go to the project root from the terminal
    • Then type the mvn clean install

    Result of the test run

    • Tool generate the related report inside the target folder of project root directory. inside the target/robotframework directory contain the test related report.
  10. Extending the library

  11. Generate service stub based libraries

    • update the service.xml with required details of the service.
    • Then run the ClientGenerator class by providing the package name as parameter.
    • There is two ways you can generate Libraries
      1. Generate Libraries and build the tool
        • generate the libraries and build the tool with the new libraries
      2. Generate libraries after tool build
        • you can generate libraries and use them even after you build the tool. generate the libraries inside the test module and import them into test script.
    • Use the generate.sh to generare libraries on Linux and generate.bat on windows
      1. run generate.sh [packagename] ex: generate.sh sample.lib
      2. for the help run generate.sh -help
    • Using maven exec plugin to generate the Libraries
    •               
      run mvn exec:java  -Dexec.mainClass="client.genration.ServiceStubClientGeneratorr"  -Dexec.args="package_name"                        
                              

    Define you own Library

    • If you need to define your own library, You can use define it using java classes.
    • Create java class inside /java/src/main/Example.java.
    • Import them into the test case as below
    • Ex: Library  Example

    Define your own keyword library

    • Create .txt file inside library.
    • At the top define the region as keyword by ***keyword*** tag
    • Then define the keyword name
    • Then define the list of existing command
    • Then import it to the test cases at the top.
    • ex:  resources             mykeywordslibrary
    • Example keyword library file is here

    Using 3rd party libraries

    • You can use the 3rd party library with this tool.
    • Download the library file and place inside the library folder.
    • Then import them into the test file
    • Extra text file is import to the test file at beginning of the follow as below
    • ex: Library  SeleniumLibrary
  12. references

  13.  

    [1]T. Parr, “Introduction - StringTemplate 4 - Confluence,” Introduction - StringTemplate 4 - Confluence, 06-Aug-2012. [Online]. Available: https://theantlrguy.atlassian.net/wiki/display/ST4/Introduction. [Accessed: 20-Aug-2014].

    “Robot Framework User Guide,” Robot Framework User Guide, 17-Jun-2014. [Online]. Available: http://robotframework.googlecode.com/hg/doc/userguide/RobotFrameworkUserGuide.html?r=2.8.5. [Accessed: 21-Aug-2014].