Package org.primefaces.selenium
Class PrimeSelenium
java.lang.Object
org.primefaces.selenium.PrimeSelenium
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidclearInput(org.openqa.selenium.WebElement input, boolean isAjaxified) Clears the input field of text.static <T extends org.openqa.selenium.WebElement>
TcreateFragment(Class<T> fragmentClass, org.openqa.selenium.By by) Creates the PrimeFaces Selenium component for the selector.static <T extends org.openqa.selenium.WebElement>
TcreateFragment(Class<T> fragmentClass, org.openqa.selenium.WebElement element) Creates the PrimeFaces Selenium component for the element.static voidGlobally disable all CSS and jQuery animations.static voidGlobally enable all CSS and jQuery animations.static <T> TexecuteScript(boolean isAjaxified, String script, Object... args) Executes JavaScript in the browser and will wait if the request is an AJAX request.static <T> TexecuteScript(String script, Object... args) Executes JavaScript in the browser.static Stringstatic org.openqa.selenium.CapabilitiesGet Capabilities of WebDriver.static StringGets the URL of the page.static StringgetUrl(AbstractPrimePage page) Gets the URL of the page.static org.openqa.selenium.WebDriverGets the current Selenium WebDriver.static org.openqa.selenium.html5.WebStorageGet WebStorage of WebDriver.static <T extends AbstractPrimePage>
TGoto a particular page.static voidGoto a particular page.static voidgoTo(AbstractPrimePage page) Goto a particular page.static <T> TGuard the widget script which fires an AJAX request and means wait until it has completed before returning.static <T> TguardAjax(T target) Guard the AJAX request which means wait until it has completed before returning.static <T> TguardAjax(T target, int delayInMilliseconds) Guard the AJAX request which means wait until it has completed before returning.static <T> TguardHttp(T target) Guard the HTTP request which means wait until it has completed before returning.static booleanhasCssClass(org.openqa.selenium.WebElement element, String... cssClass) Checks a WebElement if it has a CSS class or classes.static booleanisChrome()Is the current WebDriver a Chrome driver?static booleanisElementClickable(org.openqa.selenium.WebElement element) Is this element clickable?static booleanisElementDisplayed(org.openqa.selenium.By by) Is the Element displayed on the page?static booleanisElementDisplayed(org.openqa.selenium.WebElement element) Is the Element displayed on the page?static booleanisElementEnabled(org.openqa.selenium.By by) Is the Element enabled on the page?static booleanisElementEnabled(org.openqa.selenium.WebElement element) Is the Element enabled on the page?static booleanisElementPresent(org.openqa.selenium.By by) Is the Element present on the page?static booleanisElementPresent(org.openqa.selenium.WebElement element) Is the Element present on the page?static booleanIs the current WebDriver a Firefox driver?static booleanIs this driver running headless? Meaning without a UI.static booleanisMacOs()Are we running on MacOS?static booleanisSafari()Is the current WebDriver a Safari driver?static booleanisVisibleInViewport(org.openqa.selenium.WebElement element) Is the Element visisible in the current viewport??static voidsetHiddenInput(org.openqa.selenium.WebElement input, String value) Sets a value to a hidden input.static voidwait(int milliseconds) Waits specified amount of milliseconds.static org.openqa.selenium.support.ui.WebDriverWaitWait until the document is loaded.static org.openqa.selenium.support.ui.WebDriverWaitwaitGui()Wait will ignore instances of NotFoundException that are encountered (thrown) by default in the 'until' condition, and immediately propagate all others.
-
Method Details
-
getWebDriver
public static org.openqa.selenium.WebDriver getWebDriver()Gets the current Selenium WebDriver.- Returns:
- the
WebDrivercurrently being used
-
createFragment
public static <T extends org.openqa.selenium.WebElement> T createFragment(Class<T> fragmentClass, org.openqa.selenium.By by) Creates the PrimeFaces Selenium component for the selector.- Type Parameters:
T- the type of component returned- Parameters:
fragmentClass- the component class to create like InputText.classby- the selector to find the component by- Returns:
- the component
-
createFragment
public static <T extends org.openqa.selenium.WebElement> T createFragment(Class<T> fragmentClass, org.openqa.selenium.WebElement element) Creates the PrimeFaces Selenium component for the element.- Type Parameters:
T- the type of component returned- Parameters:
fragmentClass- the component class to create like InputText.classelement- the WebElement to bind this component class to- Returns:
- the component
-
goTo
Goto a particular page.- Type Parameters:
T- theAbstractPrimePagetype- Parameters:
pageClass- the Page class to go to- Returns:
- the
AbstractPrimePagepage created
-
goTo
Goto a particular page.- Parameters:
page- theAbstractPrimePageto go to
-
goTo
Goto a particular page.- Parameters:
partialUrl- the partial URL
-
getUrl
Gets the URL of the page.- Parameters:
page- theAbstractPrimePage- Returns:
- the URL of the page
-
getUrl
-
getBaseUrl
-
hasCssClass
Checks a WebElement if it has a CSS class or classes. If more than one is listed then ALL must be found on the element.- Parameters:
element- the element to checkcssClass- the CSS class or classes to look for- Returns:
- true if this element has the CSS class
-
isElementPresent
public static boolean isElementPresent(org.openqa.selenium.By by) Is the Element present on the page?- Parameters:
by- the selector- Returns:
- true if present
-
isElementPresent
public static boolean isElementPresent(org.openqa.selenium.WebElement element) Is the Element present on the page?- Parameters:
element- the WebElement to check- Returns:
- true if present
-
isElementDisplayed
public static boolean isElementDisplayed(org.openqa.selenium.By by) Is the Element displayed on the page?- Parameters:
by- the selector- Returns:
- true if displayed
-
isElementDisplayed
public static boolean isElementDisplayed(org.openqa.selenium.WebElement element) Is the Element displayed on the page?- Parameters:
element- the WebElement to check- Returns:
- true if displayed
-
isVisibleInViewport
public static boolean isVisibleInViewport(org.openqa.selenium.WebElement element) Is the Element visisible in the current viewport??- Parameters:
element- the WebElement to check- Returns:
- true if visible
-
isElementEnabled
public static boolean isElementEnabled(org.openqa.selenium.By by) Is the Element enabled on the page?- Parameters:
by- the selector- Returns:
- true if enabled
-
isElementEnabled
public static boolean isElementEnabled(org.openqa.selenium.WebElement element) Is the Element enabled on the page?- Parameters:
element- the WebElement to check- Returns:
- true if enabled
-
isElementClickable
public static boolean isElementClickable(org.openqa.selenium.WebElement element) Is this element clickable?- Parameters:
element- the WebElement to check for clickable- Returns:
- true if clickable false if not
-
guardHttp
public static <T> T guardHttp(T target) Guard the HTTP request which means wait until it has completed before returning.- Type Parameters:
T- the type- Parameters:
target- the target to guard- Returns:
- the type
-
guardAjax
public static <T> T guardAjax(T target) Guard the AJAX request which means wait until it has completed before returning.- Type Parameters:
T- the type of element- Parameters:
target- the element to guard- Returns:
- the element
-
guardAjax
public static <T> T guardAjax(T target, int delayInMilliseconds) Guard the AJAX request which means wait until it has completed before returning. This introduces a delay because some client side activity uses "setTimeout" Javascript to delay the execution of AJAX.- Type Parameters:
T- the element type- Parameters:
target- the element to guarddelayInMilliseconds- how long to delay before expecting an AJAX event- Returns:
- the element
-
guardAjax
Guard the widget script which fires an AJAX request and means wait until it has completed before returning.- Type Parameters:
T- the return type- Parameters:
script- the script to executeargs- any arguments to the script- Returns:
- the result of running the JavaScript
-
executeScript
-
executeScript
Executes JavaScript in the browser and will wait if the request is an AJAX request.- Type Parameters:
T- the return type- Parameters:
isAjaxified- true if this is an AJAX request, false if regular scriptscript- the script to executeargs- any arguments to the script- Returns:
- the result of running the JavaScript
-
waitGui
public static org.openqa.selenium.support.ui.WebDriverWait waitGui()Wait will ignore instances of NotFoundException that are encountered (thrown) by default in the 'until' condition, and immediately propagate all others. You can add more to the ignore list by calling ignoring(exceptions to add).- Returns:
- the
WebDriverWait
-
waitDocumentLoad
public static org.openqa.selenium.support.ui.WebDriverWait waitDocumentLoad()Wait until the document is loaded.- Returns:
- the
WebDriverWait
-
disableAnimations
public static void disableAnimations()Globally disable all CSS and jQuery animations. -
enableAnimations
public static void enableAnimations()Globally enable all CSS and jQuery animations. -
setHiddenInput
Sets a value to a hidden input.- Parameters:
input- the WebElement input to setvalue- the value to set- See Also:
-
clearInput
public static void clearInput(org.openqa.selenium.WebElement input, boolean isAjaxified) Clears the input field of text.- Parameters:
input- the WebElement input to setisAjaxified- true if using AJAX- See Also:
-
isChrome
public static boolean isChrome()Is the current WebDriver a Chrome driver?- Returns:
- true if Chrome, false if any other browser
-
isFirefox
public static boolean isFirefox()Is the current WebDriver a Firefox driver?- Returns:
- true if Firefox, false if any other browser
-
isSafari
public static boolean isSafari()Is the current WebDriver a Safari driver?- Returns:
- true if Safari, false if any other browser
-
isMacOs
public static boolean isMacOs()Are we running on MacOS?- Returns:
- true if MacOS
-
isHeadless
public static boolean isHeadless()Is this driver running headless? Meaning without a UI.- Returns:
- true if headless, false if not
-
wait
public static void wait(int milliseconds) Waits specified amount of milliseconds.- Parameters:
milliseconds- how many milliseconds to wait
-
getWebStorage
public static org.openqa.selenium.html5.WebStorage getWebStorage()Get WebStorage of WebDriver.- Returns:
- Returns WebStorage of WebDriver when this feature is supported by the browser. Some browsers like Safari (as of january 2021) do not support WebStorage via WebDriver. In this case null is returned.
-
getCapabilities
public static org.openqa.selenium.Capabilities getCapabilities()Get Capabilities of WebDriver.- Returns:
- Returns Capabilities of WebDriver
-