Class AbstractLightWeightPageAction


public abstract class AbstractLightWeightPageAction extends AbstractWebAction
AbstractLightWeightPageAction is the base class for all HTML/XML-based actions which do simple page processing only. In contrast to AbstractHtmlPageAction, the loaded page is represented as a single unparsed string. This makes it harder to pick certain elements of the page, but completely avoids the client-side overhead to parse the page and represent it as a tree of elements. Especially with complex pages, the overhead may be significantly lower this way. So this class should be used, if either the page processing is simple enough or the test clients turn out to be the bottleneck.
  • Constructor Details

    • AbstractLightWeightPageAction

      protected AbstractLightWeightPageAction(AbstractWebAction previousAction, String timerName)
      Creates a new AbstractLightWeightPageAction 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
    • AbstractLightWeightPageAction

      protected AbstractLightWeightPageAction(String timerName)
      Creates a new AbstractLightWeightPageAction 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 Details

    • getPreviousAction

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

      public LightWeightPage getLightWeightPage()
      Returns the light-weight page generated by this action.
      Returns:
      the page
    • getContent

      public String getContent()
      Returns the unparsed content of the web page loaded by this action.
      Returns:
      the content of the loaded page as string
    • getHttpResponseCode

      public int getHttpResponseCode()
      Returns the response code of the last loaded page.
      Returns:
      the HTTP response code
    • getURL

      public URL getURL()
      Returns the URL that was used to load the page. Subsequent actions may use this value to create new URLs based on this URL.
      Returns:
      the URL
    • run

      public void run() throws 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:
      Throwable - if an error occurred while running the action
    • setLightWeightPage

      public void setLightWeightPage(LightWeightPage page)
      Sets the given light-weight page object to be the result of this action. Typically, the light-weight page is generated by one of the loadPage() methods and need not be set explicitly.
      Parameters:
      page - the page to set
    • loadPage

      protected void loadPage(URL url) throws Exception
      Loads the page using HTTP GET from the passed URL and stores it internally. The URL is stored for further reference.
      Parameters:
      url - the target URL
      Throws:
      Exception - if an error occurred while loading the page
    • loadPage

      protected void loadPage(String urlAsString) throws Exception
      Creates an URL from the passed string, loads the page using HTTP GET and stores it internally. The URL is stored for further reference.
      Parameters:
      urlAsString - an URL as string
      Throws:
      Exception - if an error occurred while loading the page
    • loadPage

      protected void loadPage(URL url, HttpMethod method, List<NameValuePair> requestParameters) throws Exception
      Loads the page using the given request method from the passed URL and stores it internally. 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:
      Exception - if an error occurred while loading the page