Package org.zkoss.test.webdriver
Class BaseTestCase
java.lang.Object
org.zkoss.test.webdriver.BaseTestCase
- Direct Known Subclasses:
SingletonWebDriverTestCase,WebDriverTestCase
A base class to test using WebDriver.
Currently support Chromium headless
- Author:
- jumperchen
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final ThreadLocal<org.openqa.selenium.WebDriver>protected org.openqa.selenium.WebDriverstatic final Stringprotected static int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidAsserts no ZK and JS errorprotected voidAsserts no JavaScript errors occur.protected voidAsserts no ZK errorprotected voidblur(ClientWidget locator) Sets the blur state to the given locator.protected voidcheck(ClientWidget locator) Checks the given locator.protected voidclick(ClientWidget locator) Clicks upon the given locator.protected voidclickAt(ClientWidget locator, int offsetX, int offsetY) protected voidCloses the zk.log console and removes it.org.openqa.selenium.WebDriverconnect()org.openqa.selenium.WebDriverprotected voidcopy()Press hot key (e.g.protected voidcut()Press hot key (e.g.protected voiddblClick(ClientWidget locator) Double clicks upon the given locator.protected voiddestroyServer(org.eclipse.jetty.server.Server currentServer) protected voidDisables the connection waiting.protected voiddragdropTo(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.protected voiddropUploadFile(JQuery element, Path file) Simulates drag and drop a file to a Dropupload element.protected voiddropUploadFiles(JQuery element, List<Path> files, int offsetX, int offsetY) Simulates drag and drop files to a Dropupload element.protected voidEnables the connection waiting.static voidprotected voidfocus(ClientWidget locator) Sets the focus state to the given locator.protected org.openqa.selenium.interactions.ActionsReturns the browser actions.protected org.openqa.selenium.interactions.ActionsgetActions(Duration pause) Returns the browser actions.protected static Stringprotected static Stringprotected static Stringstatic Stringprotected Stringprotected Stringprotected static StringgetHost()protected StringReturns the text content of zk messagebox from client side.protected static intgetPort()protected Stringprotected intgetRetryCount(boolean includingAnimation) Returns the retry count for waiting for Ajax response.protected static Stringprotected intgetSpeed()Returns the wait response speed.static intgetStatusCode(String url) Gets the HTTP response status code.protected StringgetTestURL(String file) protected intprotected org.openqa.selenium.WebDriverprotected org.openqa.selenium.chrome.ChromeOptionsGets the WebDriver options.protected StringgetZKLog()Returns the text of zk.log from client side.booleanhasError()protected voidinitServer(org.eclipse.jetty.server.Server currentServer) protected org.openqa.selenium.WebDriverprotected booleanprotected static booleanisMac()protected static booleanprotected static booleanisUnix()protected booleanprotected booleanisUsingRemoteWebDriver(org.openqa.selenium.chrome.ChromeOptions driverOptions) protected booleanisUsingRemoteWebDriver(org.openqa.selenium.firefox.FirefoxOptions driverOptions) protected static booleanprotected booleanReturns the text of zk.log from client side.protected JQueryReturns the Jquery object of the selectorprotected JQueryjq(ClientWidget el) Returns the Jquery object of the ZKClientObject.protected voidmouseOver(ClientWidget locator) Hover.static intReturns the int value from the given string number.protected voidpaste()Press hot key (e.g.protected voidrightClick(ClientWidget locator) Right clicks upon the given locator.protected voidTrigger a select all action.protected WidgetselectComboitem(Widget combobox, int index) Selects an comboitem from the given combobox.protected voidsendKeys(ClientWidget locator, CharSequence... keysToSend) Use this method to simulate typing into an element, which may set its value.protected voidsetCursorPosition(ClientWidget locator, int position) Moves the text cursor to the specified position in the given input element or textarea.protected voidsleep(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.voidstop()protected StringstripJsessionid(String url) Strips ;jsessionid= in URL because it is annoying when comparing URLs.static org.openqa.selenium.WebElementtoElement(ClientWidget locator) protected voidtrigger(ClientWidget widget, String event) Execute all handlers and behaviors attached to the matched elements for the given event typestatic StringTrims the multiline string into one line string.protected voidtype(ClientWidget locator, String text) Types the text into the given locator.protected voidWaits for Ajax response.protected voidwaitResponse(boolean includingAnimation) Waits for Ajax response.protected voidwaitResponse(int timeout) Waits for Ajax response according to the timeout attribute.protected voidwaitResponse(int timeout, boolean includingAnimation) Waits for Ajax response according to the timeout attribute.protected WidgetReturns the Widget object of the UUID.protected WidgetReturns the Widget object of the given element.protected WidgetReturns the Widget object from the JQuery object.protected ZKReturns the ZK object of the selectorprotected ZKzk(ClientWidget el) Returns the ZK object of the ZKClientObject.
-
Field Details
-
PACKAGE
-
static_port
protected static int static_port -
_local
-
driver
protected org.openqa.selenium.WebDriver driver
-
-
Constructor Details
-
BaseTestCase
public BaseTestCase()
-
-
Method Details
-
getPort
protected static int getPort() -
getContextPath
-
getHost
-
getAddress
-
isHeadless
protected boolean isHeadless() -
getWebDriver
protected org.openqa.selenium.WebDriver getWebDriver() -
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
-
getFileLocation
-
getFileExtension
-
connect
-
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
-
getBaseResource
-
initServer
- 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
-
eval
-
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
Returns the Widget object of the UUID.- Parameters:
uuid- the element ID.
-
widget
Returns the Widget object of the given element.- Parameters:
element- the element.
-
widget
Returns the Widget object from the JQuery object.- Parameters:
jQuery- the JQuery object.
-
jq
Returns the Jquery object of the selectorDefault: without "#" sign
- Parameters:
selector- the selector
-
jq
Returns the Jquery object of the ZKClientObject.- Parameters:
el- the ZKClientObject
-
zk
Returns the ZK object of the ZKClientObject.- Parameters:
el- the ZKClientObject
-
zk
Returns the ZK object of the selector- Parameters:
selector- the selector of the element
-
parseInt
Returns the int value from the given string number.- Parameters:
number- the string number, if null or empty, 0 is assumed.
-
trigger
Execute all handlers and behaviors attached to the matched elements for the given event type- Parameters:
widget-event-
-
toElement
-
trim
Trims the multiline string into one line 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
Sets the focus state to the given locator.- Parameters:
locator-
-
blur
Sets the blur state to the given locator.- Parameters:
locator-
-
click
Clicks upon the given locator.- Parameters:
locator-
-
clickAt
-
rightClick
Right clicks upon the given locator.- Parameters:
locator-
-
dblClick
Double clicks upon the given locator.- Parameters:
locator-
-
check
Checks the given locator. It's the same asclick(ClientWidget)internally.- Parameters:
locator-
-
type
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
Use this method to simulate typing into an element, which may set its value.- Parameters:
keysToSend- character sequence to send to the element
-
selectComboitem
Selects an comboitem from the given combobox.- Parameters:
combobox-index-
-
getStatusCode
Gets the HTTP response status code.- Parameters:
url- the URL- Returns:
- status code. -1 if the connection has any exception.
-
stripJsessionid
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, anAssertions.fail(String)would be raised. -
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 afterActions.clickAndHold(org.openqa.selenium.WebElement). -
getActions
Returns the browser actions.- Parameters:
pause- the pause duration afterActions.clickAndHold(org.openqa.selenium.WebElement)- Since:
- 1.4.39.0.1
-
dropUploadFile
Simulates drag and drop a file to a Dropupload element.- Parameters:
element- Dropupload elementfile- 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 elementfiles- file pathsoffsetX- 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
Moves the text cursor to the specified position in the given input element or textarea.- Parameters:
locator- pointing to an input element or textareaposition- position (starts from 0)
-
mouseOver
Hover.- Parameters:
locator- element
-
dragdropTo
Drag the element from (x, y) (start from element center point), move the mouse by offset, and drop.- Parameters:
locator- elementfromX- 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()
-