org.specrunner.webdriver.impl
Class FinderXPath

java.lang.Object
  extended by org.specrunner.parameters.core.ParameterHolder
      extended by org.specrunner.webdriver.impl.FinderXPath
All Implemented Interfaces:
IParameterHolder, IFinder

public class FinderXPath
extends ParameterHolder
implements IFinder

Utility class to manage search strategies to be used by browser aware plugins. You can register XPath search strategies, and reuse then in your tests. Patterns like search by id, name, value, a tag which contains something, tags or attributes that start with something, or pure XPath are already registered.

Author:
Thiago Santos

Field Summary
protected  String by
          The reference to document objects.
protected  String separator
          The separator of arguments in 'by' attribute.
 
Constructor Summary
protected FinderXPath()
          Minimum constructor.
 
Method Summary
 void addStrategy(String name, String xpath)
          Map an new search strategy.
 List<org.openqa.selenium.WebElement> find(IContext context, IResultSet result, org.openqa.selenium.WebDriver client)
          Returns a list of elements.
 String findStrategy(String name)
          Recover a given strategy.
static FinderXPath get()
          Gets the thread safe instance of finder.
 String[] getArguments(IContext context)
          Get the arguments for search strategy.
 String getBy()
          The search strategy to be used. i.e.
 String getSeparator()
          Gets the parameter separator.
 Iterator<String> getStrategies()
          List of available strategies.
 String getType()
          Get the type of search strategy. i.e.
 String getXPath(IContext context)
          Gets the XPath related to the plugin.
 void reset()
          Clear any previous finder settings.
 String resume(IContext context)
          The representation of the filter.
 void setBy(String by)
          Sets the target reference.
 void setSeparator(String separator)
          Sets the separator.
 
Methods inherited from class org.specrunner.parameters.core.ParameterHolder
getParameters, setParameters
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.specrunner.parameters.IParameterHolder
getParameters, setParameters
 

Field Detail

by

protected String by
The reference to document objects.


separator

protected String separator
The separator of arguments in 'by' attribute.

Constructor Detail

FinderXPath

protected FinderXPath()
Minimum constructor.

Method Detail

get

public static FinderXPath get()
Gets the thread safe instance of finder.

Returns:
The finder instance.

getStrategies

public Iterator<String> getStrategies()
List of available strategies.

Returns:
The list of strategies.

addStrategy

public void addStrategy(String name,
                        String xpath)
Map an new search strategy.

Parameters:
name - The strategy name.
xpath - The corresponding XPath with replace masks as ${0}, ${1}, and so on.

findStrategy

public String findStrategy(String name)
Recover a given strategy.

Parameters:
name - The strategy name.
Returns:
The corresponding XPath.

getBy

public String getBy()
The search strategy to be used. i.e. by="id:txtName" means find the element whose 'id' is 'txtName'. The 'by' attribute is closely related to FindeXPath strategy.

The 'id' type is associated in FindeXPath to the XPath "//*[@id='{0}']", is means that if you use 'by="id:txtName"', this plugin will lookup the 'id' corresponding XPath, tokenize the content after ':' using ';' as separator and replace '{...}' elements in order. To use another separator set 'separator' attribute.

In the previous example, 'by=id:txtName' becomes a XPath expression "//*[@id='txtName']".

Returns:
The search strategy.

setBy

public void setBy(String by)
Sets the target reference.

Parameters:
by - The reference.

getSeparator

public String getSeparator()
Gets the parameter separator. Default is ";".

Returns:
The separator.

setSeparator

public void setSeparator(String separator)
Sets the separator.

Parameters:
separator - The separator.

getType

public String getType()
Get the type of search strategy. i.e. 'id', or 'name'.

Returns:
The search type, null, not specified.

getArguments

public String[] getArguments(IContext context)
Get the arguments for search strategy. Examples:

Parameters:
context - The test context.
Returns:
The search strategy arguments.

getXPath

public String getXPath(IContext context)
                throws PluginException
Gets the XPath related to the plugin.

Parameters:
context - The test context.
Returns:
The XPath expression to find elements.
Throws:
PluginException - On XPath generation errors.

reset

public void reset()
Description copied from interface: IFinder
Clear any previous finder settings.

Specified by:
reset in interface IFinder

find

public List<org.openqa.selenium.WebElement> find(IContext context,
                                                 IResultSet result,
                                                 org.openqa.selenium.WebDriver client)
                                          throws PluginException
Description copied from interface: IFinder
Returns a list of elements.

Specified by:
find in interface IFinder
Parameters:
context - The test context.
result - The result set.
client - The browser.
Returns:
A list empty or not of elements.
Throws:
PluginException - On filter errors.

resume

public String resume(IContext context)
              throws PluginException
Description copied from interface: IFinder
The representation of the filter.

Specified by:
resume in interface IFinder
Parameters:
context - The test context.
Returns:
A string that 'explain' the search used.
Throws:
PluginException - On detail errors.


Copyright © 2013. All rights reserved.