Service Virtualization

Expand all | Collapse all

Custom Test Step for Build XML dynamically based on the input tag

  • 1.  Custom Test Step for Build XML dynamically based on the input tag

    Posted Aug 17, 2017 09:54 AM

    Hi All,

     

    I am trying to create request XML based on the inputs given (Excel data sheet ) to each tags dynamically, for that I have written code using Execute Script JSR 223 but the performance is very slow sometimes application going to Not Responding , since the code has multiple loops and conditions. So am trying for alternate approach.

     

    I hope creating separate test step would help me. Kindly help in creating new test step.

     

    Share me if any similar code is available I will try to modify for my requirement.

     

    Thanks in Advance.

     

    Thanks

    Ram

    ram2010mech@gmail.com



  • 2.  Re: Custom Test Step for Build XML dynamically based on the input tag

    Posted Aug 17, 2017 12:03 PM

    You can use property to provide value in XML request. I am not sure why you need to code for that.

    Can you share the test case?



  • 3.  Re: Custom Test Step for Build XML dynamically based on the input tag

    Posted Aug 17, 2017 02:21 PM

    Thanks Monika for the reply. Actually my test is to check the behaviour of a system when it gets Request from multiple interfaces . All interface system sends the request to perform the same action but the XML body may varies from system to system . Also number of repetitive tags are based on the inputs given. For some system some tags are mandatory some are optional like wise for others. Accommodation of all these in standard xml Request template does not work.

    hence I need to write a script to pass the tags in xml with data based on the sending system.

     

    please help me on this.

     

    thanks

    Ram



  • 4.  Re: Custom Test Step for Build XML dynamically based on the input tag

    Posted Aug 17, 2017 04:18 PM

    Hi Ram,

     

    Can you clarify whether you are trying to build a test case or are you trying to build a virtual service? 

     

    Secondly, I take it your XML payload will have N repeated elements which needs to be dynamic and have dynamic values. We have support for this type of use case in Service Virtualization, but I don't think it's available in Application Test, hence why I'm asking whether you are trying to build a test case vs virtual service.

     

    However, depending on how dynamic your XML payload needs to be, this can potentially still be solved with a bit of scripting.

     

    Can you provide some example payloads so I can see how much they will vary. You can change the element names and values, I'm more interested in the structure of the payload and the variations of the structure.



  • 5.  Re: Custom Test Step for Build XML dynamically based on the input tag

    Posted Aug 18, 2017 10:04 AM

    Hi William,

    Apologies couldn’t make prompt reply.

    Am trying this for Application Test (Service Testing), here I have attached the sample XMLs. In the attached XML I have not provided all the tags there are more than 150 tags in each xml but I have given few tags and how the tags vary between applications. Kindly check and suggest how I can overcome this.

    Currently I have given the tag name as header in excel for each application and the code will check form where the request is being sent based on that the sheet name and with tag will be chosen and data will be taken from excel sheet.

    Also based on the number of inputs given tags will get added under each element nodes (repetitive nodes)

     

    Thanks

    Ram

    Attachment(s)



  • 6.  Re: Custom Test Step for Build XML dynamically based on the input tag

    Posted Aug 18, 2017 01:32 PM

    Ram,

     

    In your example, is the challenge here that "AddressInformation"/"CustomerAddressInformation" repeats itself multiple times? What values are you storing in Excel and how are you storing the repeating elements? Are they all stored in separate rows? And are all values in the XML you provided stored in Excel?

     

    Given the nature of your testing requirements, I think scripting, using loops and conditions, is the only way, there isn't a built-in function for this. 

     

    Have you tried creating a Java extension with the code you have written? It may perform better if the code is compiled into a Java extension as opposed to the inlined script you've written.



  • 7.  Re: Custom Test Step for Build XML dynamically based on the input tag
    Best Answer

    Posted Aug 18, 2017 03:13 PM

    Ram,

     

    I just noticed you already suggested the idea of creating a test step to do this. There's a document for this called DevTest_SDK_ENU_<version>.pdf. In this document you'll want to look for instructions on how to create a custom step in Chapter 6: Extending Test Steps. It's pretty straight forward. You'll need to extend one of the base classes and add your code into a few of the methods.



  • 8.  Re: Custom Test Step for Build XML dynamically based on the input tag

    Posted Aug 19, 2017 02:00 PM

    HI William,

     

    can you please share me the document - ram2010mech@gmail.com

     

    Thanks

    Ram



  • 9.  Re: Custom Test Step for Build XML dynamically based on the input tag

    Posted Aug 20, 2017 03:23 PM

    Ram,

     

    The PDF document is rather large to be sent over e-mail.

     

    To obtain the document do the following:

    1. Log into support.ca.com

    2. Navigate to Menu > Documentation

    3. Type in DevTest and select the version you have installed

    4. Click SDK (under Using category)

     

    This link should hopefully take you there directly: Using the SDK - DevTest Solutions - 10.1 - CA Technologies Documentation 

    Note the above link is for 10.1. You can modify the URL to look for version 10.0 etc.

    On this page look for "examples.zip" download, which has various sample implementations for reference.

     

    Also, the document I referred to in an earlier post is for older versions of DevTest, namely 8.0. You can also find this exact copy I mentioned by logging into support.ca.com > Menu > Documentation, followed by clicking on the "Go to Bookshelves and PDFs to find documentation for previous releases: Bookshelves and PDFs for Previous Releases - Bookshelves and PDFs - CA Technologies Documentation 

     

    Type in CA DevTest Solutions and hit Enter. Select the appropriate language edition and there will be a list of PDFs to download, such as "Using the SDK".

     

    Lastly, you can also access the Java docs for DevTest SDK by going to your <DevTest HOME>\doc and extracting the SDKJavaDoc.zip



  • 10.  Re: Custom Test Step for Build XML dynamically based on the input tag

    Posted Aug 24, 2017 08:27 AM

    How about saving all templates in separate files and reading them on  the run time and populating the data. if you have repeated nodes, you can put them in separate file as well and read them in a loop based on the repeated data.



  • 11.  Re: Custom Test Step for Build XML dynamically based on the input tag

    Posted Aug 28, 2017 07:52 AM

    Thanks Abhinav for the suggestion, we have more than 500 test scenarios to be tested with various combination of input tags so maintaining template for each scenarios seem difficult and also need to write code to handle 500 templates.

     

    Thanks

    Ram



  • 12.  Re: Custom Test Step for Build XML dynamically based on the input tag

    Posted Aug 28, 2017 07:55 AM

    Hi All, 

     

    I need to pass the current execution row number in the below code as a parameter, kindly help me how to include that in my code. Note sure under which class file and which method. Please help me on this.

     

    Thanks in advance.

     

    package lisa;
    import java.util.Map;
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    import org.w3c.dom.Element;
    import com.itko.lisa.test.CustJavaNodeInterface;
    import com.itko.lisa.test.TestCase;
    import com.itko.lisa.test.TestDefException;
    import com.itko.lisa.test.TestExec;
    import com.itko.lisa.test.TestRunException;
    import com.itko.util.ParameterList;

    public class UpdateXML implements CustJavaNodeInterface {

    /**
    *
    */
    private static final long serialVersionUID = -8327096151988468063L;


    static protected Log cat = LogFactory.getLog( "lisa.UpdateXML" );

    @Override
    public Object executeNodeLogic(TestExec ts, Map params)
    throws TestRunException {
    // TODO Auto-generated method stub
    BuildXMLDynamically ac = new BuildXMLDynamically();
    ts.log( "We got called with: " + params.toString() );
    String excel = (String)params.get("ExcelPath");
    String sheet = (String)params.get("Sheet");
    String RequestXML = (String)params.get("RequestXML");
    String tag = (String)params.get("tagName");
    String xml = ac.xml(excel,sheet,RequestXML);
    return xml;
    }

    @Override
    public ParameterList getParameters() {
    // TODO Auto-generated method stub
    ParameterList pl = new ParameterList( "ExcelPath=&Sheet=&RequestXML=&tagName" );
    return pl;
    }

    @Override
    public void initialize(TestCase arg0, Element arg1) throws TestDefException {
    // TODO Auto-generated method stub
    cat.debug( "called initialize" );

    }

    }

     

    Thanks

    Ram 

    ram2010mech@gmail.com