Class AbstractHtmlPageAction

  • Direct Known Subclasses:
    AbstractHtmlUnitScriptAction

    public abstract class AbstractHtmlPageAction
    extends AbstractWebAction
    AbstractHtmlPageAction is the base class for all HTML-based actions. In contrast to AbstractLightWeightPageAction, the loaded page is parsed and stored internally as a tree of elements. This makes it easy to locate and query/manipulate a certain page element.

    In case JavaScript processing is enabled, the loaded pages might start JS background jobs (via window.setTimeout() and window.setInterval()). In order to wait for these jobs to finish, an optional waiting time can be specified for each of the page loading methods. The framework will not return from these methods unless either all background jobs are finished or the specified waiting time is exceeded. Note that in the latter case any pending (i.e. scheduled, but not running yet) background job is removed, while any running job is left running. If no waiting time is specified, a default waiting time is read from the configuration.

    Note that if the specified waiting time is negative, the framework will not wait for any job to finish, nor will it cancel pending jobs.

    See Also:
    AbstractLightWeightPageAction
    • Constructor Detail

      • AbstractHtmlPageAction

        protected AbstractHtmlPageAction​(AbstractWebAction previousAction,
                                         java.lang.String timerName)
        Creates a new AbstractHtmlPageAction object and gives it the passed timer name. This constructor is typically used for an intermediate action in a sequence of actions, i.e. it has a previous action.
        Parameters:
        previousAction - the action that preceded the current action
        timerName - the name of the timer that is associated with this action
      • AbstractHtmlPageAction

        protected AbstractHtmlPageAction​(java.lang.String timerName)
        Creates a new AbstractHtmlPageAction object and gives it the passed timer name. This constructor is typically used for the first action in a sequence of actions, i.e. it has no previous action.
        Parameters:
        timerName - the name of the timer that is associated with this action
    • Method Detail

      • getHtmlPage

        public HtmlPage getHtmlPage()
        Returns the parsed HTML page object generated by this action.
        Returns:
        the page
      • getPreviousAction

        public AbstractHtmlPageAction getPreviousAction()
        Returns the action that was passed as the previous action to the constructor. Allows access to data collected during the previous action.
        Overrides:
        getPreviousAction in class AbstractWebAction
        Returns:
        the previous action (may be null)
      • run

        public void run()
                 throws java.lang.Throwable
        The run method must restore the state in case we constructed another action in between to prevalidate conditions.
        Overrides:
        run in class AbstractWebAction
        Throws:
        java.lang.Throwable - if an error occurred while running the action
      • setHtmlPage

        public void setHtmlPage​(HtmlPage htmlPage)
        Sets the given HTML page object to be the result of this action. Typically, the HTML page is generated by one of the loadPage...() methods and need not be set explicitly.
        Parameters:
        htmlPage - the page to set
      • setHtmlPage

        public void setHtmlPage​(HtmlPage htmlPage,
                                long waitingTime)
        Sets the given HTML page object to be the result of this action and waits for background task to be finished. Typically, the HTML page is generated by one of the loadPage...() methods and need not be set explicitly.
        Parameters:
        htmlPage - the page to set
        waitingTime - Waiting time for all background tasks on the page to be finished
      • loadPage

        protected void loadPage​(java.net.URL url,
                                HttpMethod method,
                                java.util.List<NameValuePair> requestParameters,
                                long waitingTime)
                         throws java.lang.Exception
        Loads the page using the given request method from the passed URL. The specified request parameters are added either to the request body if the request method is HttpMethod.POST or appended to the query string of the target URL for any other request method.
        Parameters:
        url - the target URL
        method - the HTTP request method to be used
        requestParameters - the list of custom parameters to add
        waitingTime - Waiting time for all background tasks on the page to be finished
        Throws:
        java.lang.Exception - if an error occurred while loading the page
      • loadPage

        protected void loadPage​(java.net.URL url,
                                HttpMethod method,
                                java.util.List<NameValuePair> requestParameters)
                         throws java.lang.Exception
        Loads the page using the given request method from the passed URL. The specified request parameters are added either to the request body if the request method is HttpMethod.POST or appended to the query string of the target URL for any other request method.
        Parameters:
        url - the target URL
        method - the HTTP request method to be used
        requestParameters - the list of custom parameters to add
        Throws:
        java.lang.Exception - if an error occurred while loading the page
      • loadPage

        protected void loadPage​(java.net.URL url,
                                long waitingTime)
                         throws java.lang.Exception
        Loads the page using HTTP GET from the passed URL and waits for background task to be finished.
        Parameters:
        url - the target URL
        waitingTime - Waiting time for all background tasks on the page to be finished
        Throws:
        java.lang.Exception - if an error occurred while loading the page
      • loadPage

        protected void loadPage​(java.net.URL url)
                         throws java.lang.Exception
        Loads the page using HTTP GET from the passed URL.
        Parameters:
        url - the target URL
        Throws:
        java.lang.Exception - if an error occurred while loading the page
      • loadPage

        protected void loadPage​(java.lang.String urlAsString,
                                long waitingTime)
                         throws java.lang.Exception
        Loads the page using HTTP GET from the passed URL.
        Parameters:
        urlAsString - the target URL as string
        waitingTime - Waiting time for all background tasks on the page to be finished
        Throws:
        java.lang.Exception - if an error occurred while loading the page
      • loadPage

        protected void loadPage​(java.lang.String urlAsString)
                         throws java.lang.Exception
        Loads the page using HTTP GET from the passed URL.
        Parameters:
        urlAsString - the target URL as string
        Throws:
        java.lang.Exception - if an error occurred while loading the page
      • loadPageByClick

        protected void loadPageByClick​(HtmlElement element,
                                       long waitingTime)
                                throws java.lang.Exception
        Loads the page by "clicking" the passed HTML element.
        Parameters:
        element - the HTML element to click
        waitingTime - Waiting time for all background tasks on the page to be finished
        Throws:
        java.lang.Exception - if an error occurred while loading the page
      • loadPageByClick

        protected void loadPageByClick​(HtmlElement element)
                                throws java.lang.Exception
        Loads the page by "clicking" the passed HTML element.
        Parameters:
        element - the HTML element to click
        Throws:
        java.lang.Exception - if an error occurred while loading the page
      • loadPageByDragAndDrop

        protected void loadPageByDragAndDrop​(HtmlElement draggable,
                                             HtmlElement dropTarget,
                                             long waitingTime)
                                      throws java.lang.Exception
        Loads the page by drag and drop
        Parameters:
        draggable - the dragged object
        dropTarget - the element on which to drop
        Throws:
        java.lang.Exception - if an error occurred while loading the page
      • loadPageByDragAndDrop

        protected void loadPageByDragAndDrop​(HtmlElement draggable,
                                             HtmlElement dropTarget)
                                      throws java.lang.Exception
        Loads the page by drag and drop
        Parameters:
        draggable - the dragged object
        dropTarget - the element on which to drop
        Throws:
        java.lang.Exception - if an error occurred while loading the page
      • loadPageByFormClick

        @Deprecated
        protected void loadPageByFormClick​(HtmlForm form,
                                           java.lang.String elementToClick,
                                           boolean randomPosition,
                                           long waitingTime)
                                    throws java.lang.Exception
        Deprecated.
        As of XLT 4.9.0, use loadPageByFormClick(HtmlForm, String, long) instead.
        Loads the page by "clicking" the passed HTML element in the specified HTML form element. This method skips hidden elements and reports an error if a suitable element to click on was not found.
        Parameters:
        form - the HTML form
        elementToClick - the HTML element to click, cannot be a hidden element, this can be the name or the id. The name will be tried first, after that the id.
        randomPosition - (parameter ignored)
        waitingTime - Waiting time for all background tasks on the page to be finished
        Throws:
        java.lang.Exception - if an error occurred while loading the page
        ElementMissingException - if we do not have an element to click on
      • loadPageByFormClick

        @Deprecated
        protected void loadPageByFormClick​(HtmlForm form,
                                           java.lang.String elementToClick,
                                           boolean randomPosition)
                                    throws java.lang.Exception
        Deprecated.
        As of XLT 4.9.0, use loadPageByFormClick(HtmlForm, String) instead.
        Loads the page by "clicking" the passed HTML element in the specified HTML form element. This method skips hidden elements and reports an error if a suitable element to click on was not found.
        Parameters:
        form - the HTML form
        elementToClick - the HTML element to click, cannot be a hidden element, this can be the name or the id. The name will be tried first, after that the id.
        randomPosition - (parameter ignored)
        Throws:
        java.lang.Exception - if an error occurred while loading the page
        ElementMissingException - if we do not have an element to click on
      • loadPageByFormClick

        protected void loadPageByFormClick​(HtmlForm form,
                                           java.lang.String elementToClick,
                                           long waitingTime)
                                    throws java.lang.Exception
        Loads the page by "clicking" the passed HTML element in the specified HTML form element.
        Parameters:
        form - the HTML form
        elementToClick - the HTML element to click, cannot be a hidden element, this can be the name or the id. The name will be tried first, after that the id.
        waitingTime - Waiting time for all background tasks on the page to be finished
        Throws:
        java.lang.Exception - if an error occurred while loading the page
      • loadPageByFormClick

        protected void loadPageByFormClick​(HtmlForm form,
                                           java.lang.String elementToClick)
                                    throws java.lang.Exception
        Loads the page by "clicking" the passed HTML element in the specified HTML form element.
        Parameters:
        form - the HTML form
        elementToClick - the HTML element to click
        Throws:
        java.lang.Exception - if an error occurred while loading the page
      • loadPageBySelect

        protected void loadPageBySelect​(HtmlSelect select,
                                        java.lang.String optionValue)
                                 throws java.lang.Exception
        Loads the page by selecting an option of the given HTML select element.
        Parameters:
        select - the HTML select element
        optionValue - the value of the HTML option to select
        Throws:
        java.lang.Exception
      • loadPageBySelect

        protected void loadPageBySelect​(HtmlSelect select,
                                        java.lang.String optionValue,
                                        long waitingTime)
                                 throws java.lang.Exception
        Loads the page by selecting an option from the given HTML select element.
        Parameters:
        select - the HTML select
        optionValue - the value of the HTML option to select
        waitingTime - Waiting time for all background tasks on the page to be finished
        Throws:
        java.lang.Exception
      • loadPageBySelect

        protected void loadPageBySelect​(HtmlSelect select,
                                        HtmlOption option)
        Loads the page by selecting an option form the given HTML select element.
        Parameters:
        select - the HTML select
        option - the HTML option to select
      • loadPageBySelect

        protected void loadPageBySelect​(HtmlSelect select,
                                        HtmlOption option,
                                        long waitingTime)
                                 throws java.lang.Exception
        Loads the page by selecting an option from the given HTML select element.
        Parameters:
        select - the HTML select
        option - the HTML option to select
        waitingTime - Waiting time for all background tasks on the page to be finished
        Throws:
        java.lang.Exception
      • loadPageByFormSubmit

        protected void loadPageByFormSubmit​(HtmlForm form,
                                            SubmittableElement element,
                                            long waitingTime)
                                     throws java.lang.Exception
        Loads the page by submitting the given form. Form submission is triggered by the given submittable element.
        Parameters:
        form - the HTML form to submit
        element - the submittable element used to trigger form submission
        waitingTime - Waiting time for all background tasks on the page to be finished
        Throws:
        java.lang.Exception
      • loadPageByFormSubmit

        protected void loadPageByFormSubmit​(HtmlForm form,
                                            SubmittableElement element)
                                     throws java.lang.Exception
        Loads the page by submitting the given form. Form submission is triggered by the given submittable element.
        Parameters:
        form - the HTML form to submit
        element - the submittable element used to trigger form submission
        Throws:
        java.lang.Exception
      • loadPageByFormSubmit

        protected void loadPageByFormSubmit​(HtmlForm form,
                                            long waitingTime)
                                     throws java.lang.Exception
        Loads the page by submitting the given form.
        Parameters:
        form - the HTML form to submit
        waitingTime - Waiting time for all background tasks on the page to be finished
        Throws:
        java.lang.Exception
      • loadPageByFormSubmit

        protected void loadPageByFormSubmit​(HtmlForm form)
                                     throws java.lang.Exception
        Loads the page by submitting the given form.
        Parameters:
        form - the HTML form to submit
        Throws:
        java.lang.Exception
      • loadPageByTypingKeys

        protected void loadPageByTypingKeys​(HtmlElement element,
                                            java.lang.String text,
                                            long waitingTime)
                                     throws java.lang.Exception
        Loads the page by typing keys. Whether or not the page is reloaded depends on the key event handlers attached to the target HTML element.
        Parameters:
        element - the target HTML element
        text - the text to type
        waitingTime - Waiting time for all background tasks on the page to be finished
        Throws:
        java.lang.Exception
      • loadPageByTypingKeys

        protected void loadPageByTypingKeys​(HtmlElement element,
                                            java.lang.String text)
                                     throws java.lang.Exception
        Loads the page by typing keys. Whether or not the page is reloaded depends on the key event handlers attached to the target HTML element.
        Parameters:
        element - the target HTML element
        text - the text to type
        Throws:
        java.lang.Exception
      • getNetworkDataSet

        protected java.util.List<NetworkData> getNetworkDataSet()
        Returns the network data set.
        Returns:
        network data as set