XApproach - cyberspaceru/Jedi GitHub Wiki

The Jedi QA using approaches to creating XPath queries.

What is an approach?

Each approach is a javascript function which returns some value to improve a query. You can set a list of approaches in the 'Jedi QA' tab.

In order to create new approach initialize new object:

var nameApp = new XApproach('name', {arg1: 1, arg2: 'some value'});

And then it can be added to a set of approaches for creating of XPath queries. You can create a specific set for a tag:

var commonSet = [nameApp];
var inputSet = [indexApp, titleApp];
var aSet = [anotherApp, [idApp, hrefApp]];
var settings = {
    input: inputSet, //$ only for an 'input' tag.
    a: aSet, //$ only for an 'a' tag.
    common: commonSet //$ for another tags.
};
settings; // Send settings to the XEngine.

If You will have some errors then You will see an alert message.

The list of approaches:

Attribute

Each attribute can become an approach. In this case, the query will contain an equal expression, for example: div[@id = 'some id']

var idApp = new XApproach('id');

InnerText

Creating an expression: contains(text(), “inner text of the element”)

var innerTextApp = new XApproach('innerText');

Indexator

Create an expression with an element index. If You want to use it with another approach, use position.

Example: div[1]

var indexatorApp = new XApproach('indexator');

Position

Creating an expression with an element index.

Example: div[position() = 1]

var positionApp = new XApproach('position');

Ancestor

Create a predicate expression by the Ancestor axis.

Arguments:

  1. approaches - an array of approaches is applying to create a predicate expression for an axis.

Example: H2[ancestor::DIV[@id = 'post-40']]

var approaches = [idApp, valueApp];
var ancestorApp = new XApproach('ancestor', {approaches: approaches});

FollowingSibling

Create a predicate expression by the Following-sibling axis.

Arguments:

  1. approaches - an array of approaches is applying to create a predicate expression for an axis.

Example: H2[following-sibling::DIV[@id = 'post-40']]

var approaches = [idApp, valueApp];
var followingSiblingApp = new XApproach('followingSibling', {approaches: approaches});

Child

Create a predicate expression by the Child axis.

Arguments:

  1. approaches - an array of approaches is applying to create a predicate expression for an axis.

Example: H2[child::DIV[@id = 'post-40']]

var approaches = [idApp, valueApp];
var childApp = new XApproach('child', {approaches: approaches});