com.ibm.team.fvt.tests.web
Class WebPage

java.lang.Object
  extended by com.ibm.team.fvt.tests.web.WebPage

public abstract class WebPage
extends java.lang.Object

The abstract class for any web page connected to a WebBrowser.

A web page is created using a location which is the initial url sent to the browser to load the page. It may slightly differ from the browser current url after it has been loaded (see getUrl().

It also stores the configuration used while running the test in order to access any necessary information from it (e.g. timeouts).

Finally, the web page is also associated with a getUser() as its content might slightly or completely differ depending of it. This user let also the page know whether a login operation when a new one is connected to it.

This class provides the following basic functionalities:

It also provides any convenient method to access basic browser functionalities without having to specify all parameters, ie. by using default parameter value:


Field Summary
static java.lang.String[] NO_DATA
           
 
Constructor Summary
WebPage(java.lang.String url, Config config, User user)
           
 
Method Summary
<P extends WebLinkHover<? extends WebPage>>
P
checkHoverTitle(WebBrowserElement linkElement, java.lang.Class<P> hoverClass)
          Check the hover title of the given link element.
<RH extends WebRichHover<? extends WebPage>>
RH
checkRichHover(WebBrowserElement linkElement, java.lang.Class<RH> richHoverClass, java.lang.String... data)
          Check the rich hover of the given link element.
static void clearHistory()
          Clear web pages history.
 boolean equals(java.lang.Object o)
           
 WebPage get()
          Get the page content.
 WebBrowser getBrowser()
          Return the browser associated with the current page.
 Config getConfig()
          Return the configuration associated with the current page.
static WebPage getCurrentPage()
          Return the current page displayed on the browser.
 java.lang.String getLocation()
          Return the page location used when creating it.
static
<P extends WebPage>
P
getPage(java.lang.Class<P> pageClass)
          Seek the cache to find the instance of the given page class.
static WebPage getPage(java.lang.String location)
          Get from the cache the page instance for the given location.
static WebPage getPageUsingBrowser(Config config)
          Retrieve the existing page for the browser current URL.
abstract  java.lang.String getTitle()
          Return the title of the page.
 java.lang.String getUrl()
          Return the URL of the page loaded in the browser.
 User getUser()
          Return the user used when the page was loaded.
 WebPage goBack()
          Move back a single "item" in the browser's history.
 int hashCode()
           
 boolean login(User user)
          Login the page from current user to the given user.
 boolean login(User user, boolean force)
          Login the page from current user to the given user.
static WebPage openPage(java.lang.String location)
           
static
<P extends WebPage>
P
openPage(java.lang.String location, Config config, User user, java.lang.Class<P> pageClass, java.lang.String... data)
          Retrieve the existing page for the given location.
<P extends WebPage>
P
openPageUsingBrowser(java.lang.Class<P> pageClass, java.lang.String... data)
          Retrieve the existing page for the browser current URL.
<P extends WebPage>
P
openPageUsingHoverTitle(WebRichHover<? extends WebPage> hover, java.lang.Class<P> openedPageClass, java.lang.String... data)
          Click on the given hover title to open a new page.
<P extends WebPage>
P
openPageUsingLink(org.openqa.selenium.By linkBy, java.lang.Class<P> openedPageClass)
          Click on the link found using the given mechanism assuming that will open a new page.
<P extends WebPage>
P
openPageUsingLink(org.openqa.selenium.By linkBy, java.lang.Class<P> openedPageClass, int timeOut)
          Click on the link found using the given mechanism assuming that will open a new page.
<P extends WebPage>
P
openPageUsingLink(org.openqa.selenium.By linkBy, java.lang.Class<P> openedPageClass, java.lang.String... info)
          Click on the link found using the given mechanism assuming that will open a new page.
<P extends WebPage>
P
openPageUsingLink(WebBrowserElement parentElement, org.openqa.selenium.By linkBy, java.lang.Class<P> openedPageClass)
          Click on the link found using the given mechanism assuming that will open a new page.
<P extends WebPage>
P
openPageUsingLink(WebBrowserElement parentElement, org.openqa.selenium.By linkBy, java.lang.Class<P> openedPageClass, boolean fail, int time_out, java.lang.String... info)
          Click on the link found using the given mechanism assuming that will open a new page.
<P extends WebPage>
P
openPageUsingLink(WebBrowserElement linkElement, java.lang.Class<P> openedPageClass, java.lang.String... data)
          Click on the given link assuming that will open a new page.
 void parkMouse()
          Park the mouse at a location where links are not found in order to prevent unexpected rich hovers from loading by accident.
 void refresh()
          Refresh the page content using WebBrowser.refresh() and wait for the page to be loaded (see waitForLoadingPageEnd()).
<RH extends WebTextHover>
RH
richHoverOverLink(WebBrowserElement linkElement, java.lang.Class<RH> richHoverClass, java.lang.String... additionalData)
          Perform a mouse hovering over the given link element.
static WebPage searchPageInHistory(java.lang.String location)
          Return the first page found in the history.
 void takeSnapshotFailure(java.lang.String fileName)
          Takes a failure snapshot.
 void takeSnapshotInfo(java.lang.String fileName)
          Takes an information snapshot.
 void takeSnapshotWarning(java.lang.String fileName)
          Takes a warning snapshot.
 java.lang.String toString()
           
 WebBrowserElement waitForElement(org.openqa.selenium.By parentBy, org.openqa.selenium.By findBy, boolean fail, int time_out)
          Wait until have found the web element relatively to a parent element using the respective given mechanisms.
 java.lang.String waitForText(WebBrowserElement element, boolean fail, int time_out, java.lang.String... texts)
          Wait until have got one of the expected texts on of the given element.
 WebBrowserElement waitForTextPresent(java.lang.String... texts)
          Wait until have got one of the expected texts on of the given element.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

NO_DATA

public static final java.lang.String[] NO_DATA
Constructor Detail

WebPage

public WebPage(java.lang.String url,
               Config config,
               User user)
Method Detail

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

clearHistory

public static void clearHistory()
Clear web pages history.


searchPageInHistory

public static WebPage searchPageInHistory(java.lang.String location)
Return the first page found in the history.

Parameters:
location - The page location
Returns:
The found page or null if none was found.

getCurrentPage

public static WebPage getCurrentPage()
Return the current page displayed on the browser.

This is the last page of the internal cache.

Returns:
The current page as a WebPage.

getPage

public static <P extends WebPage> P getPage(java.lang.Class<P> pageClass)
Seek the cache to find the instance of the given page class.

Note that this is a very expensive method which should not be used too frequently.

TODO Replace the pages cache keys to store class instead location.

Parameters:
pageClass - The page class
Returns:
The instance of the class associate with the give page page class or null if this page hasn't been created yet.

getPage

public static WebPage getPage(java.lang.String location)
Get from the cache the page instance for the given location.

Parameters:
location - The page location
Returns:
The instance of the class associate with the page or null if this page hasn't been created yet.

getPageUsingBrowser

public static WebPage getPageUsingBrowser(Config config)
Retrieve the existing page for the browser current URL. Create it if it's the first time the page is requested.

Returns:
The instance of the class associate with the page or null if no page location matching the browser url is found in the cache...

openPage

public static WebPage openPage(java.lang.String location)

openPage

public static <P extends WebPage> P openPage(java.lang.String location,
                                             Config config,
                                             User user,
                                             java.lang.Class<P> pageClass,
                                             java.lang.String... data)
Retrieve the existing page for the given location. Create it if it is the first time the page is requested.

Parameters:
location - The url of the page
config - The config to use for the requested page
user - The user to use on the requested page
pageClass - The class associated with the page to open
data - Additional CLM information to be stored in the page
Returns:
The instance of the class associate with the page.

checkHoverTitle

public <P extends WebLinkHover<? extends WebPage>> P checkHoverTitle(WebBrowserElement linkElement,
                                                                     java.lang.Class<P> hoverClass)
Check the hover title of the given link element.

This check opens the hover by positioning the mouse pointer over the given link element and checks whether its title matches the given text.

Type Parameters:
P - The expected class for the hover
Parameters:
linkElement - The link on which to hover
hoverClass - The expected class for the hover
Returns:
The opened hover web element as WebBrowserElement
Throws:
ScenarioFailedError - in following cases:
  • The hover is not found (typically when it fails to open)
  • The hover title is not found after shortTimeout() (typically when the hover is still empty when the timeout is reached)
  • The title does not match the expected one
TODO Should infer the hover class as done in ClmProjectAreaPageHelper#checkRichHover(...)

checkRichHover

public <RH extends WebRichHover<? extends WebPage>> RH checkRichHover(WebBrowserElement linkElement,
                                                                      java.lang.Class<RH> richHoverClass,
                                                                      java.lang.String... data)
Check the rich hover of the given link element.

This check opens the rich hover by positioning the mouse pointer over the given link element and perform checks on its content (typically the title).

Type Parameters:
RH - The expected class for the hover
Parameters:
linkElement - The link on which to hover
richHoverClass - The expected class for the hover
Returns:
The opened rich hover web element as WebBrowserElement
Throws:
ScenarioFailedError - in following cases:
  • The rich hover is not found (typically when it fails to open)
  • The rich hover title is not found after shortTimeout() (typically when the hover is still empty when the timeout is reached)
  • The title does not match the expected one
TODO Should infer the hover class as done in ClmProjectAreaPageHelper#checkRichHover(...)

get

public final WebPage get()
Get the page content.

Returns:
The page instance

getBrowser

public WebBrowser getBrowser()
Return the browser associated with the current page.

Returns:
The browser as WebBrowser

getConfig

public Config getConfig()
Return the configuration associated with the current page.

Returns:
The configuration as Config

getLocation

public java.lang.String getLocation()
Return the page location used when creating it.

Returns:
The page location

getTitle

public abstract java.lang.String getTitle()
Return the title of the page.

Returns:
The title as a String.

getUrl

public final java.lang.String getUrl()
Return the URL of the page loaded in the browser.

Returns:
The browser URL as a String
See Also:
WebBrowser.getCurrentUrl()

getUser

public User getUser()
Return the user used when the page was loaded.

Returns:
The user.

goBack

public WebPage goBack()
Move back a single "item" in the browser's history.

See Also:
WebBrowser.back()

parkMouse

public void parkMouse()
Park the mouse at a location where links are not found in order to prevent unexpected rich hovers from loading by accident. The parking zone used for this purpose is the (0,0) location of the element, which is the top-left corner of the display area of the browser.


login

public boolean login(User user)
Login the page from current user to the given user.

Nothing happen if the current user is already logged in.

Parameters:
user - The user to log in.

login

public boolean login(User user,
                     boolean force)
Login the page from current user to the given user.

Nothing happen if the current user is already logged in.

Parameters:
user - The user to log in.
force - Force the user login, even if it's already logged

openPageUsingBrowser

public <P extends WebPage> P openPageUsingBrowser(java.lang.Class<P> pageClass,
                                                  java.lang.String... data)
Retrieve the existing page for the browser current URL. Create it if it's the first time the page is requested.

Parameters:
pageClass - The class associated with the page to open
data - Additional CLM information to be stored in the page
Returns:
The instance of the class associate with the page.

openPageUsingHoverTitle

public <P extends WebPage> P openPageUsingHoverTitle(WebRichHover<? extends WebPage> hover,
                                                     java.lang.Class<P> openedPageClass,
                                                     java.lang.String... data)
Click on the given hover title to open a new page.

Note that the browser url after having clicked on the hover title will be used for the page location.

Parameters:
hover - The hover on which to click on title
openedPageClass - The class associated with the opened page
data - Provide additional information to store in the page when opening it
Returns:
The web page (as a subclass of WebPage) opened after having clicked on the link
See Also:
openPage(String, Config, User, Class, String...), WebBrowserElement.click()

openPageUsingLink

public <P extends WebPage> P openPageUsingLink(org.openqa.selenium.By linkBy,
                                               java.lang.Class<P> openedPageClass)
Click on the link found using the given mechanism assuming that will open a new page.

The opened page URL is got from the application which usually takes it from the href attribute of the link web element (see Topology.getPageUrl(String).

Note that:


openPageUsingLink

public <P extends WebPage> P openPageUsingLink(org.openqa.selenium.By linkBy,
                                               java.lang.Class<P> openedPageClass,
                                               int timeOut)
Click on the link found using the given mechanism assuming that will open a new page.

The opened page URL is got from the application which usually takes it from the href attribute of the link web element (see Topology.getPageUrl(String).

Note that:


openPageUsingLink

public <P extends WebPage> P openPageUsingLink(org.openqa.selenium.By linkBy,
                                               java.lang.Class<P> openedPageClass,
                                               java.lang.String... info)
Click on the link found using the given mechanism assuming that will open a new page.

The opened page URL is got from the application which usually takes it from the href attribute of the link web element (see Topology.getPageUrl(String).

Note that:


openPageUsingLink

public <P extends WebPage> P openPageUsingLink(WebBrowserElement parentElement,
                                               org.openqa.selenium.By linkBy,
                                               java.lang.Class<P> openedPageClass)
Click on the link found using the given mechanism assuming that will open a new page.

The opened page URL is got from the application which usually takes it from the href attribute of the link web element (see Topology.getPageUrl(String).

Note that:


openPageUsingLink

public <P extends WebPage> P openPageUsingLink(WebBrowserElement parentElement,
                                               org.openqa.selenium.By linkBy,
                                               java.lang.Class<P> openedPageClass,
                                               boolean fail,
                                               int time_out,
                                               java.lang.String... info)
Click on the link found using the given mechanism assuming that will open a new page.

The opened page URL is got from the application which usually takes it from the href attribute of the link web element (see Topology.getPageUrl(String).

Parameters:
parentElement - The parent element where to start to search from, if null, then search in the entire page content
linkBy - The mechanism to find the link element in the current page
openedPageClass - The class associated with the opened page
fail - Tells whether to fail if none of the elements is find before timeout
time_out - The time to wait before giving up the research
info - Provide additional information to store in the page when opening it
Returns:
The web page (as a subclass of WebPage) opened after having clicked on the link
See Also:
WebBrowser.waitForElement(WebBrowserElement, By, boolean, int, boolean, boolean), openPageUsingLink(WebBrowserElement, Class, String...), WebBrowserElement.click()

openPageUsingLink

public <P extends WebPage> P openPageUsingLink(WebBrowserElement linkElement,
                                               java.lang.Class<P> openedPageClass,
                                               java.lang.String... data)
Click on the given link assuming that will open a new page.

The opened page URL is got from the application (see Topology.getPageUrl(String)) which usually takes it from the href attribute of the link web element.

Parameters:
linkElement - The link on which to click
openedPageClass - The class associated with the opened page
data - Provide additional information to store in the page when opening it
Returns:
The web page (as a subclass of WebPage) opened after having clicked on the link

refresh

public void refresh()
Refresh the page content using WebBrowser.refresh() and wait for the page to be loaded (see waitForLoadingPageEnd()).

If subclass overrides this method, it's strongly recommended to call the super implementation in order to implicitly wait for the end of the page load, but also to set the refreshed flag...


richHoverOverLink

public <RH extends WebTextHover> RH richHoverOverLink(WebBrowserElement linkElement,
                                                      java.lang.Class<RH> richHoverClass,
                                                      java.lang.String... additionalData)
Perform a mouse hovering over the given link element.

Type Parameters:
RH - The rich hover specialized class
Parameters:
linkElement - The web element on which to hover
richHoverClass - The rich hover specialized class
additionalData - Additional data to check in the rich hover
Returns:
The opened rich hover as the given specialized class

takeSnapshotFailure

public void takeSnapshotFailure(java.lang.String fileName)
Takes a failure snapshot.

Parameters:
fileName - The name of the snapshot file.

takeSnapshotInfo

public void takeSnapshotInfo(java.lang.String fileName)
Takes an information snapshot.

Parameters:
fileName - The name of the snapshot file.

takeSnapshotWarning

public void takeSnapshotWarning(java.lang.String fileName)
Takes a warning snapshot.

Parameters:
fileName - The name of the snapshot file.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

waitForElement

public WebBrowserElement waitForElement(org.openqa.selenium.By parentBy,
                                        org.openqa.selenium.By findBy,
                                        boolean fail,
                                        int time_out)
Wait until have found the web element relatively to a parent element using the respective given mechanisms.

Note that:


waitForText

public java.lang.String waitForText(WebBrowserElement element,
                                    boolean fail,
                                    int time_out,
                                    java.lang.String... texts)
Wait until have got one of the expected texts on of the given element.

Note that:

Parameters:
element - The text element to be read
fail - Tells whether to fail if none of the elements is find before timeout
time_out - The time to wait before giving up the research
texts - The expected texts
Returns:
One of the expected text as String or null if element text never matches one before the timeout and asked not to fail
Throws:
ScenarioFailedError - if element text never matches an expected ones before the timeout and asked to fail
See Also:
WebBrowser.waitForText(WebBrowserElement, boolean, int, String...)

waitForTextPresent

public WebBrowserElement waitForTextPresent(java.lang.String... texts)
Wait until have got one of the expected texts on of the given element.

Note that:

Parameters:
texts - The expected texts
Returns:
One of the expected text as String or null if element text never matches one before the timeout and asked not to fail
Throws:
ScenarioFailedError - if element text never matches an expected ones before the timeout and asked to fail
See Also:
WebBrowser.waitForText(WebBrowserElement, boolean, int, String...)