17 Using the Web Services Module

This chapter provides instructions on using the OpenScript Web Services Module, which supports testing of Web Services.

17.1 About the Web Services Module

The Web Services Module is an application module that supports testing of Web Services. The Web Services Module is an extension to the HTTP Module. The OpenScript Web Services module includes the following features:

  • The Web Services Module. The New Project wizard (select New from the File menu) includes a "Web Services Script" option to use when creating Web Services scripts in OpenScript.

  • Support for SOAP Protocols. The Web Service Module supports the SOAP 1.1 and 1.2 protocols.

  • Support for multiple parsers. The Web Service Module supports the multiple WSDL parsers. In addition to the default OpenScript and Oracle parsers, OpenScript can also be configure to use apache AXIS and .Net parsers.

  • WSDL Manager. The OpenScript WSDL Manager lets you import and store Web Services Definition files for creating Web Services scripts. Using the WSDL Manager, you add Web Services methods to the OpenScript tree.

  • XML Editor. The OpenScript XML Editor lets you edit Web Services requests to include either static values or variables.

  • Web Services-specific Application Programming Interface (API). The Web Services Module includes a Web Services Module API Specification that can be used to customize Web Services scripts.

17.1.1 Key Features of the Web Services Module

The Web Services Module is an extension module to HTTP Module that extends the platform with Web Services testing capabilities. The Web Services Module is fully integrated with the OpenScript platform including the Results view, Details view, Properties view, Console/Problems views, Preferences, Step Groups, Script Manager, and Workspace Manager.

The Web Services methods are added to the Script tree using the WSDL Manager. Web Services method postdata parameters can be edited using the XML Editor features of the Details View.

OpenScript shows the results of Web Services script playback in the Results view. The Results view shows results for each script command (including duration and summary for failures). The Results Report compiles the same information into an HTML Results Report. Results can be exported from the OpenScript GUI in standard format (CSV / HTML). Results are also generated for unattended playback through the command line.

The Web Services Module API includes a "ws" class that provides additional programming functionality.

17.2 Creating Web Services Scripts Using WSDL Manager

Creating Web Services scripts using WSDL Manager involves the following major steps:

  1. Create a Web Services script tree.

  2. Add WSDL files to the WSDL Manager view.

  3. Add methods from the WSDL Manager to the script tree.

  4. Edit method parameters in the Details view.

The following sections explain each of the major steps.

17.2.1 Creating the Web Services Script Tree

To create a Web Services script tree:

  1. Start OpenScript.

  2. Select New from the File menu.

  3. Expand the General group and select Web Services.

  4. Click Next.

  5. Select the Repository and Workspace.

  6. Enter a script name.

  7. Click Finish. A new Script tree is created in the Script View and the WSDL Manager view appears.

17.2.2 Adding WSDL Files to the WSDL Manager View

To add files to the WSDL Manager view:

  1. Click the Add icon in the WSDL Manager view.

  2. Enter the URL to a the WSDL file or click Browse to select a local file.

  3. Select the parser to use and set the Roll over option.

  4. Click Next. The parsed methods appear.

  5. Click Finish to add the parsed methods to the WSDL Manager view.

17.2.3 Adding Methods to the Script Tree

