Class BaseTestCase

java.lang.Object
org.zkoss.test.webdriver.BaseTestCase
Direct Known Subclasses:
SingletonWebDriverTestCase, WebDriverTestCase

public abstract class BaseTestCase extends Object
A base class to test using WebDriver.

Currently support Chromium headless

Author:
jumperchen
  • Field Details

    • PACKAGE

      public static final String PACKAGE
    • static_port

      protected static int static_port
    • _local

      protected static final ThreadLocal<org.openqa.selenium.WebDriver> _local
    • driver

      protected org.openqa.selenium.WebDriver driver
  • Constructor Details

    • BaseTestCase

      public BaseTestCase()
  • Method Details

    • getPort

      protected static int getPort()
    • getContextPath

      protected static String getContextPath()
    • getHost

      protected static String getHost()
    • getAddress

      protected static String getAddress()
    • isHeadless

      protected boolean isHeadless()
    • getWebDriver

      protected org.openqa.selenium.WebDriver getWebDriver()
    • getRemoteWebDriverUrl

      protected String getRemoteWebDriverUrl()
    • isUseDocker

      protected boolean isUseDocker()
    • isUsingRemoteWebDriver

      protected boolean isUsingRemoteWebDriver(org.openqa.selenium.chrome.ChromeOptions driverOptions)
    • isUsingRemoteWebDriver

      protected boolean isUsingRemoteWebDriver(org.openqa.selenium.firefox.FirefoxOptions driverOptions)
    • getWebDriverOptions

      protected org.openqa.selenium.chrome.ChromeOptions getWebDriverOptions()
      Gets the WebDriver options. You can add arguments for Chromium to change settings like locale or user-agent string. A list of available options can be found at Capabilities & ChromeOptions.
      Returns:
      WebDriver options
    • connect

      public org.openqa.selenium.WebDriver connect()
    • getTestURL

      protected String getTestURL(String file)
    • getFileLocation

      protected String getFileLocation()
    • getFileExtension

      protected String getFileExtension()
    • connect

      public org.openqa.selenium.WebDriver connect(String location)
    • disableConnectionWait

      protected void disableConnectionWait()
      Disables the connection waiting.

      By default, it will wait for the connection to be established. In some cases, you may want to disable it, such as alert text at connect phase.

    • enableConnectionWait

      protected void enableConnectionWait()
      Enables the connection waiting.
      See Also:
    • initWebDriver

      protected org.openqa.selenium.WebDriver initWebDriver()
    • getTimeout

      protected int getTimeout()
    • stop

      @AfterEach public void stop()
    • getServerPort

      protected static String getServerPort()
    • getBaseResource

      protected static String getBaseResource()
    • initServer

      protected void initServer(org.eclipse.jetty.server.Server currentServer) throws Exception
      Throws:
      Exception
    • destroyServer

      protected void destroyServer(org.eclipse.jetty.server.Server currentServer)
    • waitResponse

      protected void waitResponse()
      Waits for Ajax response. (excluding animation check)
      See Also:
    • waitResponse

      protected void waitResponse(boolean includingAnimation)
      Waits for Ajax response.

      By default the timeout time is specified in config.properties

      Parameters:
      includingAnimation - if true, it will include animation check.
      See Also:
    • getSpeed

      protected int getSpeed()
      Returns the wait response speed.

      Default: 500ms

      Returns:
    • waitResponse

      protected void waitResponse(int timeout, boolean includingAnimation)
      Waits for Ajax response according to the timeout attribute.
      Parameters:
      timeout -
      includingAnimation - if true, it will include animation check.
    • getRetryCount

      protected int getRetryCount(boolean includingAnimation)
      Returns the retry count for waiting for Ajax response. Default: 3 and if including animation, 5.
    • getEval

      public static String getEval(String script)
    • eval

      public static void eval(String script)
    • sleep

      protected void sleep(long millis)
      Causes the currently executing thread to sleep for the specified number of milliseconds, subject to the precision and accuracy of system timers and schedulers. The thread does not lose ownership of any monitors.
      Parameters:
      millis - the length of time to sleep in milliseconds.
    • waitResponse

      protected void waitResponse(int timeout)
      Waits for Ajax response according to the timeout attribute.(excluding animation check)
      Parameters:
      timeout - the time. (millisecond).
      See Also:
    • widget

      protected Widget widget(String uuid)
      Returns the Widget object of the UUID.
      Parameters:
      uuid - the element ID.
    • widget

      protected Widget widget(Element element)
      Returns the Widget object of the given element.
      Parameters:
      element - the element.
    • widget

      protected Widget widget(JQuery jQuery)
      Returns the Widget object from the JQuery object.
      Parameters:
      jQuery - the JQuery object.
    • jq

      protected JQuery jq(String selector)
      Returns the Jquery object of the selector

      Default: without "#" sign

      Parameters:
      selector - the selector
    • jq

      protected JQuery jq(ClientWidget el)
      Returns the Jquery object of the ZKClientObject.
      Parameters:
      el - the ZKClientObject
    • zk

      protected ZK zk(ClientWidget el)
      Returns the ZK object of the ZKClientObject.
      Parameters:
      el - the ZKClientObject
    • zk

      protected ZK zk(String selector)
      Returns the ZK object of the selector
      Parameters:
      selector - the selector of the element
    • parseInt

      public static int parseInt(String number)
      Returns the int value from the given string number.
      Parameters:
      number - the string number, if null or empty, 0 is assumed.
    • trigger

      protected void trigger(ClientWidget widget, String event)
      Execute all handlers and behaviors attached to the matched elements for the given event type
      Parameters:
      widget -
      event -
    • toElement

      public static org.openqa.selenium.WebElement toElement(ClientWidget locator)
    • trim

      public static String trim(String text)
      Trims the multiline string into one line string.
    • getZKLog

      protected String getZKLog()
      Returns the text of zk.log from client side.
    • isZKLogAvailable

      protected boolean isZKLogAvailable()
      Returns the text of zk.log from client side.
    • closeZKLog

      protected void closeZKLog()
      Closes the zk.log console and removes it.
    • focus

      protected void focus(ClientWidget locator)
      Sets the focus state to the given locator.
      Parameters:
      locator -
    • blur

      protected void blur(ClientWidget locator)
      Sets the blur state to the given locator.
      Parameters:
      locator -
    • click

      protected void click(ClientWidget locator)
      Clicks upon the given locator.
      Parameters:
      locator -
    • clickAt

      protected void clickAt(ClientWidget locator, int offsetX, int offsetY)
    • rightClick

      protected void rightClick(ClientWidget locator)
      Right clicks upon the given locator.
      Parameters:
      locator -
    • dblClick

      protected void dblClick(ClientWidget locator)
      Double clicks upon the given locator.
      Parameters:
      locator -
    • check

      protected void check(ClientWidget locator)
      Checks the given locator. It's the same as click(ClientWidget) internally.
      Parameters:
      locator -
    • type

      protected void type(ClientWidget locator, String text)
      Types the text into the given locator.

      By default, it will simulate a real user behavior to focus the input elemnt from the given locator, and then replace the old text with the new text and then blur the input element.

      Parameters:
      locator -
      text -
    • sendKeys

      protected void sendKeys(ClientWidget locator, CharSequence... keysToSend)
      Use this method to simulate typing into an element, which may set its value.
      Parameters:
      keysToSend - character sequence to send to the element
    • selectComboitem

      protected Widget selectComboitem(Widget combobox, int index)
      Selects an comboitem from the given combobox.
      Parameters:
      combobox -
      index -
    • getStatusCode

      public static int getStatusCode(String url)
      Gets the HTTP response status code.
      Parameters:
      url - the URL
      Returns:
      status code. -1 if the connection has any exception.
    • stripJsessionid

      protected String stripJsessionid(String url)
      Strips ;jsessionid= in URL because it is annoying when comparing URLs.
      Parameters:
      url - the original URL
      Returns:
      stripped URL
    • hasError

      public boolean hasError()
    • assertNoZKError

      protected void assertNoZKError()
      Asserts no ZK error
    • assertNoAnyError

      protected void assertNoAnyError()
      Asserts no ZK and JS error
    • assertNoJSError

      protected void assertNoJSError()
      Asserts no JavaScript errors occur. If there is any error on browser console, an Assertions.fail(String) would be raised.
    • getMessageBoxContent

      protected String getMessageBoxContent()
      Returns the text content of zk messagebox from client side.
    • getActions

      protected org.openqa.selenium.interactions.Actions getActions()
      Returns the browser actions. Starting from 1.4.39.0.1, pauses for 100 milliseconds after Actions.clickAndHold(org.openqa.selenium.WebElement).
    • getActions

      protected org.openqa.selenium.interactions.Actions getActions(Duration pause)
      Returns the browser actions.
      Parameters:
      pause - the pause duration after Actions.clickAndHold(org.openqa.selenium.WebElement)
      Since:
      1.4.39.0.1
    • dropUploadFile

      protected void dropUploadFile(JQuery element, Path file) throws FileNotFoundException
      Simulates drag and drop a file to a Dropupload element.
      Parameters:
      element - Dropupload element
      file - file path
      Throws:
      FileNotFoundException - file not found
    • dropUploadFiles

      protected void dropUploadFiles(JQuery element, List<Path> files, int offsetX, int offsetY) throws FileNotFoundException
      Simulates drag and drop files to a Dropupload element.
      Parameters:
      element - Dropupload element
      files - file paths
      offsetX - Drop offset x relative to the top/left corner of the drop area. Center if 0.
      offsetY - Drop offset y relative to the top/left corner of the drop area. Center if 0.
      Throws:
      FileNotFoundException - file not found
      See Also:
    • cut

      protected void cut()
      Press hot key (e.g. Ctrl + X) to trigger a cut action. It's caller's responsibility to focus/select text before calling this method.
    • copy

      protected void copy()
      Press hot key (e.g. Ctrl + C) to trigger a copy action. It's caller's responsibility to focus/select text before calling this method.
    • paste

      protected void paste()
      Press hot key (e.g. Ctrl + V) to trigger a paste action. It's caller's responsibility to click/focus on a DOM node before calling this method.
    • selectAll

      protected void selectAll()
      Trigger a select all action. It's caller's responsibility to click/focus on a DOM node before calling this method.
    • setCursorPosition

      protected void setCursorPosition(ClientWidget locator, int position)
      Moves the text cursor to the specified position in the given input element or textarea.
      Parameters:
      locator - pointing to an input element or textarea
      position - position (starts from 0)
    • mouseOver

      protected void mouseOver(ClientWidget locator)
      Hover.
      Parameters:
      locator - element
    • dragdropTo

      protected void dragdropTo(ClientWidget locator, int fromX, int fromY, int offsetX, int offsetY)
      Drag the element from (x, y) (start from element center point), move the mouse by offset, and drop.
      Parameters:
      locator - element
      fromX - X (start from element center point)
      fromY - Y (start from element center point)
      offsetX - Offset X (negative means left)
      offsetY - Offset Y (negative means up)
    • isUnix

      protected static boolean isUnix()
    • isWindows

      protected static boolean isWindows()
    • isSolaris

      protected static boolean isSolaris()
    • isMac

      protected static boolean isMac()