public class Browser extends Object implements BrowserContext
WebDriver. It is configured using
BrowserConfiguration. Controls automatic reporting using listeners
provided by configuration.| Modifier and Type | Field and Description |
|---|---|
protected String |
baseUrl |
protected String |
baseUrlRegex |
protected BrowserConfiguration |
configuration |
protected Map<String,Object> |
dataHolder |
static String |
DEFAULT_CONFIGURATION_KEY |
protected org.openqa.selenium.WebDriver |
driver |
protected BrowserElementLoader |
elementLoader |
static DateTimeFormatter |
FILE_DATE_FORMATTER |
protected com.thoughtworks.selenium.webdriven.JavascriptLibrary |
javascriptLibrary |
protected String |
label |
static String |
LABEL_DELIMITER |
protected List<BrowserListener> |
listeners |
protected Page |
page |
static String |
PROPERTIES_CONFIGURATION_KEY |
protected File |
reportDir |
protected boolean |
reported |
protected boolean |
urlVerification |
protected BrowserUtils |
utils |
protected double |
waitRetryInterval |
protected double |
waitTimeout |
| Constructor and Description |
|---|
Browser()
Constructs a new instance with default configuration.
|
Browser(BrowserConfiguration configuration)
Constructs a new instance and configures it.
|
Browser(Class<T> configCls)
Constructs a new instance with configuration constructed
from given class.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(BrowserListener listener)
Adds listener.
|
protected void |
applyConfiguration(BrowserConfiguration configuration) |
void |
assertAt(Class<?> page)
Asserts that actual page is a given class.
|
void |
checkIfPresent(org.openqa.selenium.WebElement element)
Checks if element exists on actual page.
|
<T extends BrowserElement> |
constructBrowserElement(Class<T> element,
BrowserContext context,
org.openqa.selenium.WebElement webElement,
boolean optional) |
<T extends BrowserEvent> |
constructEvent(Class<T> eventCls,
BrowserContext context)
Constructs a new instance of
BrowserEvent subclass with given
context and local time. |
<T extends Logic> |
constructLogic(Class<T> logic,
BrowserContext context) |
<T extends Page> |
constructPage(Class<T> page)
Construct page defined by class.
|
protected org.openqa.selenium.WebDriver |
createDriver() |
org.openqa.selenium.support.pagefactory.ElementLocator |
createElementLocator(org.openqa.selenium.SearchContext searchContext,
org.openqa.selenium.By by) |
org.openqa.selenium.support.pagefactory.ElementLocator |
createElementLocator(org.openqa.selenium.SearchContext searchContext,
org.openqa.selenium.By by,
boolean lookupCached) |
org.openqa.selenium.support.pagefactory.ElementLocator |
createElementLocator(org.openqa.selenium.SearchContext searchContext,
Field field) |
protected String |
escapeFileName(String name) |
<T extends BrowserElement> |
find(BrowserContext context,
org.openqa.selenium.By by,
Class<T> elementCls)
Find all elements within the given context using the given mechanism
as instances of the given
BrowserElement or its subclass. |
org.openqa.selenium.WebElement |
findElement(org.openqa.selenium.By by) |
List<org.openqa.selenium.WebElement> |
findElements(org.openqa.selenium.By by) |
<T extends BrowserElement> |
findOne(BrowserContext context,
org.openqa.selenium.By by,
Class<T> elementCls,
boolean optional)
Find the first element within the given context using the given mechanism
as instance of the given
BrowserElement or its subclass. |
String |
getBaseUrl()
Base URL for pages.
|
String |
getBaseUrlRegex()
Base URL regex for pages.
|
Browser |
getBrowser()
Returns
Browser instance. |
BrowserConfiguration |
getConfiguration()
Returns
BrowserConfiguration instance. |
<T> T |
getConfiguration(Class<T> configuration)
Returns
BrowserConfiguration instance casted to specific type. |
BrowserContext |
getContext()
Returns parent
BrowserContext instance. |
Map<String,Object> |
getDataHolder()
Returns map which holds data.
|
org.openqa.selenium.WebDriver |
getDriver()
Returns wrapped
WebDriver instance. |
<T> T |
getDriver(Class<T> driver)
Returns wrapped
WebDriver instance casted to specific type. |
BrowserElementLoader |
getElementLoader() |
protected Path |
getFilePath(String name,
String extension) |
com.thoughtworks.selenium.webdriven.JavascriptLibrary |
getJavascriptLibrary() |
String |
getLabel()
Browser label which is mainly used for reporting.
|
Page |
getPage()
Returns actual page or null if browser
has no page initiated.
|
<T> T |
getPage(Class<T> page)
Returns actual page casted to given
type or null if browser has no page
initiated.
|
String |
getProperty(String key)
Returns property as
String. |
File |
getReportDir()
Returns reporting directory, which is used as root
directory for files stored using
BrowserContext.saveFile(File, String, String)
and similar methods. |
protected Path |
getUniqueFilePath(String name,
String extension) |
BrowserUtils |
getUtils()
Returns utils instance.
|
double |
getWaitRetryInterval()
Returns default wait retry interval.
|
double |
getWaitTimeout()
Returns default wait timeout.
|
<T extends Page> |
goTo(Class<T> page)
Go to page defined by class.
|
<T extends Page> |
goTo(T page)
Go to already constructed page.
|
<T extends Page> |
goToSafely(Class<T> page)
Safely go to page defined by class.
|
<T extends Page> |
goToSafely(T page)
Safely go to already constructed page.
|
void |
goToUrl(String url)
Go to specific URL.
|
protected void |
init(BrowserConfiguration configuration) |
protected <T extends BrowserConfiguration> |
init(Class<T> configCls) |
<T extends BrowserElement> |
initBrowserElement(Class<T> element,
BrowserContext context,
org.openqa.selenium.WebElement webElement,
boolean optional) |
<T extends BrowserElement> |
initBrowserElement(T element)
Initialize already constructed element.
|
protected void |
initDefault() |
void |
initElements(BrowserContext context) |
protected void |
initListeners() |
<T extends Logic> |
initLogic(Class<T> logic,
BrowserContext context) |
<T extends Logic> |
initLogic(T logic)
Initialize logic defined by class.
|
Page |
initOnePage(Object... pages)
Initialize first of matching page.
|
Page |
initOnePageSafely(Object... pages)
Safely initialize first of matching page.
|
<T extends Page> |
initPage(Class<T> page)
Initialize page defined by class.
|
<T extends Page> |
initPage(T page)
Initialize already constructed page.
|
<T extends Page> |
initPageSafely(Class<T> page)
Safely initialize page defined by class.
|
<T extends Page> |
initPageSafely(T page)
Safely initialize already constructed page.
|
boolean |
isAt(Class<?> page)
Check if actual page is a given class.
|
boolean |
isNotPresent(org.openqa.selenium.WebElement element)
Returns true if element does not exists on actual page.
|
boolean |
isPresent(org.openqa.selenium.WebElement element)
Returns true if element exists on actual page.
|
boolean |
isReported()
Is storing files using browser enabled.
|
boolean |
isUrlVerification()
Is URL on pages verified?
|
void |
quit()
Quits browser and wrapped
WebDriver. |
void |
report(BrowserContext context,
String label)
Triggers
OnReportEvent with given context and label. |
void |
saveFile(byte[] bytes,
String name,
String extension)
Saves bytes into named file with extension.
|
void |
saveFile(File file,
String name,
String extension)
Saves file into named file with extension.
|
void |
saveFile(String content,
String name,
String extension)
Saves string into named file with extension.
|
void |
setBaseUrl(String baseUrl)
Updates base URL
|
void |
setBaseUrlRegex(String baseUrlRegex)
Updates base URL regex
|
void |
setLabel(String... labels)
Modify browser label joining given labels.
|
void |
setLabel(String label)
Modify browser label
|
void |
setPage(Page page)
Sets actual browser page.
|
void |
setReported(boolean reported)
Toggles storing files using browser.
|
void |
setUrlVerification(boolean urlVerification)
Toggles pages URL verification.
|
void |
setWaitRetryInterval(double waitRetryInterval)
Sets default wait retry interval.
|
void |
setWaitTimeout(double waitTimeout)
Sets default wait timeout.
|
void |
triggerEvent(BrowserEvent event)
Triggers
BrowserEvent. |
void |
useEnclosingMethodLabel()
Sets label using enclosing method class name and method name.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitconstructBrowserElement, constructEvent, constructLogic, createElementLocator, createElementLocator, createElementLocator, find, find, find, findOne, findOne, findOne, findOne, findOneOptional, findOneOptional, findOneOptional, findOneOptional, getBrowser, getContext, getWrappedDriver, initBrowserElement, initElements, initLogic, report, waiting, waiting, waiting, waitingcastString, getProperty, getProperty, getPropertyaddData, getData, removeDatapublic static final String PROPERTIES_CONFIGURATION_KEY
public static final String DEFAULT_CONFIGURATION_KEY
public static final String LABEL_DELIMITER
public static final DateTimeFormatter FILE_DATE_FORMATTER
protected BrowserConfiguration configuration
protected org.openqa.selenium.WebDriver driver
protected String baseUrl
protected String baseUrlRegex
protected boolean urlVerification
protected double waitTimeout
protected double waitRetryInterval
protected Page page
protected String label
protected boolean reported
protected File reportDir
protected List<BrowserListener> listeners
protected BrowserUtils utils
protected BrowserElementLoader elementLoader
protected com.thoughtworks.selenium.webdriven.JavascriptLibrary javascriptLibrary
public Browser()
BrowserConfiguration with system properties using System.getProperties()
and properties from resource named seleniumbrowser.properties.public Browser(Class<T> configCls)
public Browser(BrowserConfiguration configuration)
configuration - The configurationprotected void initDefault()
protected <T extends BrowserConfiguration> void init(Class<T> configCls)
protected void init(BrowserConfiguration configuration)
protected void applyConfiguration(BrowserConfiguration configuration)
protected void initListeners()
protected org.openqa.selenium.WebDriver createDriver()
public void addListener(BrowserListener listener)
listener - The added listenerpublic String getLabel()
public void setLabel(String label)
label - Browser labelpublic void setLabel(String... labels)
labels - Browser labelspublic String getBaseUrl()
public void setBaseUrl(String baseUrl)
baseUrl - New base URLpublic String getBaseUrlRegex()
public void setBaseUrlRegex(String baseUrlRegex)
baseUrlRegex - New base URL regexpublic boolean isUrlVerification()
public void setUrlVerification(boolean urlVerification)
urlVerification - The new statuspublic double getWaitTimeout()
BrowserContextgetWaitTimeout in interface BrowserContextpublic void setWaitTimeout(double waitTimeout)
waitTimeout - The default wait timeout.public double getWaitRetryInterval()
BrowserContextgetWaitRetryInterval in interface BrowserContextpublic void setWaitRetryInterval(double waitRetryInterval)
waitRetryInterval - The default wait retry interval.public boolean isReported()
public void setReported(boolean reported)
reported - The reported status.public File getReportDir()
BrowserContext.saveFile(File, String, String)
and similar methods.public BrowserUtils getUtils()
getUtils in interface BrowserContextpublic BrowserElementLoader getElementLoader()
public com.thoughtworks.selenium.webdriven.JavascriptLibrary getJavascriptLibrary()
public org.openqa.selenium.support.pagefactory.ElementLocator createElementLocator(org.openqa.selenium.SearchContext searchContext,
Field field)
public org.openqa.selenium.support.pagefactory.ElementLocator createElementLocator(org.openqa.selenium.SearchContext searchContext,
org.openqa.selenium.By by)
public org.openqa.selenium.support.pagefactory.ElementLocator createElementLocator(org.openqa.selenium.SearchContext searchContext,
org.openqa.selenium.By by,
boolean lookupCached)
public void quit()
WebDriver.public void useEnclosingMethodLabel()
public void report(BrowserContext context, String label)
OnReportEvent with given context and label.context - The report contextlabel - The report labelpublic <T extends BrowserEvent> T constructEvent(Class<T> eventCls, BrowserContext context)
BrowserEvent subclass with given
context and local time.eventCls - The event class to constructcontext - The context to usepublic BrowserContext getContext()
BrowserContextBrowserContext instance.getContext in interface BrowserContextpublic Browser getBrowser()
BrowserContextBrowser instance.getBrowser in interface BrowserContextpublic BrowserConfiguration getConfiguration()
BrowserContextBrowserConfiguration instance.getConfiguration in interface BrowserContextpublic <T> T getConfiguration(Class<T> configuration)
BrowserContextBrowserConfiguration instance casted to specific type.getConfiguration in interface BrowserContextpublic org.openqa.selenium.WebDriver getDriver()
BrowserContextWebDriver instance.getDriver in interface BrowserContextpublic <T> T getDriver(Class<T> driver)
BrowserContextWebDriver instance casted to specific type.getDriver in interface BrowserContextpublic Page getPage()
BrowserContextgetPage in interface BrowserContextpublic <T> T getPage(Class<T> page)
BrowserContextgetPage in interface BrowserContextpage - The class to cast the page topublic void setPage(Page page)
BrowserContextsetPage in interface BrowserContextpage - The page to setpublic boolean isAt(Class<?> page)
BrowserContextisAt in interface BrowserContextpage - The class to check the page againstpublic void assertAt(Class<?> page)
BrowserContextAssertionError if condition did not
pass.assertAt in interface BrowserContextpage - The class to check the page againstpublic <T extends Page> T goToSafely(Class<T> page)
BrowserContextgoToSafely in interface BrowserContextpage - The page class to go topublic <T extends Page> T goToSafely(T page)
BrowserContextgoToSafely in interface BrowserContextpage - The page instance to go topublic <T extends Page> T initPageSafely(Class<T> page)
BrowserContextinitPageSafely in interface BrowserContextpage - The page class to initializepublic <T extends Page> T initPageSafely(T page)
BrowserContextinitPageSafely in interface BrowserContextpage - The page instance to initializepublic Page initOnePageSafely(Object... pages)
BrowserContextPage instances.
It iterates over all pages and tries to initialize
and verify them. First verified page is returned.
If none of the pages is verified null is returned.initOnePageSafely in interface BrowserContextpages - The page classes or pages to initializepublic <T extends Page> T goTo(Class<T> page)
BrowserContextgoTo in interface BrowserContextpage - The page class to go topublic <T extends Page> T goTo(T page)
BrowserContextgoTo in interface BrowserContextpage - The page instance to go topublic <T extends Page> T initPage(Class<T> page)
BrowserContextinitPage in interface BrowserContextpage - The page class to initializepublic <T extends Page> T initPage(T page)
BrowserContextinitPage in interface BrowserContextpage - The page instance to initializepublic Page initOnePage(Object... pages)
BrowserContextPage instances.
It iterates over all pages and tries to initialize
and verify them. First verified page is returned.
If none of the pages is verified VerificationException
is thrown.initOnePage in interface BrowserContextpages - The page classes or pages to initializepublic <T extends Page> T constructPage(Class<T> page)
BrowserContextconstructPage in interface BrowserContextpage - The page class to constructpublic <T extends BrowserElement> T initBrowserElement(T element)
BrowserContextinitBrowserElement in interface BrowserContextelement - The element instance to initializepublic <T extends BrowserElement> T initBrowserElement(Class<T> element, BrowserContext context, org.openqa.selenium.WebElement webElement, boolean optional)
public <T extends BrowserElement> T constructBrowserElement(Class<T> element, BrowserContext context, org.openqa.selenium.WebElement webElement, boolean optional)
public <T extends Logic> T initLogic(T logic)
BrowserContextinitLogic in interface BrowserContextlogic - The logic instance to initializepublic <T extends Logic> T initLogic(Class<T> logic, BrowserContext context)
public <T extends Logic> T constructLogic(Class<T> logic, BrowserContext context)
public void initElements(BrowserContext context)
public void checkIfPresent(org.openqa.selenium.WebElement element)
throws org.openqa.selenium.NoSuchElementException
BrowserContextNoSuchElementException.checkIfPresent in interface BrowserContextelement - The element to testorg.openqa.selenium.NoSuchElementException - if element is not presentpublic boolean isPresent(org.openqa.selenium.WebElement element)
BrowserContextBrowserContext.isNotPresent(WebElement).isPresent in interface BrowserContextelement - The element to testtrue if element is presentpublic boolean isNotPresent(org.openqa.selenium.WebElement element)
BrowserContextBrowserContext.isPresent(WebElement).isNotPresent in interface BrowserContextelement - The element to testtrue if element is not presentpublic List<org.openqa.selenium.WebElement> findElements(org.openqa.selenium.By by)
findElements in interface org.openqa.selenium.SearchContextpublic org.openqa.selenium.WebElement findElement(org.openqa.selenium.By by)
findElement in interface org.openqa.selenium.SearchContextpublic <T extends BrowserElement> List<T> find(BrowserContext context, org.openqa.selenium.By by, Class<T> elementCls)
BrowserContextBrowserElement or its subclass.find in interface BrowserContextcontext - The browser context to search inby - The locating mechanism to useelementCls - The element classBrowserElements as instances of the given
BrowserElement or its subclass, or an empty list if nothing matchespublic <T extends BrowserElement> T findOne(BrowserContext context, org.openqa.selenium.By by, Class<T> elementCls, boolean optional)
BrowserContextBrowserElement or its subclass.
If optional is true and no matching elements are found null
is returned instead of throwing NoSuchElementException.findOne in interface BrowserContextcontext - The browser context to search inby - The locating mechanismelementCls - The element classoptional - true for returning null instead of throwing
NoSuchElementException if no matching elements are foundBrowserElement or its subclasspublic void goToUrl(String url)
BrowserContextgoToUrl in interface BrowserContexturl - The URL to go topublic void triggerEvent(BrowserEvent event)
BrowserContextBrowserEvent.triggerEvent in interface BrowserContextevent - The triggered eventpublic Map<String,Object> getDataHolder()
DataSourcegetDataHolder in interface BrowserContextgetDataHolder in interface DataSourcepublic String getProperty(String key)
PropertySourceString.getProperty in interface BrowserContextgetProperty in interface PropertySourcekey - The property key.public void saveFile(String content, String name, String extension)
BrowserContextgetFilePath(String, String).
If isReported() is false
no file is saved.saveFile in interface BrowserContextcontent - The string content to save.name - The file name without extension.extension - The file extension.public void saveFile(byte[] bytes,
String name,
String extension)
BrowserContextgetFilePath(String, String).
If isReported() is false
no file is saved.saveFile in interface BrowserContextbytes - The bytes to save.name - The file name without extension.extension - The file extension.public void saveFile(File file, String name, String extension)
BrowserContextgetFilePath(String, String).
If isReported() is false
no file is saved.saveFile in interface BrowserContextfile - The file to save.name - The file name without extension.extension - The file extension.Copyright © 2016 Etnetera a.s.. All rights reserved.