To add WSDL file methods from the WSDL Manager view to the script tree:

  1. Expand the WSDL file tree in the WSDL Manager view.

  2. Right-click the method to add and select Add to script from the shortcut menu. The method will be added to the Run node of the script tree.

    In the Java Code view, a ws.method(method)/ws.endMethod() group with a ws.post() method will be added to the script code, as follows:

    ws.method("findApprovedPatientsByLastName");
    {
      ws.post(2, "http://server:7011/medrec-jaxws-services/PatientFacadeService", 
        "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>
        <soapenv:Envelope 
          xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"
          xmlns:med=\"http://www.oracle.com/medrec\/">\r\n
            <soapenv:Header/>\r\n
              <soapenv:Body>\r\n
                <med:findApprovedPatientsByLastName>\r\n
                 <!--Optional:-->\r\n
                 <arg0>String</arg0>\r\n
                </med:findApprovedPatientsByLastName>\r\n
              </soapenv:Body>\r\n
        </soapenv:Envelope>", null, true, null, null);
    }
    ws.endMethod();
    

17.2.4 Editing Method Parameters in the Details View

To edit WSDL file methods in the Details View:

  1. Expand the Run node in the Script tree view.

  2. Expand the WSDL method node in the Script tree view.

  3. Select an XML post data node in the Script tree view.

  4. Open the Details view and select the XML Tree tab.

  5. Click a value in the right column of the XML Tree tab to edit the value.

    or

    Right-click a parameter in the left column of the XML Tree tab and select Substitute Variable to select a variable name or Databank value to substitute for the parameter value. If you parameterize a value with a Databank, the databank variable appears as {{db.databankFileName.field,recordedValue}} in the SOAP parameters. For example, the optional argument <arg0> in the above postdata example would appear as <arg0>{{db.customer.LastName,String}}</arg0>\r\n.

    The XML source in the XML tab is not decoded by default. Right-click the XML source in the XML tab and select Format to format the contents. When you format the xml contents, the inner text of an element will be decoded. The following is an example of the inner text of an element before formatting:

    <soapenv name="google&quot;">google&quot;</soapenv>
    

    The following is an example of the inner text of an element after formatting:

    <soapenv name="google&quot;">google"</soapenv>
    

17.3 Modifying Scripts

Once a script has been created/recorded, you can make modifications to customize the script for your specific testing needs.

17.3.1 Adding a Web Services Post Navigation

To add a Web Services Post Navigation to a script:

  1. Create a Web Services script.

  2. Select the Run node.

  3. Select the Script menu and then select Other from the Add sub menu.

  4. Expand the HTTP node.

  5. Select the Web Services Post Navigation node from the Web Services group and click OK.

  6. On the Base URL tab, enter the URL, request and response charsets, and set the Encode strings option.

  7. On the Post Data tab, enter the SOAP protocol postdata XML.

  8. On the Headers tab, use the Add button to add name/value pairs and actions to the Base URL.

  9. Click OK to add the Web Services Post Navigation node to the script tree.

    In the Java Code view, the Web Services Post Navigation consists of the code executed in the ws.Post method (line breaks and spacing added for clarity):

    ws.post(2, "http://testserver2/EmployeeLookup/EmployeeLookup.asmx",
      "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n\r\n
        <soapenv:Envelope 
           xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" 
           xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 
           xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" 
           xmlns:web=\"http://oracle.com/webservices\"> \r\n
         <soapenv:Header/> \r\n
           <soapenv:Body> \r\n
             <web:findEmployee soapenv:
               encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"> \r\n
               <criteria xmlns:enc=\"http://oracle.com/webservices/encodedTypes\"
                 xsi:type=\"enc:SearchCriteria\"> \r\n
                 <FirstName xsi:type=\"xsd:string\">string</FirstName> \r\n
                 <LastName xsi:type=\"xsd:string\">string</LastName> \r\n
                 <EmployeeID xsi:type=\"xsd:int\">3</EmployeeID> \r\n
               </criteria> \r\n
             </web:findEmployee> \r\n
           </soapenv:Body> \r\n
        </soapenv:Envelope>",
      http.headers(http.header("Content-Type", "text/xml", 
        Header.HeaderAction.Modify),
        http.header("SOAPAction","\"http://oracle.com/webservices/findEmployee\"",
          Header.HeaderAction.Add)),
      false, "UTF-8", "UTF-8");
    

17.3.2 Adding a Text Matching Test

You can use Text Matching Tests to report an error and/or abort the script if a request does not match the Text Matching Test criteria.

To add a Text Matching Test to a Web Services script:

  1. Create a Web Services script.

  2. Expand the Run node.

  3. Select the Web Services postdata node where you want to add the Text Matching test.

  4. Select the Script menu and then select Other from the Add menu.

  5. Select Text Matching Test from the Validation group.

  6. Enter a name for the test.

  7. Enter the Text to Match.

  8. Enter any error message text to log if the test fails.

  9. Select the source location to look for the text to match: HTML or Response Header.

  10. Select the Pass when setting.

    Selected text is present: the test case passes if the Text to Match string is found in the selected source.

    Selected text is absent: the test case passes if the Text to Match string is not found in the selected source.

  11. Select the Regular Expression option if the Text to Match is a Regular Expression. Clear the Regular Expression option if the Text to Match is plain text.

  12. Click OK to add the Text Matching Test node to the script tree.

    In the Java Code view, the Text Matching Test consists of the code executed in the http.match method (line breaks and spacing added for clarity):

    http.match("Test name", "Text to Match", "Error Message", 
          Source location = Source.Html | Source.ResponseHeader, 
          pass when present = false | pass when absent = true, 
          is not RegExp = false | is RegExp = true);
    

    Example:

    http.match("MyTXTMatch", "Login", "Could not find login", Source.Html, false, false);
    

Set the default Error recovery setting for the HTTP Text Matching test in the OpenScript playback preferences.

17.3.3 Adding Security Extensions

You can add security extensions to Web Services scripts.

To add security extensions to a Web Services script:

  1. Create a Web Services script.

  2. Expand the Run node.

  3. Select the Web Services method node where you want to add the security and attachments.

  4. Select the Script menu and then select Other from the Add menu.

  5. Expand the HTTP node.

  6. Select Web Services Security Attachments from the Web Services group and click OK.

  7. If necessary click the WS-Security tab.

  8. Enter a URL. If you selected a Web Services navigation node in the script tree, the URL will be automatically entered.

  9. Select User Username Token

  10. Enter the user name and password.

    Username: specifies the user name to use for the Username Token in the XML request.

    Password: specifies the password to use for the Username Token in the XML request.

    Confirm Password: confirms the password.

  11. Select the password type: Password Text or Password Digest.

    Password Text: when selected, the password in the XML request is included as plain text. The URI attribute for the <wsse:Password> element is set to #PasswordText.

    Password Digest: when selected, the password is encrypted. The URI attribute for the <wsse:Password> element is set to #PasswordDigest.

  12. Select or clear the Add Created Header, Add Nonce and Add Timestamp options.

    Add Created Header: when selected, a creation timestamp is included in the Username Token of the XML request for use in setting the server cache limit of used nonces.

    Add Nonce: when selected, a cryptographically random nonce value is included in the Username Token of the XML request to provide a countermeasure for replay attacks.

    Add Timestamp: when selected, a timestamp value is included in the Web Services security element of the XML request. The timestamp includes both Created and Expires elements. Specify the Valid For number of seconds.

  13. Click OK to add the Security Attachment node to the script tree.

    In the Java Code view, the Security Attachment consists of the code executed in the ws.addSecurityAttachments method (line breaks and spacing added for clarity), as follows:

    ws.addSecurityAttachments("url",
      ws.security("userName", deobfuscate("password"),addCreatedHeader, 
        addNonce, addTimestamp, validFor), null);
    

    If you add security and file attachments together, the ws.addSecurityAttachments method includes both the ws.security and ws.attachments methods (line breaks and spacing added for clarity), as follows:

    ws.addSecurityAttachments("url",
       ws.security("userName", deobfuscate("password"),true, true, true, 10),
       ws.attachments(AttachmentMechanism.transferType,
         ws.attachment("filename","attachmentPart")));
    

17.3.4 Adding Attachments

You can add file attachments to Web Services scripts.

To add file attachments to a Web Services script:

  1. Create a Web Services script.

  2. Expand the Run node.

  3. Select the Web Services method node where you want to add the security and attachments.

  4. Select the Script menu and then select Other from the Add menu.

  5. Select Web Services Security Attachments from the Web Services group.

  6. If necessary click the WS-Security tab.

  7. Enter a URL. If you selected a Web Services navigation node in the script tree, the URL will be automatically entered.

  8. Click the Attachments tab.

  9. Select the Transfer Type.

    • DEFAULT - uses the default transfer type specified by the Content-Type header.

    • SWA - Security SOAP Messages with Attachments

    • MTOM - SOAP Message Transmission Optimization Mechanism

    • DIME - Direct Internet Message Encapsulation

  10. Click Add.

  11. Enter the path and file name or click Browse to select a file.

  12. If the Web Services method includes any Attachment Part object identifiers, select an Attachment Part from the list. If the Web Services method does not include any Attachment Part object identifiers, the list will be empty.

  13. Click OK to add the Security Attachment node to the script tree.

    In the Java Code view, the Security Attachment consists of the code executed in the ws.addSecurityAttachments method (line breaks and spacing added for clarity) as follows:

    ws.addSecurityAttachments("url", null, 
       ws.attachments(AttachmentMechanism.transferType, 
         ws.attachment("filename","attachmentPart")));
    

    If you add security and file attachments together, the ws.addSecurityAttachments method includes both the ws.security and ws.attachments methods (line breaks and spacing added for clarity), as follows:

    ws.addSecurityAttachments("url", 
       ws.security("userName", deobfuscate("password"),true, true, true, 10), 
       ws.attachments(AttachmentMechanism.transferType, 
         ws.attachment("filename","attachmentPart")));
    

    The following example Web Services script method shows the ws.addSecurityAttachments method with a ws.post postdata method used to upload a file. The ws.post method specifies the SOAP Envelope postdata, Content-Type, and SOAP Action.

    ws.method("upload");
    {
      ws.addSecurityAttachments("http://myurl.com:8080/services/MTOMService",
        ws.security("username", deobfuscate("5blNah5kX/XuZnepYwInFw=="), 
          true, true, true, 20), 
        ws.attachments(AttachmentMechanism.MTOM, 
          ws.attachment("C:\\OracleATS\\OFT\\test.txt", "<upload>776598931581")));
    
      ws.post(15, "http://myurl.com:8080/services/MTOMService",
        "<soapenv:Envelope 
            xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" 
            xmlns:ser=\"http://service.interop.mtom.sample\">\r\n
          <soapenv:Header/>\r\n
          <soapenv:Body>\r\n
            <ser:upload>\r\n
              <!--Optional:-->\r\n
              <ser:fileName>string</ser:fileName>\r\n
              <!--Optional:-->\r\n
              <ser:contents>cid:776598931581</ser:contents>\r\n
            </ser:upload>\r\n
          </soapenv:Body>\r\n
        </soapenv:Envelope>",
        http.headers(http.header("Content-Type", "text/xml;charset=UTF-8",
            Header.HeaderAction.Modify), 
          http.header("SOAPAction", "\"urn:upload\"",
            Header.HeaderAction.Modify)), 
        true, null, null);
    }
    ws.endMethod();
    

17.3.5 Web Services Module API

The Web Services Module includes a script Application Programming Interface (API) specific to Web Services testing. The Web Services script creates the Java code that corresponds to the Tree View and displays the Web Services commands in the Java Code view using easy-to-understand function names. The Java Code view commands correspond to the Tree View and you can edit your scripts in either view.

You can use the Web Services API to enhance scripts with additional testing functionality. Commands that are specific to the Web Services Module are part of the "ws" class. Additional functional test methods are available in the "http" class. You can also leverage other commands from other enabled classes (services) or general Java commands in your scripts.

Many API methods can be added using the Web Services Test Module Tree View. Additional methods can be added using the Java Code view. Use Ctrl-space in the Java Code view to open an Intellisense window listing available procedures. See the API Reference in the OpenScript help for additional programming information.

17.4 Recording Web Services Scripts

If you have a Web Services client application written already that communicates over HTTP and which communicates through a proxy, you can record the traffic using thee OpenScript HTTP recorder.

17.4.1 Setting Web Services Record Preferences

To set Web Srvices record preferences:

  1. Start OpenScript.

  2. Select OpenScript Preferences from the View menu.

  3. Expand the OpenScript node and the Record category.

  4. Select Web Services.

  5. Click the tabs and set the preferences.

  6. Click OK.

17.4.2 Recording Web Services Scripts

To record Web Services script:

  1. Start OpenScript.

  2. Set the Web Services Recording preferences.

  3. Select New from the File menu.

  4. Expand the General group and select Web Services.

  5. Click Next.

  6. Select the Repository and Workspace.

  7. Enter a script name.

  8. Click Finish. A new Script tree is created in the Script View and the WSDL Manager view appears.

  9. Select Record from the Script menu. The browser automatically opens when you start recording.

  10. Load the web page where you want to start recording into the browser.

  11. Navigate the web site to record navigations. The navigations will be added to the node of the script tree specified by the Set Record Section setting (the Run node is the default).

  12. When finished navigating pages, close the browser.

  13. Select Stop from the Script menu or click the Stop button on the OpenScript toolbar.

  14. Expand the Run node of the script to view the page navigation nodes in the script tree.

    You can customize the script using the menu options or the Code View for specific testing requirements.

    Note: Do not close the script editor view or script project while recording or playing back scripts. Doing so could result in unpredictable behavior in the OpenScript application.