Class DriverHelper
- java.lang.Object
-
- com.qaprosoft.carina.core.foundation.webdriver.DriverHelper
-
- Direct Known Subclasses:
AbstractUIObject
public class DriverHelper extends java.lang.Object
DriverHelper - WebDriver wrapper for logging and reporting features. Also it contains some complex operations with UI.- Author:
- Alex Khursevich
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.String
CRYPTO_PATTERN
protected com.zebrunner.carina.crypto.CryptoTool
cryptoTool
protected org.openqa.selenium.WebDriver
driver
protected static long
EXPLICIT_TIMEOUT
protected java.lang.String
pageURL
protected static long
RETRY_TIME
protected static long
SHORT_TIMEOUT
protected long
timer
-
Constructor Summary
Constructors Constructor Description DriverHelper()
DriverHelper(org.openqa.selenium.WebDriver driver)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
acceptAlert()
Accepts alert modal.void
addCookie(org.openqa.selenium.Cookie cookie)
boolean
allElementListsAreNotEmpty(long timeout, java.util.List<ExtendedWebElement>... elements)
Method which quickly looks for all element lists and check that they contain at least one element during timeoutboolean
allElementListsAreNotEmpty(java.util.List<ExtendedWebElement>... elements)
Method which quickly looks for all element lists and check that they contain at least one element during SHORT_TIMEOUTboolean
allElementsPresent(long timeout, ExtendedWebElement... elements)
Method which quickly looks for all element and check that they present during timeout secboolean
allElementsPresent(ExtendedWebElement... elements)
Method which quickly looks for all element and check that they present during EXPLICIT_TIMEOUTvoid
assertElementPresent(ExtendedWebElement extWebElement)
void
assertElementPresent(ExtendedWebElement extWebElement, long timeout)
void
assertElementWithTextPresent(ExtendedWebElement extWebElement, java.lang.String text)
void
assertElementWithTextPresent(ExtendedWebElement extWebElement, java.lang.String text, long timeout)
void
cancelAlert()
Cancels alert modal.void
clickAny(long timeout, ExtendedWebElement... elements)
Clicks on element.void
clickAny(ExtendedWebElement... elements)
Clicks on element.void
dragAndDrop(ExtendedWebElement from, ExtendedWebElement to)
Drags and drops element to specified place.void
dragAndDropHtml5(ExtendedWebElement from, ExtendedWebElement to)
Drags and drops element to specified place.ExtendedWebElement
findExtendedWebElement(org.openqa.selenium.By by)
Find element on the page
Element search is limited by theConfiguration.Parameter.EXPLICIT_TIMEOUT
ExtendedWebElement
findExtendedWebElement(org.openqa.selenium.By by, long timeout)
Find element on the pageExtendedWebElement
findExtendedWebElement(org.openqa.selenium.By by, java.lang.String name)
Find element on the page
Element search is limited by theConfiguration.Parameter.EXPLICIT_TIMEOUT
ExtendedWebElement
findExtendedWebElement(org.openqa.selenium.By by, java.lang.String name, long timeout)
Find element on the pagejava.util.List<ExtendedWebElement>
findExtendedWebElements(org.openqa.selenium.By by)
Find elements on the page
Elements search is limited by theConfiguration.Parameter.EXPLICIT_TIMEOUT
java.util.List<ExtendedWebElement>
findExtendedWebElements(org.openqa.selenium.By by, long timeout)
Find elements on the pagejava.lang.String
getClipboardText()
java.lang.String
getCurrentUrl()
Get a string representing the current URL that the browser is looking at.java.lang.String
getCurrentUrl(long timeout)
Get a string representing the current URL that the browser is looking at.org.openqa.selenium.WebDriver
getDriver()
java.lang.String
getPageSource()
java.lang.String
getPageURL()
java.lang.String
getTitle()
Return page title.java.lang.String
getTitle(long timeout)
Return page title.boolean
isAlertPresent()
Checks that alert modal is shown.boolean
isAnyElementPresent(long timeout, ExtendedWebElement... elements)
Method which quickly looks for any element presence during timeout secboolean
isAnyElementPresent(ExtendedWebElement... elements)
Method which quickly looks for any element presence during SHORT_TIMEOUTboolean
isElementNotPresent(ExtendedWebElement extWebElement)
Check that element not present on page.boolean
isElementNotPresent(ExtendedWebElement extWebElement, long timeout)
Check that element not present on page.boolean
isElementNotPresent(java.lang.String controlInfo, org.openqa.selenium.WebElement element)
Check that element not present on page.boolean
isElementWithTextPresent(ExtendedWebElement extWebElement, java.lang.String text)
Check that element with text present.boolean
isElementWithTextPresent(ExtendedWebElement extWebElement, java.lang.String text, long timeout)
Check that element with text present.boolean
isPageOpened(AbstractPage page)
boolean
isPageOpened(AbstractPage page, long timeout)
boolean
isTitleAsExpected(java.lang.String expectedTitle)
Checks that page title is as expected.boolean
isTitleAsExpectedPattern(java.lang.String expectedPattern)
Checks that page suites to expected pattern.boolean
isUrlAsExpected(java.lang.String expectedURL)
Checks that current URL is as expected.boolean
isUrlAsExpected(java.lang.String expectedURL, long timeout)
Checks that current URL is as expected.void
navigateBack()
Go back in browser.void
open()
Opens page according to specified in constructor URL.void
openTab(java.lang.String url)
Opens a new tab for the given URLvoid
openURL(java.lang.String url)
Open URL.void
openURL(java.lang.String url, long timeout)
Open URL.void
pause(long timeout)
Pause for specified timeout.void
pause(java.lang.Double timeout)
<T> T
performIgnoreException(java.util.function.Supplier<T> supplier)
void
pressTab()
void
refresh()
Refresh browser.void
refresh(long timeout)
Refresh browser.ExtendedWebElement
returnAnyPresentElement(long timeout, ExtendedWebElement... elements)
return Any Present Element from the list which present during timeout secExtendedWebElement
returnAnyPresentElement(ExtendedWebElement... elements)
return Any Present Element from the list which present during SHORT_TIMEOUTboolean
setClipboardText(java.lang.String text)
Set text to clipboardprotected void
setDriver(org.openqa.selenium.WebDriver driver)
protected void
setPageAbsoluteURL(java.lang.String url)
protected void
setPageURL(java.lang.String relURL)
void
slide(ExtendedWebElement slider, int moveX, int moveY)
Performs slider move for specified offset.void
switchWindow()
java.lang.Object
trigger(java.lang.String script)
Executes a script Really should only be used when the web driver is sucking at exposing functionality nativelyjava.lang.Object
trigger(java.lang.String script, org.openqa.selenium.WebElement element)
Executes a script on an element Really should only be used when the web driver is sucking at exposing functionality nativelyboolean
waitUntil(org.openqa.selenium.support.ui.ExpectedCondition<?> condition, long timeout)
Wait until any condition happens.
-
-
-
Field Detail
-
EXPLICIT_TIMEOUT
protected static final long EXPLICIT_TIMEOUT
-
SHORT_TIMEOUT
protected static final long SHORT_TIMEOUT
-
RETRY_TIME
protected static final long RETRY_TIME
-
timer
protected long timer
-
driver
protected org.openqa.selenium.WebDriver driver
-
pageURL
protected java.lang.String pageURL
-
cryptoTool
protected com.zebrunner.carina.crypto.CryptoTool cryptoTool
-
CRYPTO_PATTERN
protected static java.lang.String CRYPTO_PATTERN
-
-
Method Detail
-
open
public void open()
Opens page according to specified in constructor URL.
-
openURL
public void openURL(java.lang.String url)
Open URL.- Parameters:
url
- to open.
-
openURL
public void openURL(java.lang.String url, long timeout)
Open URL.- Parameters:
url
- to open.timeout
- long
-
setPageURL
protected void setPageURL(java.lang.String relURL)
-
setPageAbsoluteURL
protected void setPageAbsoluteURL(java.lang.String url)
-
getPageURL
public java.lang.String getPageURL()
-
allElementsPresent
public boolean allElementsPresent(ExtendedWebElement... elements)
Method which quickly looks for all element and check that they present during EXPLICIT_TIMEOUT- Parameters:
elements
- ExtendedWebElement...- Returns:
- boolean return true only if all elements present.
-
allElementsPresent
public boolean allElementsPresent(long timeout, ExtendedWebElement... elements)
Method which quickly looks for all element and check that they present during timeout sec- Parameters:
timeout
- longelements
- ExtendedWebElement...- Returns:
- boolean return true only if all elements present.
-
allElementListsAreNotEmpty
public boolean allElementListsAreNotEmpty(java.util.List<ExtendedWebElement>... elements)
Method which quickly looks for all element lists and check that they contain at least one element during SHORT_TIMEOUT- Parameters:
elements
- List<ExtendedWebElement>...- Returns:
- boolean
-
allElementListsAreNotEmpty
public boolean allElementListsAreNotEmpty(long timeout, java.util.List<ExtendedWebElement>... elements)
Method which quickly looks for all element lists and check that they contain at least one element during timeout- Parameters:
timeout
- longelements
- List<ExtendedWebElement>...- Returns:
- boolean return true only if All Element lists contain at least one element
-
isAnyElementPresent
public boolean isAnyElementPresent(ExtendedWebElement... elements)
Method which quickly looks for any element presence during SHORT_TIMEOUT- Parameters:
elements
- ExtendedWebElement...- Returns:
- true if any of elements was found.
-
isAnyElementPresent
public boolean isAnyElementPresent(long timeout, ExtendedWebElement... elements)
Method which quickly looks for any element presence during timeout sec- Parameters:
timeout
- longelements
- ExtendedWebElement...- Returns:
- true if any of elements was found.
-
returnAnyPresentElement
public ExtendedWebElement returnAnyPresentElement(ExtendedWebElement... elements)
return Any Present Element from the list which present during SHORT_TIMEOUT- Parameters:
elements
- ExtendedWebElement...- Returns:
- ExtendedWebElement
-
returnAnyPresentElement
public ExtendedWebElement returnAnyPresentElement(long timeout, ExtendedWebElement... elements)
return Any Present Element from the list which present during timeout sec- Parameters:
timeout
- longelements
- ExtendedWebElement...- Returns:
- ExtendedWebElement
-
isElementWithTextPresent
public boolean isElementWithTextPresent(ExtendedWebElement extWebElement, java.lang.String text)
Check that element with text present.- Parameters:
extWebElement
- to check if element with text is presenttext
- of element to check.- Returns:
- element with text existence status.
-
isElementWithTextPresent
public boolean isElementWithTextPresent(ExtendedWebElement extWebElement, java.lang.String text, long timeout)
Check that element with text present.- Parameters:
extWebElement
- to check if element with text is presenttext
- of element to check.timeout
- Long- Returns:
- element with text existence status.
-
isElementNotPresent
public boolean isElementNotPresent(ExtendedWebElement extWebElement)
Check that element not present on page.- Parameters:
extWebElement
- to check if element is not present- Returns:
- element non-existence status.
-
isElementNotPresent
public boolean isElementNotPresent(ExtendedWebElement extWebElement, long timeout)
Check that element not present on page.- Parameters:
extWebElement
- to check if element is not presenttimeout
- to wait- Returns:
- element non-existence status.
-
isElementNotPresent
public boolean isElementNotPresent(java.lang.String controlInfo, org.openqa.selenium.WebElement element)
Check that element not present on page.- Parameters:
element
- to check if element is not presentcontrolInfo
- String- Returns:
- element non-existence status.
-
clickAny
public void clickAny(ExtendedWebElement... elements)
Clicks on element.- Parameters:
elements
- ExtendedWebElements to click
-
clickAny
public void clickAny(long timeout, ExtendedWebElement... elements)
Clicks on element.- Parameters:
elements
- ExtendedWebElements to clicktimeout
- to wait
-
getPageSource
public java.lang.String getPageSource()
-
addCookie
public void addCookie(org.openqa.selenium.Cookie cookie)
-
getCurrentUrl
public java.lang.String getCurrentUrl()
Get a string representing the current URL that the browser is looking at.- Returns:
- url.
-
getCurrentUrl
public java.lang.String getCurrentUrl(long timeout)
Get a string representing the current URL that the browser is looking at.- Parameters:
timeout
- long- Returns:
- validation result.
-
isUrlAsExpected
public boolean isUrlAsExpected(java.lang.String expectedURL)
Checks that current URL is as expected.- Parameters:
expectedURL
- Expected Url- Returns:
- validation result.
-
isUrlAsExpected
public boolean isUrlAsExpected(java.lang.String expectedURL, long timeout)
Checks that current URL is as expected.- Parameters:
expectedURL
- Expected Urltimeout
- long- Returns:
- validation result.
-
getClipboardText
public java.lang.String getClipboardText()
- Returns:
- String saved in clipboard
-
setClipboardText
public boolean setClipboardText(java.lang.String text)
Set text to clipboard- Parameters:
text
- text- Returns:
- true if successfull, false otherwise
-
pause
public void pause(long timeout)
Pause for specified timeout.- Parameters:
timeout
- in seconds.
-
pause
public void pause(java.lang.Double timeout)
-
getTitle
public java.lang.String getTitle()
Return page title.- Returns:
- title String.
-
getTitle
public java.lang.String getTitle(long timeout)
Return page title.- Parameters:
timeout
- long- Returns:
- title String.
-
isTitleAsExpected
public boolean isTitleAsExpected(java.lang.String expectedTitle)
Checks that page title is as expected.- Parameters:
expectedTitle
- Expected title- Returns:
- validation result.
-
isTitleAsExpectedPattern
public boolean isTitleAsExpectedPattern(java.lang.String expectedPattern)
Checks that page suites to expected pattern.- Parameters:
expectedPattern
- Expected Pattern- Returns:
- validation result.
-
navigateBack
public void navigateBack()
Go back in browser.
-
refresh
public void refresh()
Refresh browser.
-
refresh
public void refresh(long timeout)
Refresh browser.- Parameters:
timeout
- long
-
pressTab
public void pressTab()
-
dragAndDrop
public void dragAndDrop(ExtendedWebElement from, ExtendedWebElement to)
Drags and drops element to specified place.- Parameters:
from
- - element to drag.to
- - element to drop to.
-
dragAndDropHtml5
public void dragAndDropHtml5(ExtendedWebElement from, ExtendedWebElement to)
Drags and drops element to specified place. Elements Need To have an id.- Parameters:
from
- - the element to drag.to
- - the element to drop to.
-
slide
public void slide(ExtendedWebElement slider, int moveX, int moveY)
Performs slider move for specified offset.- Parameters:
slider
- slidermoveX
- move xmoveY
- move y
-
acceptAlert
public void acceptAlert()
Accepts alert modal.
-
cancelAlert
public void cancelAlert()
Cancels alert modal.
-
isAlertPresent
public boolean isAlertPresent()
Checks that alert modal is shown.- Returns:
- whether the alert modal present.
-
isPageOpened
public boolean isPageOpened(AbstractPage page)
-
isPageOpened
public boolean isPageOpened(AbstractPage page, long timeout)
-
trigger
public java.lang.Object trigger(java.lang.String script, org.openqa.selenium.WebElement element)
Executes a script on an element Really should only be used when the web driver is sucking at exposing functionality natively- Parameters:
script
- The script to executeelement
- The target of the script, referenced as arguments[0]- Returns:
- Object
-
trigger
public java.lang.Object trigger(java.lang.String script)
Executes a script Really should only be used when the web driver is sucking at exposing functionality natively- Parameters:
script
- The script to execute- Returns:
- Object
-
openTab
public void openTab(java.lang.String url)
Opens a new tab for the given URL- Parameters:
url
- The URL to- Throws:
java.lang.RuntimeException
- If unable to open tab
-
switchWindow
public void switchWindow() throws org.openqa.selenium.NoSuchWindowException
- Throws:
org.openqa.selenium.NoSuchWindowException
-
assertElementPresent
public void assertElementPresent(ExtendedWebElement extWebElement)
-
assertElementPresent
public void assertElementPresent(ExtendedWebElement extWebElement, long timeout)
-
assertElementWithTextPresent
public void assertElementWithTextPresent(ExtendedWebElement extWebElement, java.lang.String text)
-
assertElementWithTextPresent
public void assertElementWithTextPresent(ExtendedWebElement extWebElement, java.lang.String text, long timeout)
-
findExtendedWebElement
public ExtendedWebElement findExtendedWebElement(org.openqa.selenium.By by)
Find element on the page
Element search is limited by theConfiguration.Parameter.EXPLICIT_TIMEOUT
- Parameters:
by
- seeBy
- Returns:
ExtendedWebElement
if exists,null
otherwise
-
findExtendedWebElement
public ExtendedWebElement findExtendedWebElement(org.openqa.selenium.By by, long timeout)
Find element on the page- Parameters:
by
- seeBy
timeout
- time to wait, in seconds- Returns:
ExtendedWebElement
if exists,null
otherwise
-
findExtendedWebElement
public ExtendedWebElement findExtendedWebElement(org.openqa.selenium.By by, java.lang.String name)
Find element on the page
Element search is limited by theConfiguration.Parameter.EXPLICIT_TIMEOUT
- Parameters:
by
- seeBy
name
- the name that will be given to the found element- Returns:
ExtendedWebElement
if exists,null
otherwise
-
findExtendedWebElement
public ExtendedWebElement findExtendedWebElement(org.openqa.selenium.By by, java.lang.String name, long timeout)
Find element on the page- Parameters:
by
- seeBy
name
- the name that will be given to the found elementtimeout
- time to wait, in seconds- Returns:
ExtendedWebElement
if exists,null
otherwise
-
findExtendedWebElements
public java.util.List<ExtendedWebElement> findExtendedWebElements(org.openqa.selenium.By by)
Find elements on the page
Elements search is limited by theConfiguration.Parameter.EXPLICIT_TIMEOUT
- Parameters:
by
- seeBy
- Returns:
- list of
ExtendedWebElement
s, empty list otherwise
-
findExtendedWebElements
public java.util.List<ExtendedWebElement> findExtendedWebElements(org.openqa.selenium.By by, long timeout)
Find elements on the page- Parameters:
by
- seeBy
timeout
- time to wait, in seconds- Returns:
- list of
ExtendedWebElement
s if found, empty list otherwise
-
setDriver
protected void setDriver(org.openqa.selenium.WebDriver driver)
-
getDriver
public org.openqa.selenium.WebDriver getDriver()
-
waitUntil
public boolean waitUntil(org.openqa.selenium.support.ui.ExpectedCondition<?> condition, long timeout)
Wait until any condition happens.- Parameters:
condition
- - ExpectedCondition.timeout
- - timeout.- Returns:
- true if condition happen.
-
performIgnoreException
public <T> T performIgnoreException(java.util.function.Supplier<T> supplier)
-
-