public class BrowserManagement extends RunOnFailureKeywordsAdapter
| Modifier and Type | Field and Description |
|---|---|
protected Element |
element
Instantiated Element keyword bean
|
protected double |
implicitWait
Implicit wait in milliseconds
|
protected Logging |
logging
Instantiated Logging keyword bean
|
String |
remoteWebDriverProxyDomain |
String |
remoteWebDriverProxyHost |
String |
remoteWebDriverProxyPassword |
String |
remoteWebDriverProxyPort |
String |
remoteWebDriverProxyUser |
String |
remoteWebDriverProxyWorkstation |
protected double |
timeout
Timeout in milliseconds
|
protected WebDriverCache |
webDriverCache
Cache for all open browsers.
|
| Constructor and Description |
|---|
BrowserManagement() |
| Modifier and Type | Method and Description |
|---|---|
void |
addLocationStrategy(String strategyName,
String functionDefinition) |
void |
addLocationStrategy(String strategyName,
String functionDefinition,
String delimiter)
Registers a JavaScript function as locator with the specified strategy
name.
|
void |
closeAllBrowsers()
Closes all open browser instances and resets the browser cache.
|
void |
closeBrowser()
Closes the current browser instance.
|
void |
closeWindow()
Closes the currently open pop-up window.
|
protected org.openqa.selenium.remote.DesiredCapabilities |
createDesiredCapabilities(String browserName,
String desiredCapabilitiesString,
String browserOptions) |
protected org.openqa.selenium.WebDriver |
createLocalWebDriver(String browserName,
org.openqa.selenium.remote.DesiredCapabilities desiredCapabilities) |
protected org.openqa.selenium.WebDriver |
createRemoteWebDriver(org.openqa.selenium.remote.DesiredCapabilities desiredCapabilities,
URL remoteUrl) |
protected org.openqa.selenium.WebDriver |
createWebDriver(String browserName,
String desiredCapabilitiesString,
String remoteUrlString,
String browserOptions) |
org.openqa.selenium.WebDriver |
getCurrentWebDriver() |
String |
getLocation()
Returns the current location.
|
protected String |
getPasswordFromURL(URL url) |
String |
getRemoteCapabilities()
Returns the actually supported capabilities of the remote browser
instance.
|
String |
getRemoteSessionId()
Returns the session id of the remote browser instance.
|
String |
getSeleniumImplicitWait()
Returns the implicit wait time in seconds that is used by Selenium.
|
String |
getSeleniumSpeed()
(NOT IMPLEMENTED) Returns the delay in seconds that is waited
after each Selenium command.
|
String |
getSeleniumTimeout()
Returns the timeout in seconds that is used by various keywords.
|
String |
getSource()
Returns the entire HTML source of the current page or frame.
|
String |
getSystemInfo()
Returns basic system information about the execution environment.
|
double |
getTimeout() |
String |
getTitle()
Returns the title of current page.
|
protected String |
getUserFromURL(URL url) |
WebDriverCache |
getWebDriverCache() |
List<String> |
getWindowIdentifiers()
Returns the id attributes of all windows known to the current browser
instance.
|
List<String> |
getWindowNames()
Returns the names of all windows known to the current browser instance.
|
Object[] |
getWindowSize()
Returns current window size as width then height.
|
List<String> |
getWindowTitles()
Returns the titles of all windows known to the current browser instance.
|
void |
goBack()
Simulates the user clicking the "back" button on their browser.
|
void |
goTo(String url)
Navigates the active browser instance to the provided URL.
|
void |
locationShouldBe(String url)
Verify the current page URL is exactly url.
|
void |
locationShouldContain(String url)
Verify the current page URL contains url.
|
void |
maximizeBrowserWindow()
Maximizes current browser window.
|
String |
openBrowser(String url) |
String |
openBrowser(String url,
String browserName) |
String |
openBrowser(String url,
String browserName,
String alias) |
String |
openBrowser(String url,
String browserName,
String alias,
String remoteUrl) |
String |
openBrowser(String url,
String browserName,
String alias,
String remoteUrl,
String desiredCapabilities) |
String |
openBrowser(String url,
String browserName,
String alias,
String remoteUrl,
String desiredCapabilities,
String browserOptions)
Opens a new browser instance to given URL.
|
protected void |
parseBrowserOptionsFirefox(String browserOptions,
org.openqa.selenium.remote.DesiredCapabilities desiredCapabilities) |
void |
reloadPage()
Simulates user reloading page.
|
void |
selectFrame(String locator)
Selects the frame identified by locator as current frame.
|
void |
selectWindow() |
void |
selectWindow(String locator)
Selects the window identified by locator as the context of
actions.
|
String |
setBrowserImplicitWait(String timestr)
Sets and returns the implicit wait time in seconds that is used by the
current Selenium 2 WebDriver instance.
|
protected void |
setRemoteWebDriverProxy(org.openqa.selenium.remote.HttpCommandExecutor httpCommandExecutor) |
void |
setRemoteWebDriverProxy(String host,
String port) |
void |
setRemoteWebDriverProxy(String host,
String port,
String user) |
void |
setRemoteWebDriverProxy(String host,
String port,
String user,
String password) |
void |
setRemoteWebDriverProxy(String host,
String port,
String user,
String password,
String domain) |
void |
setRemoteWebDriverProxy(String host,
String port,
String username,
String password,
String domain,
String workstation)
Configures proxy handling for remote WebDriver instances.
|
String |
setSeleniumImplicitWait(String timestr)
Sets and returns the implicit wait time in seconds that is used by all
Selenium 2 WebDriver instances.
|
String |
setSeleniumSpeed(String timestr)
(NOT IMPLEMENTED) Sets and returns the delay in seconds that is
waited after each Selenium command.
|
String |
setSeleniumTimeout(String timestr)
Sets and returns the timeout in seconds that is used by various keywords.
|
void |
setWindowSize(String width,
String height)
Sets the width and height of the current window to the
specified values.
|
void |
switchBrowser(String indexOrAlias)
"Switches between active browser instances using an index or an
alias.
|
void |
titleShouldBe(String title)
Verify the current page title is exactly title.
|
void |
titleShouldContain(String title)
Verify the current page title contains title.
|
void |
titleShouldNotBe(String title)
Verify the current page title is not exactly title.
|
void |
titleShouldNotContain(String title)
Verify the current page title does not contain title.
|
protected List<String> |
toList(List<String> items) |
protected List<String> |
toList(List<String> items,
String what) |
void |
unselectFrame()
Selects the top frame as the current frame.
|
runOnFailureByAspectJpublic String remoteWebDriverProxyHost
public String remoteWebDriverProxyPort
public String remoteWebDriverProxyUser
public String remoteWebDriverProxyPassword
public String remoteWebDriverProxyDomain
public String remoteWebDriverProxyWorkstation
protected WebDriverCache webDriverCache
protected double timeout
protected double implicitWait
protected Logging logging
protected Element element
public WebDriverCache getWebDriverCache()
public org.openqa.selenium.WebDriver getCurrentWebDriver()
public double getTimeout()
public void addLocationStrategy(String strategyName, String functionDefinition, String delimiter)
| Add Location Strategy | byId | return window.document.getElementById(arguments[0]); |
| Input Text | byId=firstName | Max |
| Add Location Strategy | byClassname | return window.document.getElementsByClassName(arguments[0])[arguments[1]]; | , |
| Input Text | byClassname=input,3 | Max |
strategyName - Name of the location strategy.functionDefinition - The JavaScript function to register.delimiter - Default=NONE. The delimiter to split the given locator valuepublic void closeBrowser()
public String openBrowser(String url, String browserName) throws Throwable
Throwablepublic String openBrowser(String url, String browserName, String alias) throws Throwable
Throwablepublic String openBrowser(String url, String browserName, String alias, String remoteUrl) throws Throwable
Throwablepublic String openBrowser(String url, String browserName, String alias, String remoteUrl, String desiredCapabilities) throws Throwable
Throwablepublic String openBrowser(String url, String browserName, String alias, String remoteUrl, String desiredCapabilities, String browserOptions) throws Throwable
| firefox | FireFox |
| ff | FireFox |
| internetexplorer | Internet Explorer |
| ie | Internet Explorer |
| googlechrome | Google Chrome |
| gc | Google Chrome |
| chrome | Google Chrome |
| opera | Opera |
| phantomjs | PhantomJS |
| htmlunitwithjs | HTMLUnit with Javascipt support |
| safari | Safari |
| ipad | iPad |
| iphone | iPhone |
| android | Android |
| htmlunit | HTMLUnit |
| platform:Windows 8,browserName:firefox,version:25 |
|
{ "platform":"Windows 8", "browserName":"firefox", "version":"25", "proxy": { "proxyType":"manual", "httpProxy":"localhost:8118" } } |
|
{ "preferences": { "extensions.firebug.currentVersion":"1.8.1", "extensions.firebug.addonBarOpened":true, "extensions.firebug.enableSites":true } "extensions": [ "firebug-1.8.1.xpi", "modify_headers-0.7.1.1-fx.xpi" ] } |
url - The URL to open in the newly created browser instance.browserName - Default=firefox. Optional name of the browser to start.alias - Default=NONE. Optional alias for the newly created browser
instance. The alias can be used later for switching between
browsers instances, just as returned index.remoteUrl - Default=NONE. Optional remote grid URL. When specified no
local WebDriver instance is created, but a network connection
to a Selenium 2 WebDriver Grid Hub at the given URL is opened.desiredCapabilities - Default=NONE. Optional desired capabilities of the newly
created remote browser instances can be specified in a simple
key1:val1,key2:val2 format or as a JSON object (see examples
above). Used to communicate to the remote grid, which kind of
browser, etc. should be used. For more information see: DesiredCapabilitiesThrowablecloseAllBrowsers(),
closeBrowser(),
switchBrowser(java.lang.String)public void switchBrowser(String indexOrAlias)
| Open Browser | http://google.com | ff | |
| Location Should Be | http://google.com | ||
| Open Browser | http://yahoo.com | ie | 2nd conn |
| Location Should Be | http://yahoo.com | ||
| Switch Browser | 1 | # index | |
| Page Should Contain | I'm feeling lucky | ||
| Switch Browser | 2nd conn | # alias | |
| Page Should Contain | More Yahoo! | ||
| Close All Browsers |
| ${id} = | Open Browser | http://google.com |
| # Do something ... | ||
| Switch Browser | ${id} |
indexOrAlias - the index or alias of the browser instance to switch tocloseAllBrowsers(),
closeBrowser(),
openBrowser(java.lang.String)public void closeAllBrowsers()
public void closeWindow()
public List<String> getWindowIdentifiers()
Logging.logWindowIdentifiers()public List<String> getWindowNames()
Logging.logWindowNames()public List<String> getWindowTitles()
Logging.logWindowTitles()public void maximizeBrowserWindow()
public Object[] getWindowSize()
| ${width} | ${height}= | Get Window Size |
public void setWindowSize(String width, String height)
| Set Window Size | 800 | 600 |
| ${width} | ${height}= | Get Window Size |
| Should Be Equal | ${width} | 800 |
| Should Be Equal | ${height} | 600 |
width - The window width to set in px.height - The window height to set in px.public void selectFrame(String locator)
locator - The locator to locate the framepublic void selectWindow()
public void selectWindow(String locator)
| Click Link | popup_link | # opens new window |
| Select Window | popupName | |
| Title Should Be | Popup Title | |
| Select Window | # Chooses the main window again |
| Strategy | Example | Description |
| title | Select Window | title=My Document | Matches by window title |
| name | Select Window | name=${name} | Matches by window javascript name |
| url | Select Window | url=http://google.com | Matches by window's current URL |
locator - The locator to locate the windowpublic void unselectFrame()
public String getLocation()
Logging.logLocation()public String getSource()
Logging.logSource()public String getTitle()
Logging.logTitle()public String getRemoteCapabilities()
Logging.logRemoteCapabilities()public String getRemoteSessionId()
Logging.logRemoteSessionId()public String getSystemInfo()
Logging.logSystemInfo()public void locationShouldBe(String url)
url - The URL to verify.locationShouldContain(java.lang.String)public void locationShouldContain(String url)
url - The URL to verify.locationShouldBe(java.lang.String)public void titleShouldBe(String title)
title - The title to verify.titleShouldNotBe(java.lang.String),
titleShouldContain(java.lang.String),
titleShouldNotContain(java.lang.String)public void titleShouldNotBe(String title)
title - The title to verify.titleShouldBe(java.lang.String),
titleShouldContain(java.lang.String),
titleShouldNotContain(java.lang.String)public void titleShouldContain(String title)
title - The title to verify.titleShouldBe(java.lang.String),
titleShouldNotBe(java.lang.String),
titleShouldNotContain(java.lang.String)public void titleShouldNotContain(String title)
title - The title to verify.titleShouldBe(java.lang.String),
titleShouldNotBe(java.lang.String),
titleShouldContain(java.lang.String)public void goBack()
public void goTo(String url)
url - The URL to open.public void reloadPage()
public String getSeleniumSpeed()
setSeleniumSpeed(java.lang.String)public String setSeleniumSpeed(String timestr)
timestr - The delay in seconds.getSeleniumSpeed()public String getSeleniumTimeout()
setSeleniumTimeout(java.lang.String)public String setSeleniumTimeout(String timestr)
| ${orig timeout} = | Set Selenium Timeout | 15 seconds |
| # Open page that loads slowly | ||
| Set Selenium Timeout | ${orig timeout} | # Reset to old value |
timestr - The timeout in seconds.getSeleniumTimeout()public String getSeleniumImplicitWait()
setSeleniumImplicitWait(java.lang.String)public String setSeleniumImplicitWait(String timestr)
| ${orig wait} = | Set Selenium Implicit Wait | 10 seconds |
| # Perform AJAX call that is slow | ||
| Set Selenium Implicit Wait | ${orig wait} | # Reset to old value |
timestr - The implicit wait time in seconds.setBrowserImplicitWait(java.lang.String),
getSeleniumImplicitWait()public String setBrowserImplicitWait(String timestr)
| ${orig wait} = | Set Browser Implicit Wait | 10 seconds |
| # Perform AJAX call that is slow | ||
| Set Browser Implicit Wait | ${orig wait} | # Reset to old value |
timestr - The implicit wait time in seconds.setSeleniumImplicitWait(java.lang.String)public void setRemoteWebDriverProxy(String host, String port, String user, String password)
public void setRemoteWebDriverProxy(String host, String port, String user, String password, String domain)
public void setRemoteWebDriverProxy(String host, String port, String username, String password, String domain, String workstation)
host - The hostname of the proxyport - The port of the proxyusername - Default=NONE. The usenamepassword - Default=NONE. The password of the userdomain - Default=NONE. The NTLM domain nameworkstation - Default=NONE. The name of the workstationprotected org.openqa.selenium.WebDriver createWebDriver(String browserName, String desiredCapabilitiesString, String remoteUrlString, String browserOptions) throws MalformedURLException
MalformedURLExceptionprotected org.openqa.selenium.WebDriver createLocalWebDriver(String browserName, org.openqa.selenium.remote.DesiredCapabilities desiredCapabilities)
protected org.openqa.selenium.WebDriver createRemoteWebDriver(org.openqa.selenium.remote.DesiredCapabilities desiredCapabilities,
URL remoteUrl)
protected org.openqa.selenium.remote.DesiredCapabilities createDesiredCapabilities(String browserName, String desiredCapabilitiesString, String browserOptions)
protected void parseBrowserOptionsFirefox(String browserOptions, org.openqa.selenium.remote.DesiredCapabilities desiredCapabilities)
protected void setRemoteWebDriverProxy(org.openqa.selenium.remote.HttpCommandExecutor httpCommandExecutor)
Copyright © 2014. All rights reserved.