|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.kuali.rice.testtools.selenium.WebDriverUtils
public class WebDriverUtils
The goal of the WebDriverUtils class is to invert the dependencies on WebDriver from WebDriverLegacyITBase
for reuse
without having to extend WebDriverLegacyITBase.
For compatibility with JiraAwareFailureUtils
, external test framework asserts and fails should not be called from
WebDriverUtils, instead use JiraAwareAftBase
.
For the first example see waitFor
WebDriverLegacyITBase
Field Summary | |
---|---|
static String |
DEFAULT_BASE_URL
http://localhost:8080/kr-dev |
static String |
DEFAULT_BASE_URL_KRAD
http://localhost:8080/krad-dev |
static String |
DONT_TEAR_DOWN_ON_FAILURE_PROPERTY
Set to true to not close the browser after the test has if the test failed. |
static String |
DONT_TEAR_DOWN_PROPERTY
Set to true to not close the browser after the test has run. |
static String |
HUB_DRIVER_PROPERTY
remote.public.driver |
static String |
HUB_PROPERTY
For use when running Selenium tests through a Selenium Hub. |
static String |
HUB_URL_PROPERTY
http://localhost:4444/wd/hub |
static int |
IMPLICIT_WAIT_TIME_LOOP_MS
wait Methods inter loop sleep period, default of 1000 Milliseconds. |
static int |
IMPLICIT_WAIT_TIME_SECONDS_DEFAULT
IMPLICIT_WAIT_TIME_SECONDS_DEFAULT to configure, default 30 seconds. |
static boolean |
JGROWL_ERROR_FAILURE
If true tests will fail on jGrowl errors, default of false TODO upgrade to config via JVM param. |
static boolean |
jGrowlEnabled
|
static String |
JS_HIGHLIGHT_BACKGROUND
green (#66FF33) |
static String |
JS_HIGHLIGHT_BOARDER
green (#66FF33) |
static String |
JS_HIGHLIGHT_INPUT_PROPERTY
TODO: playback for javascript highlighting. |
static int |
JS_HIGHLIGHT_MS
400 milliseconds. |
static String |
JS_HIGHLIGHT_MS_PROPERTY
JS_HIGHLIGHT_MS as default. |
static String |
JS_HIGHLIGHT_PROPERTY
Highlighting of elements as selenium runs. |
static boolean |
jsHighlightEnabled
|
static String |
PROXY_HOST_PROPERTY
Local proxy used for running tests thru jmeter. |
static String |
REMOTE_AUTOLOGIN_PROPERTY
Skip automatice login if set to anything other than true/ |
static String |
REMOTE_JGROWL_ENABLED
Set to true to enable jGrowl test messages. |
static String |
REMOTE_LOGIN_UIF
Set -Dremote.login.uif=KNS to use old login screen. |
static String |
REMOTE_PROPERTIES_PROPERTY
Set -Dremote.property.file= to load proprties from file |
static String |
REMOTE_PUBLIC_CHROME
Set -Dremote.public.chrome= or WEBDRIVER_CHROME_DRIVER |
static String |
REMOTE_PUBLIC_URL_PROPERTY
-Dremote.public.url= |
static String |
REMOTE_PUBLIC_USER_PROPERTY
Set -Dremote.public.user= to the username to login as |
static String |
REMOTE_PUBLIC_USERPOOL_PROPERTY
You probably don't want to really be using a userpool, set -Dremote.public.userpool= to base url if you must. |
static String |
REMOTE_PUBLIC_WAIT_SECONDS_PROPERTY
Set -Dremote.public.wait.seconds to override DEFAULT_WAIT_SEC. |
protected static SauceLabsWebDriverHelper |
saucelabs
|
static int |
SETUP_URL_LOAD_WAIT_SECONDS
Time to wait for the URL used in setup to load, 120 seconds by default. |
static String |
WEBDRIVER_CHROME_DRIVER
Selenium's webdriver.chrome.driver parameter, you can set -Dwebdriver.chrome.driver= or Rice's REMOTE_PUBLIC_CHROME. |
Constructor Summary | |
---|---|
WebDriverUtils()
|
Method Summary | |
---|---|
static void |
acceptAlertIfPresent(org.openqa.selenium.WebDriver driver)
If an alert is present accept it print the alert text to System.out |
static void |
alertAccept(org.openqa.selenium.WebDriver driver)
Accept the javascript alert (clicking OK). |
static void |
alertDismiss(org.openqa.selenium.WebDriver driver)
Dismiss the javascript alert (clicking Cancel). |
static String |
alertText(org.openqa.selenium.WebDriver driver)
Return alert text. |
static org.openqa.selenium.chrome.ChromeDriverService |
chromeDriverCreateCheck()
ChromeDriver downloads, REMOTE_PUBLIC_CHROME ,
WEBDRIVER_CHROME_DRIVER , and HUB_DRIVER_PROPERTY |
static int |
configuredImplicityWait()
Return the configured implicity wait seconds, REMOTE_PUBLIC_WAIT_SECONDS_PROPERTY and IMPLICIT_WAIT_TIME_SECONDS_DEFAULT . |
static String |
deLinespace(String contents)
Remove double line spacing. |
static String |
determineUser(String testParam)
If REMOTE_PUBLIC_USER_PROPERTY property is set, return its value, else if REMOTE_PUBLIC_USERPOOL_PROPERTY
is set use it to query the userpool service passing the testParam. |
static boolean |
dontTearDownOnFailure(boolean passed)
Given the boolean parameter and depending on if DONT_TEAR_DOWN_ON_FAILURE_PROPERTY is set to something other
than n, don't tear down the browser window on a test failure. |
static boolean |
dontTearDownPropertyNotSet()
Setting the JVM arg remote.driver.dontTearDown to y or t leaves the browser window open when the test has completed. |
static org.openqa.selenium.WebElement |
findButtonByText(org.openqa.selenium.WebDriver driver,
String buttonText)
Find Button by text. |
static org.openqa.selenium.WebElement |
findElement(org.openqa.selenium.WebDriver driver,
org.openqa.selenium.By by)
Find and highlight the WebElement using the given WebDriver and By. |
static String |
getBaseUrlString()
In order to run as a smoke test the ability to set the baseUrl via the JVM arg remote.public.url is required. |
static org.openqa.selenium.WebElement |
getElementByAttributeValue(org.openqa.selenium.WebDriver driver,
String attributeName,
String value)
Return the WebElement that has the attribute name with the given value. |
static String |
getHubUrlString()
In order to run as a smoke test under selenium grid the ability to set the hubUrl via the JVM arg remote.public.hub is required. |
static org.openqa.selenium.WebDriver |
getWebDriver()
remote.public.driver set to chrome or firefox (null assumes firefox). |
static void |
highlightElement(org.openqa.selenium.WebDriver webDriver,
org.openqa.selenium.By by)
|
static void |
highlightElement(org.openqa.selenium.WebDriver webDriver,
org.openqa.selenium.WebElement webElement)
Highlight given WebElement. |
static void |
highlightElements(org.openqa.selenium.WebDriver webDriver,
List<org.openqa.selenium.WebElement> webElements)
|
static boolean |
isAlertPresent(org.openqa.selenium.WebDriver driver)
Return true if an alert is present, false if not. |
static Boolean |
isTextPresent(org.openqa.selenium.WebDriver driver,
String pageText,
String text)
|
static void |
jGrowl(org.openqa.selenium.WebDriver driver,
String jGrowlHeader,
boolean sticky,
String message)
Display jGrowl. |
static void |
jGrowl(org.openqa.selenium.WebDriver driver,
String jGrowlHeader,
boolean sticky,
String message,
Throwable throwable)
Display jGrowl. |
static void |
jGrowlException(Throwable throwable)
Print jGrowl Excetion to System.out, if JGROWL_ERROR_FAILURE is set to true, fail. |
static void |
selectFrameSafe(org.openqa.selenium.WebDriver driver,
String locator)
Select frame defined by locator without throwing an Exception if it doesn't exist. |
static org.openqa.selenium.WebDriver |
setUp(String username,
String url)
Setup the WebDriver test, login, and load the given web page |
static org.openqa.selenium.WebDriver |
setUp(String username,
String url,
String className,
String testName)
Setup the WebDriver test, login, and load the given web page |
static void |
stepMessage(String message)
|
static void |
tearDown(boolean passed,
String sessionId,
String poolParamTest,
String poolParamUser,
String className,
String testName)
Calls SauceLabsWebDriverHelper.tearDown(boolean, java.lang.String, java.lang.String, java.lang.String) if REMOTE_PUBLIC_USERPOOL_PROPERTY is enabled, calls a user pool
url with the given poolParamTest and poolParamUser. |
static org.openqa.selenium.WebElement |
waitAndGetElementByAttributeValue(org.openqa.selenium.WebDriver driver,
String attribute,
String attributeValue,
int waitSeconds)
Return the WebElement that has the attribute name with the given value within the given seconds to wait. |
static org.openqa.selenium.WebElement |
waitFor(org.openqa.selenium.WebDriver driver,
int waitSeconds,
org.openqa.selenium.By by,
String message)
Wait for the given amount of seconds, for the given by, using the given driver. |
static List<org.openqa.selenium.WebElement> |
waitFors(org.openqa.selenium.WebDriver driver,
org.openqa.selenium.By by)
Wait for WebElements. |
static List<org.openqa.selenium.WebElement> |
waitFors(org.openqa.selenium.WebDriver driver,
org.openqa.selenium.By by,
String message)
Wait for WebElements. |
static List<org.openqa.selenium.WebElement> |
waitFors(org.openqa.selenium.WebDriver driver,
int waitSeconds,
org.openqa.selenium.By by,
String message)
Wait for the given amount of seconds, for the given by, using the given driver. |
static void |
waitToAcceptAlert(org.openqa.selenium.WebDriver driver,
int waitSeconds,
String message)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static SauceLabsWebDriverHelper saucelabs
public static boolean jGrowlEnabled
public static boolean jsHighlightEnabled
public static final String DEFAULT_BASE_URL
public static final String DEFAULT_BASE_URL_KRAD
public static final String DONT_TEAR_DOWN_PROPERTY
Set to true to not close the browser after the test has run.
-Dremote.driver.dontTearDown=true
public static final String DONT_TEAR_DOWN_ON_FAILURE_PROPERTY
Set to true to not close the browser after the test has if the test failed.
-Dremote.driver.dontTearDownOnFailure=true
public static final String HUB_DRIVER_PROPERTY
public static final String HUB_PROPERTY
public static final String HUB_URL_PROPERTY
public static int IMPLICIT_WAIT_TIME_LOOP_MS
public static int IMPLICIT_WAIT_TIME_SECONDS_DEFAULT
IMPLICIT_WAIT_TIME_SECONDS_DEFAULT
to configure, default 30 seconds.
In code don't use this variable but call configuredImplicityWait
to get the configured value.
public static final boolean JGROWL_ERROR_FAILURE
public static final String JS_HIGHLIGHT_BACKGROUND
public static final String JS_HIGHLIGHT_BOARDER
public static final int JS_HIGHLIGHT_MS
public static final String JS_HIGHLIGHT_MS_PROPERTY
JS_HIGHLIGHT_MS
as default.
-Dremote.driver.highlight.ms=
public static final String JS_HIGHLIGHT_PROPERTY
Highlighting of elements as selenium runs.
-Dremote.driver.highlight=true
public static final String JS_HIGHLIGHT_INPUT_PROPERTY
public static final String PROXY_HOST_PROPERTY
Local proxy used for running tests thru jmeter.
Include host name and port number. Example: localhost:7777
-Dremote.public.proxy=
public static final String REMOTE_AUTOLOGIN_PROPERTY
Skip automatice login if set to anything other than true/
-Dremote.autologin=false
public static final String REMOTE_JGROWL_ENABLED
Set to true to enable jGrowl test messages.
When enabled, jGrowl messages will be sent when clicking on buttons and links identified by their text.
-Dremote.jgrowl.enabled=true
public static final String REMOTE_LOGIN_UIF
public static final String REMOTE_PROPERTIES_PROPERTY
public static final String REMOTE_PUBLIC_CHROME
public static final String REMOTE_PUBLIC_URL_PROPERTY
public static final String REMOTE_PUBLIC_WAIT_SECONDS_PROPERTY
Set -Dremote.public.wait.seconds to override DEFAULT_WAIT_SEC.
IMPLICIT_WAIT_TIME_SECONDS_DEFAULT
public static final String REMOTE_PUBLIC_USER_PROPERTY
public static final String REMOTE_PUBLIC_USERPOOL_PROPERTY
public static final int SETUP_URL_LOAD_WAIT_SECONDS
Time to wait for the URL used in setup to load, 120 seconds by default.
Sometimes this is the first hit on the app and it needs a bit longer than any other.
TODO parametrize for JVM Arg
public static final String WEBDRIVER_CHROME_DRIVER
Constructor Detail |
---|
public WebDriverUtils()
Method Detail |
---|
public static org.openqa.selenium.WebDriver setUp(String username, String url) throws Exception
username
- url
-
Exception
public static org.openqa.selenium.WebDriver setUp(String username, String url, String className, String testName) throws Exception
username
- url
- className
- testName
-
Exception
public static void tearDown(boolean passed, String sessionId, String poolParamTest, String poolParamUser, String className, String testName) throws Exception
Calls SauceLabsWebDriverHelper.tearDown(boolean, java.lang.String, java.lang.String, java.lang.String)
if REMOTE_PUBLIC_USERPOOL_PROPERTY
is enabled, calls a user pool
url with the given poolParamTest and poolParamUser.
passed
- used by SauceLabsWebDriverHelper.tearDown(boolean, java.lang.String, java.lang.String, java.lang.String)
to record Saucelabs test status can be null if Saucelabs
is not being usedsessionId
- used by SauceLabsWebDriverHelper.tearDown(boolean, java.lang.String, java.lang.String, java.lang.String)
to record Saucelabs sessionId status can be null if Saucelabs
is not being usedpoolParamTest
- can be null unless a user pool is being usedpoolParamUser
- can be null unless a user pool is being used
Exception
public static void acceptAlertIfPresent(org.openqa.selenium.WebDriver driver)
If an alert is present accept it print the alert text to System.out
driver
- to accept alert onpublic static void alertAccept(org.openqa.selenium.WebDriver driver)
Accept the javascript alert (clicking OK).
driver
- WebDriver to accept alert onpublic static void alertDismiss(org.openqa.selenium.WebDriver driver)
Dismiss the javascript alert (clicking Cancel).
driver
- WebDriver to dismiss alert onpublic static String alertText(org.openqa.selenium.WebDriver driver)
Return alert text.
driver
- to get alert text from
public static org.openqa.selenium.chrome.ChromeDriverService chromeDriverCreateCheck()
ChromeDriver downloads, REMOTE_PUBLIC_CHROME
,
WEBDRIVER_CHROME_DRIVER
, and HUB_DRIVER_PROPERTY
public static int configuredImplicityWait()
Return the configured implicity wait seconds, REMOTE_PUBLIC_WAIT_SECONDS_PROPERTY
and IMPLICIT_WAIT_TIME_SECONDS_DEFAULT
.
public static String deLinespace(String contents)
Remove double line spacing.
contents
- String to remove double line spacing from
public static String determineUser(String testParam)
If REMOTE_PUBLIC_USER_PROPERTY
property is set, return its value, else if REMOTE_PUBLIC_USERPOOL_PROPERTY
is set use it to query the userpool service passing the testParam.
testParam
- to use if using a user pool
public static boolean dontTearDownPropertyNotSet()
Setting the JVM arg remote.driver.dontTearDown to y or t leaves the browser window open when the test has completed.
Valuable when debugging, updating, or creating new tests. When implementing your own tearDown method rather than an inherited one, it is a common courtesy to include this check and not stop and shutdown the browser window to make it easy debug or update your test.
public static boolean dontTearDownOnFailure(boolean passed)
DONT_TEAR_DOWN_ON_FAILURE_PROPERTY
is set to something other
than n, don't tear down the browser window on a test failure.
passed
-
public static org.openqa.selenium.WebElement findButtonByText(org.openqa.selenium.WebDriver driver, String buttonText)
Find Button by text.
driver
- to find button onbuttonText
- text to find button by
public static org.openqa.selenium.WebElement findElement(org.openqa.selenium.WebDriver driver, org.openqa.selenium.By by)
Find and highlight the WebElement using the given WebDriver and By.
driver
- driver to find onby
- selector to find
public static String getBaseUrlString()
In order to run as a smoke test the ability to set the baseUrl via the JVM arg remote.public.url is required.
Trailing slashes are trimmed. If the remote.public.url does not start with http:// it will be added.
public static org.openqa.selenium.WebElement getElementByAttributeValue(org.openqa.selenium.WebDriver driver, String attributeName, String value)
Return the WebElement that has the attribute name with the given value.
driver
- to get element fromattributeName
- attribute name to find element byvalue
- for the attribute name to find element by
public static String getHubUrlString()
In order to run as a smoke test under selenium grid the ability to set the hubUrl via the JVM arg remote.public.hub is required.
Trailing slashes are trimmed. If the remote.public.hub does not start with http:// it will be added.
public static org.openqa.selenium.WebDriver getWebDriver()
remote.public.driver set to chrome or firefox (null assumes firefox).
if remote.public.hub is set a RemoteWebDriver is created (Selenium Grid) if proxy.host is set, the web driver is setup to use a proxy
public static void highlightElement(org.openqa.selenium.WebDriver webDriver, org.openqa.selenium.By by)
public static void highlightElements(org.openqa.selenium.WebDriver webDriver, List<org.openqa.selenium.WebElement> webElements)
public static void highlightElement(org.openqa.selenium.WebDriver webDriver, org.openqa.selenium.WebElement webElement)
Highlight given WebElement.
webDriver
- to execute highlight onwebElement
- to highlightpublic static boolean isAlertPresent(org.openqa.selenium.WebDriver driver)
Return true if an alert is present, false if not.
driver
- to check for presents of alert on
public static Boolean isTextPresent(org.openqa.selenium.WebDriver driver, String pageText, String text)
public static void jGrowl(org.openqa.selenium.WebDriver driver, String jGrowlHeader, boolean sticky, String message, Throwable throwable)
Display jGrowl.
driver
- WebDriver to execute jGrowl onjGrowlHeader
- header text for jGrowlsticky
- true to set the jGrowl to sticky, false for not stickymessage
- message to display in the jGrowlthrowable
- message and stacktrace to included in jGrowlpublic static void jGrowl(org.openqa.selenium.WebDriver driver, String jGrowlHeader, boolean sticky, String message)
Display jGrowl.
driver
- WebDriver to execute jGrowl onjGrowlHeader
- header text for jGrowlsticky
- true to set the jGrowl to sticky, false for not stickymessage
- message to display in the jGrowlpublic static void jGrowlException(Throwable throwable)
Print jGrowl Excetion to System.out, if JGROWL_ERROR_FAILURE
is set to true, fail.
throwable
- message and stack trace to print and if configured fail withpublic static void selectFrameSafe(org.openqa.selenium.WebDriver driver, String locator)
Select frame defined by locator without throwing an Exception if it doesn't exist.
driver
- to select frame onlocator
- to identify frame to selectpublic static void stepMessage(String message)
public static org.openqa.selenium.WebElement waitAndGetElementByAttributeValue(org.openqa.selenium.WebDriver driver, String attribute, String attributeValue, int waitSeconds) throws InterruptedException
Return the WebElement that has the attribute name with the given value within the given seconds to wait.
driver
- to get element fromattribute
- name to find element byattributeValue
- for the attribute name to find element bywaitSeconds
- number of seconds to wait
InterruptedException
public static void waitToAcceptAlert(org.openqa.selenium.WebDriver driver, int waitSeconds, String message) throws InterruptedException
InterruptedException
public static org.openqa.selenium.WebElement waitFor(org.openqa.selenium.WebDriver driver, int waitSeconds, org.openqa.selenium.By by, String message) throws InterruptedException
Wait for the given amount of seconds, for the given by, using the given driver. The message is displayed if the by cannot be found. No action is performed on the by, so it is possible that the by found is not visible or enabled.
driver
- WebDriver to wait onwaitSeconds
- seconds to waitby
- By to wait formessage
- to display if by is not found in waitSeconds
InterruptedException
public static List<org.openqa.selenium.WebElement> waitFors(org.openqa.selenium.WebDriver driver, org.openqa.selenium.By by) throws InterruptedException
Wait for WebElements.
driver
- WebDriver to wait onby
- By to wait for
InterruptedException
public static List<org.openqa.selenium.WebElement> waitFors(org.openqa.selenium.WebDriver driver, org.openqa.selenium.By by, String message) throws InterruptedException
Wait for WebElements.
driver
- WebDriver to wait onby
- By to wait formessage
- to display if by is not found in waitSeconds
InterruptedException
public static List<org.openqa.selenium.WebElement> waitFors(org.openqa.selenium.WebDriver driver, int waitSeconds, org.openqa.selenium.By by, String message) throws InterruptedException
Wait for the given amount of seconds, for the given by, using the given driver. The message is displayed if the by cannot be found. No action is performed on the by, so it is possible that the by found is not visible or enabled.
driver
- WebDriver to wait onwaitSeconds
- seconds to waitby
- By to wait formessage
- to display if by is not found in waitSeconds
InterruptedException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |