Package org.kquiet.browser
Class BasicActionRunner
java.lang.Object
org.kquiet.browser.BasicActionRunner
- All Implemented Interfaces:
Closeable
,AutoCloseable
,ActionRunner
BasicActionRunner
maintains two prioritized thread pool internally to execute
ActionComposer
and browser actions separatedly. The thread pool for
ActionComposer
allows multiple ones to be run concurrently(depends on parameter values in
constructors). The thread pool for browser actions is single-threaded, so only one browser action
is executed at a time(due to the constraint of WebDriver).- Author:
- Kimberly
-
Constructor Summary
ConstructorsConstructorDescriptionCreate anBasicActionRunner
withPageLoadStrategy.NONE
as page load strategy,BrowserType.CHROME
as browser type, and at most oneActionComposer
is allowed to be executed at a time.BasicActionRunner
(int maxConcurrentComposer) Create anBasicActionRunner
withPageLoadStrategy.NONE
as page load strategy andBrowserType.CHROME
as browser type.BasicActionRunner
(org.openqa.selenium.PageLoadStrategy pageLoadStrategy, BrowserType browserType) Create anBasicActionRunner
with specified page load strategy, browser type, name, and at most oneActionComposer
is allowed to be executed at a time.BasicActionRunner
(org.openqa.selenium.PageLoadStrategy pageLoadStrategy, BrowserType browserType, int maxConcurrentComposer) Create anBasicActionRunner
with specified page load strategy, browser type, name, and max number of concurrent composer. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
executeAction
(Runnable browserAction, int priority) Execute browser action with specified priority.executeComposer
(ActionComposer actionComposer) Execute givenActionComposer
.getName()
Get the name of thisActionRunner
.Get the identity of root window(the initial window as the browser started).org.openqa.selenium.WebDriver
Get associatedWebDriver
.boolean
This method checks the existence of root window and use the result as the result of browser's aliveness.boolean
isPaused()
Check whether thisActionRunner
is paused or not.void
pause()
Stop executing queuedActionComposer
or browser action, but the running ones will keep running.void
resume()
Resume to executing queuedActionComposer
or browser action (if any).Set the name of thisActionRunner
.
-
Constructor Details
-
BasicActionRunner
public BasicActionRunner()Create anBasicActionRunner
withPageLoadStrategy.NONE
as page load strategy,BrowserType.CHROME
as browser type, and at most oneActionComposer
is allowed to be executed at a time. -
BasicActionRunner
public BasicActionRunner(int maxConcurrentComposer) Create anBasicActionRunner
withPageLoadStrategy.NONE
as page load strategy andBrowserType.CHROME
as browser type.- Parameters:
maxConcurrentComposer
- the max number ofActionComposer
that could be executed by thisBasicActionRunner
concurrently.
-
BasicActionRunner
public BasicActionRunner(org.openqa.selenium.PageLoadStrategy pageLoadStrategy, BrowserType browserType) Create anBasicActionRunner
with specified page load strategy, browser type, name, and at most oneActionComposer
is allowed to be executed at a time.- Parameters:
pageLoadStrategy
- page load strategybrowserType
- the type of browser- See Also:
-
BasicActionRunner
public BasicActionRunner(org.openqa.selenium.PageLoadStrategy pageLoadStrategy, BrowserType browserType, int maxConcurrentComposer) Create anBasicActionRunner
with specified page load strategy, browser type, name, and max number of concurrent composer.- Parameters:
pageLoadStrategy
- page load strategybrowserType
- the type of browsermaxConcurrentComposer
- max number ofActionComposer
that could be executed concurrently- See Also:
-
-
Method Details
-
getName
Description copied from interface:ActionRunner
Get the name of thisActionRunner
.- Specified by:
getName
in interfaceActionRunner
- Returns:
- name represented as
String
-
setName
Description copied from interface:ActionRunner
Set the name of thisActionRunner
.- Specified by:
setName
in interfaceActionRunner
- Parameters:
name
- the name to set- Returns:
- this
ActionRunner
-
getRootWindowIdentity
Description copied from interface:ActionRunner
Get the identity of root window(the initial window as the browser started).- Specified by:
getRootWindowIdentity
in interfaceActionRunner
- Returns:
- identity represented as
String
-
executeAction
Description copied from interface:ActionRunner
Execute browser action with specified priority.- Specified by:
executeAction
in interfaceActionRunner
- Parameters:
browserAction
- browser action to executepriority
- priority of action- Returns:
- a
CompletableFuture
representing the pending completion of given browser action
-
executeComposer
Description copied from interface:ActionRunner
Execute givenActionComposer
.- Specified by:
executeComposer
in interfaceActionRunner
- Parameters:
actionComposer
-ActionComposer
to execute- Returns:
- a
CompletableFuture
representing the pending completion of givenActionComposer
-
getWebDriver
public org.openqa.selenium.WebDriver getWebDriver()Description copied from interface:ActionRunner
Get associatedWebDriver
.- Specified by:
getWebDriver
in interfaceActionRunner
- Returns:
- the
WebDriver
thisActionRunner
is using
-
isBrowserAlive
public boolean isBrowserAlive()This method checks the existence of root window and use the result as the result of browser's aliveness. When a negative result is acquired, users can choose toclose
ActionRunner
and create a new one.- Specified by:
isBrowserAlive
in interfaceActionRunner
- Returns:
true
if the root window exists;false
otherwise
-
pause
public void pause()Stop executing queuedActionComposer
or browser action, but the running ones will keep running.- Specified by:
pause
in interfaceActionRunner
-
resume
public void resume()Resume to executing queuedActionComposer
or browser action (if any).- Specified by:
resume
in interfaceActionRunner
-
isPaused
public boolean isPaused()Description copied from interface:ActionRunner
Check whether thisActionRunner
is paused or not.- Specified by:
isPaused
in interfaceActionRunner
- Returns:
true
if paused;false
otherwise
-
close
public void close()- Specified by:
close
in interfaceActionRunner
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-