Class WebBrowserVirtualUser

  • All Implemented Interfaces:
    com.facilita.fc.runtime.Commands, DataDictionary, com.facilita.fc.runtime.IMonitoredVU, java.lang.Runnable

    public class WebBrowserVirtualUser
    extends VirtualUser
    Represents a Web Java Virtual User. When a test containing Web Java Virtual Users is run, a WebBrowserVirtualUser object is created by the eggPlant Performance engine for every Virtual User in the test. These WebBrowserVirtualUser objects runs scripts/workflows by creating instances of your script classes (which are subclasses of WebBrowserScript) and calling the script() method on them.

    Each instance of WebBrowserVirtualUser has a separate WebBrowser object that can be used to send HTTP requests to a web server. This has two implications:

    • Each Virtual User has a different cache and WebBrowser settings
    • If a Virtual User is running a workflow containing multiple scripts, then changes to the Virtual User's WebBrowser object in one script will affect the other scripts too

    The WebBrowser object can be accessed from within your script() method using the WebBrowserScript.getWebBrowser() method.

    When developing Web scripts, it is recommended to customise the Web Java Virtual User type, by performing the following actions in eggPlant Performance Studio:

    • Under Workspace/Virtual Users, right-click Web Java Virtual User, and then click New VU Type
    • Type a name (which will be used as the class name) and a description
    • Expand the newly-created custom Virtual User type, and the Source folder
    • Edit the VU source file (the class which extends WebBrowserVirtualUser) by adding methods that can be called from any script which is based on your custom Virtual User, and/or overriding the methods in WebBrowserVirtualUser.
    The other source file created for the custom Virtual User type is a VU Script source file, which is a class that extends WebBrowserScript and will be the base class of any script files you create with the custom Virtual User type.
    See Also:
    WebBrowserScript
    • Constructor Detail

      • WebBrowserVirtualUser

        public WebBrowserVirtualUser()
        For internal use only.
    • Method Detail

      • getWebBrowser

        public WebBrowser getWebBrowser()
        Gets the WebBrowser belonging to this Virtual User.
        Returns:
        the WebBrowser belonging to this Virtual User
      • pre

        protected void pre()
                    throws java.lang.Exception
        Description copied from class: VirtualUser
        This method is called before any scripts are executed.

        Override this method in your custom Virtual User if you have code which should be run only once, before any scripts are executed.

        This method initialises logging systems. If you override this method in a custom Virtual User, then a call to super.pre() must be made and must occur before any code that may cause an exception or write to a log.

        Overrides:
        pre in class VirtualUser
        Throws:
        java.lang.Exception - An error occurred
      • post

        protected void post()
                     throws java.lang.Exception
        Description copied from class: VirtualUser
        This method is called after all scripts have finished executing.

        Override this method in your custom Virtual User if you have code which should be run only once, after all scripts have finished executing.

        This method shuts down logging systems. If you override this method in a custom Virtual User, then a call to super.post() must be made at the end of the method. All exceptions thrown during the execution of this method must be caught and handled.

        Overrides:
        post in class VirtualUser
        Throws:
        java.lang.Exception - An error occurred
      • onStartTransaction

        protected void onStartTransaction​(java.lang.String id,
                                          java.lang.String tag)
                                   throws java.lang.Exception
        Description copied from class: VirtualUser
        This method is called whenever a transaction is started using the VirtualUser.startTransaction(String) or VirtualUser.startTransaction(String, String) methods.

        Override this method in your custom Virtual User if you have code which should be run whenever a transaction is started.

        Overrides:
        onStartTransaction in class VirtualUser
        Parameters:
        id - the transaction identifier
        tag - extra information which appears in the Info column
        Throws:
        java.lang.Exception - An error occurred
      • atStartOfIteration

        protected void atStartOfIteration()
        Description copied from class: VirtualUser
        This method is called at the start of every iteration.

        Override this method in your custom Virtual User if you have code which should be run at the start of every iteration.

        The current iteration number can be obtained using VirtualUser.getCurrentIteration().

        Overrides:
        atStartOfIteration in class VirtualUser
      • onStartInitialSection

        public void onStartInitialSection()
        Description copied from class: VirtualUser
        This method is called whenever the Virtual User is about to start executing the initial sequence of scripts in its workflow.

        Override this method in your custom Virtual User if you have code which should be run whenever the Virtual User starts executing the initial sequence of scripts.

        Overrides:
        onStartInitialSection in class VirtualUser
      • onStartFinalSection

        public void onStartFinalSection()
        Description copied from class: VirtualUser
        This method is called whenever the Virtual User is about to start executing the final sequence of scripts in its workflow.

        Override this method in your custom Virtual User if you have code which should be run whenever the Virtual User starts executing the final sequence of scripts.

        Overrides:
        onStartFinalSection in class VirtualUser
      • attachLogMessageSender

        public void attachLogMessageSender​(com.facilita.fc.runtime.IMessageSender messageSender)
        For internal use only.
        Overrides:
        attachLogMessageSender in class VirtualUser
        Parameters:
        messageSender - the message sender
      • prepareRequest

        public void prepareRequest​(Request request)
        This method is called immediately before a Request object is sent to the web server.

        If Request.send() or Request.sendTopLevel() is called within a script() method, this method will be called before the top-level request is sent to the web server. The request parameter is a reference to the Request object on which send() (or sendTopLevel()) was called. It can be modified prior to sending.

        Override this method to modify every request (or a selection of requests based on criteria) before they are sent to the web server.

        Parameters:
        request - a request that is about to be sent to the web server
        See Also:
        processResponse(Response)
      • processResponse

        public void processResponse​(Response response)
                             throws java.lang.Exception
        This method is called immediately after a Response is returned from the web server.

        If Request.send() or Request.sendTopLevel() is called within a script() method, this method will be called before the Response object is returned. The response parameter is a reference to the Response object which is about to be returned by the send() (or sendTopLevel()) method. It can be modified prior to returning.

        Override this method to modify every response (or a selection of responses based on criteria) after they are returned by the web server.

        Parameters:
        response - the response that has just arrived from the web server
        Throws:
        java.lang.Exception - An error occurred when processing the response
        See Also:
        prepareRequest(Request)
      • getProtocol

        public Protocol getProtocol​(java.lang.String key,
                                    java.lang.String defaultValue)
                             throws NoSuchValueException,
                                    NotAllowedException,
                                    BadValueException
        Gets a Protocol by looking up a String in this Virtual User's data dictionary.

        e.g.

        
         // Look in the data dictionary for the key "protocol1". If this key doesn't exist, then default to Protocol.HTTP
         Protocol protocol1 = getProtocol("protocol1", "http");
         
        Parameters:
        key - the key to look for in the data dictionary
        defaultValue - the default value to use if the specified key does not exist in this Virtual User's data dictionary
        Returns:
        the Protocol, or a Protocol relating to the defaultValue parameter
        Throws:
        NoSuchValueException - Invalid protocol name
        NotAllowedException - The key could not be found in the data dictionary
        BadValueException - The key could not be found in the data dictionary
      • getSoapService

        public <T> T getSoapService​(java.lang.Class<T> soapServiceInterface,
                                    Url url,
                                    com.testplant.soap.SoapVersion soapVersion)
                             throws NoSuchValueException,
                                    java.lang.NoSuchMethodException,
                                    java.lang.SecurityException,
                                    java.lang.InstantiationException,
                                    java.lang.IllegalAccessException,
                                    java.lang.IllegalArgumentException,
                                    java.lang.reflect.InvocationTargetException
        Throws:
        NoSuchValueException
        java.lang.NoSuchMethodException
        java.lang.SecurityException
        java.lang.InstantiationException
        java.lang.IllegalAccessException
        java.lang.IllegalArgumentException
        java.lang.reflect.InvocationTargetException