How to create a Pattern - cyberspaceru/Jedi GitHub Wiki
Pattern - is a text file which represents a Page Object. The structure of the pattern:
********************************** First: Fields definition **********************************
{
"static_fields": [
"Page Title",
"Class Name"
],
"table_columns": [
"Element Name:target:",
"Type:select:['Button', 'Textarea', 'InputText', 'Link']",
"Field Name"
]
}
********************************** Second: Code definition **********************************
$code
{
$declaration {name: 'Java Page Object', type: 'java'}
$pattern
{
@PageTitle("$eval(static['Page Title'])")
public class $eval(static['Class Name']) {
#startsection
@FindBy(xpath = "$eval(row['xpath'].replace(/"/g, '\\"'))")
@ElementTitle("$eval(row['Element Name'])")
public WebElement $eval(row['Type'].toLowerCase().replace(/[aeiou]/gi, '') + row['Field Name']);
#endsection
}
}
}
$code
{
$declaration {name: 'C# Page Object', type: 'css'}
$pattern
{
YOUR_CODE
}
}
Fields definition
Fields definition - is a text at the start of the pattern. It's including two objects:
- static_fields - is a set of fields which is displaying in the popup and belongs to the common context.
- table_columns - are fields of a variable which you have to fill in for any node of a web page and belongs to the section context.
At the end of a field of the 'table_columns' object, You can add only one from following tags:
- :target: - then a field will be a targetable text input. In our example, 'Element Name' has this tag;
- :select:['option 1', 'option 2'] - then a field will be an HTML select and will have options which are specified in the array after the tag.
Code definition
Code definition - is a text at the end of the pattern. It can include a lot of code patterns, each of them has a tag: $code.
And this tag has other tags:
- $declaration - where you have to specify a name and a type of the code pattern;
- $pattern - is a text of your pattern.
$code
{
$declaration {name: 'name', type: 'type'}
$pattern
{
TEXT_BETWEEN_THESE_BRACKETS
}
}
Pattern tag
$pattern contains the pattern of your code or a text of another type of data representations(maybe a table?).
Within the text of the pattern, You can use a javascript code with help $eval(js_code).
The pattern has two contexts:
- Common context - where you can use the static object within a javascript code.
- Section context - where you can use the row object within a javascript code. The common context includes the section context, but not vice versa.
In order to create the section context, you have to write a text between #startsection and #endsection tags in your pattern.
For example, we have some code pattern:
$pattern
{
@PageTitle("$eval(static['Page Title'])")
#startsection
$eval(row['Element Name'])
$eval(row['xpath'])
#endsection
}
Have created variables:
Then the result of our code pattern will be:
@PageTitle("NewTab")
Search Input Text
*//INPUT[@id = 'q']
Images
*//A[contains(text(), 'Images')]
Gmail
*//A[contains(text(), 'Gmail')]