Friday, April 22, 2011

Open Script : Display Open Script Settings at Runtime

 public void run() throws Exception {
        // Displays the Details in the the result file under Comments Section
        info(getSettings().toString());
       // Prints to the console
        System.out.println(getSettings().toString());
        System.out.println(getSettings().getProperties().size());
       
}
_________________________________________________________________________
// To Display the Same Using Custom java Code :


import java.util.Enumeration;
import java.util.Hashtable;

import oracle.oats.scripting.modules.basic.api.*;
import oracle.oats.scripting.modules.browser.api.*;
import oracle.oats.scripting.modules.functionalTest.api.*;
import oracle.oats.scripting.modules.utilities.api.*;
import oracle.oats.scripting.modules.utilities.api.sql.*;
import oracle.oats.scripting.modules.utilities.api.xml.*;
import oracle.oats.scripting.modules.utilities.api.file.*;
import oracle.oats.scripting.modules.webdom.api.*;
import oracle.oats.scripting.modules.formsFT.api.*;
import oracle.oats.utilities.CaseInsensitiveProperties;

public class script extends IteratingVUserScript {
    @ScriptService oracle.oats.scripting.modules.utilities.api.UtilitiesService utilities;
    @ScriptService oracle.oats.scripting.modules.browser.api.BrowserService browser;
    @ScriptService oracle.oats.scripting.modules.functionalTest.api.FunctionalTestService ft;
    @ScriptService oracle.oats.scripting.modules.webdom.api.WebDomService web;
    @ScriptService oracle.oats.scripting.modules.formsFT.api.FormsService forms;

    public void initialize() throws Exception {
    }

    /**
     * Add code to be executed each iteration for this virtual user.
     */
    public void run() throws Exception {
        /*
         * Step 1 : get the Settings object
         * 2: get the keys
         * 3: get the value of key
         */
        //Step 1 : Get the Settings Object
        CaseInsensitiveProperties cip=getSettings().getProperties();
        // CaseInsensitiveProperties is a subclass of Properties Class
        // HashTable > Properties > CaseInsensitiveProperties
        // 2 - Get the keys
        // Returns Enumeration Object
        Enumeration enum_keys=cip.keys();
        //
        // Displays the type of Enumeration - java.util.HashTable$Enumerator@1202a06
        // Enumeration is of type Hashtable
        System.out.println("Object Type is : "+enum_keys.toString());
       
       
       
        //Iteration through the Enumeration Set
        // Use the hasMoreElements method to verify the last element
        // User nextElement - to retrieve the Object
        Object v_key;
        Object v_val;
       
        while(enum_keys.hasMoreElements())
        {
            v_key=enum_keys.nextElement();           
           
            // cip.get(Object key) - operates on a Hashtable and Returns an Object
            v_val=cip.get(v_key);           
            System.out.println("Key : "+v_key.toString()+"\tValue : "+v_val);
        }
       
// Displays 230 - Values on my system.
        System.out.println("Size is : "+cip.size());       
       
    }

    public void finish() throws Exception {
    }
}

Sample Output:

Object Type is : java.util.Hashtable$Enumerator@135b92e
Key : file.encoding.pkg    Value : sun.io
Key : http.usedeflate    Value : false
Key : org.osgi.framework.executionenvironment    Value : OSGi/Minimum-1.0,OSGi/Minimum-1.1,JRE-1.1,J2SE-1.2,J2SE-1.3,J2SE-1.4,J2SE-1.5,JavaSE-1.6
Key : ft.smartmatch    Value : true
Key : osgi.framework    Value : file:/D:/OracleATS9.2/openScript/plugins/org.eclipse.osgi_3.4.2.R34x_v20080826-1230.jar
Key : vmargs    Value :
Key : http.usegzip    Value : true
...( Total 230 Key Value Pairs were displayed on my system )
...
...
...
...
...
Key : java.specification.version    Value : 1.6
Key : err.http.node_not_found_exception    Value : Warn
Key : encryption_properties_file    Value : C:\Documents and Settings\amoni.APPLICATIONS\osworkspace\.metadata\.plugins\oracle.oats.scripting.utilities\encryption.properties
Key : sun.arch.data.model    Value : 32
Size is : 230
Size is : true

No comments:

Post a Comment