hiptest-publisher 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +98 -0
- data/bin/hiptest-publisher +11 -0
- data/lib/hiptest-publisher.rb +121 -0
- data/lib/hiptest-publisher/call_arguments_adder.rb +63 -0
- data/lib/hiptest-publisher/handlebars_helper.rb +97 -0
- data/lib/hiptest-publisher/nodes.rb +380 -0
- data/lib/hiptest-publisher/nodes_walker.rb +45 -0
- data/lib/hiptest-publisher/options_parser.rb +225 -0
- data/lib/hiptest-publisher/parameter_type_adder.rb +139 -0
- data/lib/hiptest-publisher/parent_adder.rb +18 -0
- data/lib/hiptest-publisher/render_context_maker.rb +92 -0
- data/lib/hiptest-publisher/renderer.rb +87 -0
- data/lib/hiptest-publisher/string.rb +52 -0
- data/lib/hiptest-publisher/utils.rb +47 -0
- data/lib/hiptest-publisher/xml_parser.rb +294 -0
- data/lib/templates/common/booleanliteral.hbs +1 -0
- data/lib/templates/common/dataset.hbs +0 -0
- data/lib/templates/common/datatable.hbs +3 -0
- data/lib/templates/common/nullliteral.hbs +1 -0
- data/lib/templates/common/numericliteral.hbs +1 -0
- data/lib/templates/common/stringliteral.hbs +1 -0
- data/lib/templates/common/variable.hbs +1 -0
- data/lib/templates/java/_body.hbs +5 -0
- data/lib/templates/java/_item_as_function.hbs +6 -0
- data/lib/templates/java/_scenario.hbs +7 -0
- data/lib/templates/java/actionword.hbs +1 -0
- data/lib/templates/java/actionwords.hbs +8 -0
- data/lib/templates/java/argument.hbs +1 -0
- data/lib/templates/java/assign.hbs +1 -0
- data/lib/templates/java/binaryexpression.hbs +1 -0
- data/lib/templates/java/call.hbs +1 -0
- data/lib/templates/java/dataset.hbs +3 -0
- data/lib/templates/java/dict.hbs +1 -0
- data/lib/templates/java/field.hbs +1 -0
- data/lib/templates/java/ifthen.hbs +7 -0
- data/lib/templates/java/index.hbs +1 -0
- data/lib/templates/java/list.hbs +1 -0
- data/lib/templates/java/nullliteral.hbs +1 -0
- data/lib/templates/java/output_config +11 -0
- data/lib/templates/java/parameter.hbs +1 -0
- data/lib/templates/java/parenthesis.hbs +1 -0
- data/lib/templates/java/property.hbs +1 -0
- data/lib/templates/java/scenario.hbs +1 -0
- data/lib/templates/java/scenarios.hbs +11 -0
- data/lib/templates/java/single_scenario.hbs +11 -0
- data/lib/templates/java/single_test.hbs +11 -0
- data/lib/templates/java/step.hbs +1 -0
- data/lib/templates/java/stringliteral.hbs +1 -0
- data/lib/templates/java/tag.hbs +1 -0
- data/lib/templates/java/template.hbs +1 -0
- data/lib/templates/java/test.hbs +1 -0
- data/lib/templates/java/testng/_scenario.hbs +8 -0
- data/lib/templates/java/testng/dataset.hbs +4 -0
- data/lib/templates/java/testng/scenarios.hbs +16 -0
- data/lib/templates/java/testng/single_scenario.hbs +11 -0
- data/lib/templates/java/testng/single_test.hbs +11 -0
- data/lib/templates/java/testng/tests.hbs +16 -0
- data/lib/templates/java/tests.hbs +11 -0
- data/lib/templates/java/unaryexpression.hbs +1 -0
- data/lib/templates/java/variable.hbs +1 -0
- data/lib/templates/java/while.hbs +4 -0
- data/lib/templates/python/_body.hbs +10 -0
- data/lib/templates/python/_item_as_def.hbs +2 -0
- data/lib/templates/python/_parameters.hbs +1 -0
- data/lib/templates/python/_scenario.hbs +4 -0
- data/lib/templates/python/actionword.hbs +1 -0
- data/lib/templates/python/actionwords.hbs +9 -0
- data/lib/templates/python/argument.hbs +1 -0
- data/lib/templates/python/assign.hbs +1 -0
- data/lib/templates/python/binaryexpression.hbs +1 -0
- data/lib/templates/python/call.hbs +1 -0
- data/lib/templates/python/dataset.hbs +2 -0
- data/lib/templates/python/dict.hbs +1 -0
- data/lib/templates/python/field.hbs +1 -0
- data/lib/templates/python/ifthen.hbs +4 -0
- data/lib/templates/python/index.hbs +1 -0
- data/lib/templates/python/list.hbs +1 -0
- data/lib/templates/python/nullliteral.hbs +1 -0
- data/lib/templates/python/output_config +9 -0
- data/lib/templates/python/parameter.hbs +1 -0
- data/lib/templates/python/parenthesis.hbs +1 -0
- data/lib/templates/python/project.hbs +2 -0
- data/lib/templates/python/property.hbs +1 -0
- data/lib/templates/python/scenario.hbs +1 -0
- data/lib/templates/python/scenarios.hbs +11 -0
- data/lib/templates/python/single_scenario.hbs +9 -0
- data/lib/templates/python/single_test.hbs +9 -0
- data/lib/templates/python/step.hbs +1 -0
- data/lib/templates/python/tag.hbs +1 -0
- data/lib/templates/python/template.hbs +1 -0
- data/lib/templates/python/test.hbs +1 -0
- data/lib/templates/python/tests.hbs +11 -0
- data/lib/templates/python/unaryexpression.hbs +1 -0
- data/lib/templates/python/while.hbs +4 -0
- data/lib/templates/robotframework/_keyword.hbs +4 -0
- data/lib/templates/robotframework/_scenario.hbs +11 -0
- data/lib/templates/robotframework/actionword.hbs +1 -0
- data/lib/templates/robotframework/actionwords.hbs +4 -0
- data/lib/templates/robotframework/argument.hbs +1 -0
- data/lib/templates/robotframework/assign.hbs +1 -0
- data/lib/templates/robotframework/binaryexpression.hbs +1 -0
- data/lib/templates/robotframework/call.hbs +1 -0
- data/lib/templates/robotframework/dataset.hbs +1 -0
- data/lib/templates/robotframework/datatable.hbs +2 -0
- data/lib/templates/robotframework/dict.hbs +1 -0
- data/lib/templates/robotframework/field.hbs +1 -0
- data/lib/templates/robotframework/ifthen.hbs +1 -0
- data/lib/templates/robotframework/index.hbs +1 -0
- data/lib/templates/robotframework/list.hbs +1 -0
- data/lib/templates/robotframework/nullliteral.hbs +1 -0
- data/lib/templates/robotframework/output_config +8 -0
- data/lib/templates/robotframework/parameter.hbs +1 -0
- data/lib/templates/robotframework/parenthesis.hbs +1 -0
- data/lib/templates/robotframework/project.hbs +2 -0
- data/lib/templates/robotframework/property.hbs +1 -0
- data/lib/templates/robotframework/scenario.hbs +1 -0
- data/lib/templates/robotframework/scenarios.hbs +1 -0
- data/lib/templates/robotframework/single_scenario.hbs +11 -0
- data/lib/templates/robotframework/single_test.hbs +11 -0
- data/lib/templates/robotframework/step.hbs +1 -0
- data/lib/templates/robotframework/stringliteral.hbs +1 -0
- data/lib/templates/robotframework/tag.hbs +1 -0
- data/lib/templates/robotframework/template.hbs +1 -0
- data/lib/templates/robotframework/test.hbs +1 -0
- data/lib/templates/robotframework/tests.hbs +1 -0
- data/lib/templates/robotframework/unaryexpression.hbs +1 -0
- data/lib/templates/robotframework/variable.hbs +1 -0
- data/lib/templates/robotframework/while.hbs +1 -0
- data/lib/templates/ruby/_body.hbs +9 -0
- data/lib/templates/ruby/_item_as_def.hbs +3 -0
- data/lib/templates/ruby/_scenario.hbs +5 -0
- data/lib/templates/ruby/actionword.hbs +1 -0
- data/lib/templates/ruby/actionwords.hbs +6 -0
- data/lib/templates/ruby/argument.hbs +1 -0
- data/lib/templates/ruby/assign.hbs +1 -0
- data/lib/templates/ruby/binaryexpression.hbs +1 -0
- data/lib/templates/ruby/call.hbs +1 -0
- data/lib/templates/ruby/dataset.hbs +3 -0
- data/lib/templates/ruby/dict.hbs +1 -0
- data/lib/templates/ruby/field.hbs +1 -0
- data/lib/templates/ruby/ifthen.hbs +7 -0
- data/lib/templates/ruby/index.hbs +1 -0
- data/lib/templates/ruby/list.hbs +1 -0
- data/lib/templates/ruby/minitest/_item_as_def.hbs +3 -0
- data/lib/templates/ruby/minitest/_scenario.hbs +4 -0
- data/lib/templates/ruby/minitest/dataset.hbs +3 -0
- data/lib/templates/ruby/minitest/output_config +6 -0
- data/lib/templates/ruby/minitest/scenario.hbs +1 -0
- data/lib/templates/ruby/minitest/scenarios.hbs +13 -0
- data/lib/templates/ruby/minitest/single_scenario.hbs +11 -0
- data/lib/templates/ruby/minitest/single_test.hbs +11 -0
- data/lib/templates/ruby/minitest/test.hbs +1 -0
- data/lib/templates/ruby/minitest/tests.hbs +13 -0
- data/lib/templates/ruby/output_config +6 -0
- data/lib/templates/ruby/parameter.hbs +1 -0
- data/lib/templates/ruby/parenthesis.hbs +1 -0
- data/lib/templates/ruby/project.hbs +2 -0
- data/lib/templates/ruby/property.hbs +1 -0
- data/lib/templates/ruby/scenario.hbs +1 -0
- data/lib/templates/ruby/scenarios.hbs +12 -0
- data/lib/templates/ruby/single_scenario.hbs +11 -0
- data/lib/templates/ruby/single_test.hbs +11 -0
- data/lib/templates/ruby/step.hbs +1 -0
- data/lib/templates/ruby/tag.hbs +1 -0
- data/lib/templates/ruby/template.hbs +1 -0
- data/lib/templates/ruby/test.hbs +1 -0
- data/lib/templates/ruby/tests.hbs +12 -0
- data/lib/templates/ruby/unaryexpression.hbs +1 -0
- data/lib/templates/ruby/while.hbs +5 -0
- data/lib/templates/seleniumide/argument.hbs +1 -0
- data/lib/templates/seleniumide/call.hbs +6 -0
- data/lib/templates/seleniumide/output_config +9 -0
- data/lib/templates/seleniumide/single_test.hbs +28 -0
- data/lib/templates/seleniumide/step.hbs +0 -0
- data/lib/templates/seleniumide/stringliteral.hbs +1 -0
- data/lib/templates/seleniumide/template.hbs +1 -0
- data/lib/templates/seleniumide/test.hbs +4 -0
- data/lib/templates/seleniumide/tests.hbs +19 -0
- metadata +404 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5a5e8d4f38038c17b0009f6824c62008381c394d
|
4
|
+
data.tar.gz: c233e7e0b2947c037c04d2551509c3faf12cc4f4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3f9a95295875103d1b18c083f98a99b85a113c5fc19344715c94ec9df2b9306b50e94fc467c5707d7c8cb68c513dfa0f8ba11174fbcb58e60bab2e174c8a4eef
|
7
|
+
data.tar.gz: ea856f6b89ba0c981b73768d7e5f1408782ea5a5c5d30bc291d0b10655e0a024962279873ff307ea97971fe8ac83dcebaf97db960622285917291a89f7c5bbb7
|
data/README.md
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
Hiptest Publisher
|
2
|
+
==============
|
3
|
+
|
4
|
+
[![Build Status](https://travis-ci.org/Smartesting/zest-publisher.svg?branch=master)](https://travis-ci.org/Smartesting/zest-publisher)
|
5
|
+
[![Gem version](https://badge.fury.io/rb/zest-publisher.svg)](http://badge.fury.io/rb/zest-publisher)
|
6
|
+
[![Code climate](https://codeclimate.com/github/Smartesting/zest-publisher.png)](https://codeclimate.com/github/Smartesting/zest-publisher)
|
7
|
+
[![Coverage](https://codeclimate.com/github/Smartesting/zest-publisher/coverage.png)](https://codeclimate.com/github/Smartesting/zest-publisher)
|
8
|
+
[![Dependencies](https://gemnasium.com/Smartesting/zest-publisher.svg)](https://gemnasium.com/Smartesting/zest-publisher)
|
9
|
+
|
10
|
+
|
11
|
+
Installing
|
12
|
+
----------
|
13
|
+
|
14
|
+
You need to have [Ruby installed on your machine](https://www.ruby-lang.org/en/installation/). You can then install it using gem:
|
15
|
+
|
16
|
+
```shell
|
17
|
+
gem install hiptest-publisher
|
18
|
+
```
|
19
|
+
|
20
|
+
Exporting a project
|
21
|
+
-------------------
|
22
|
+
|
23
|
+
Go to one of your [Hiptest projects](https://hiptest.net/#/projects) and select the Settings tab.
|
24
|
+
This tab is available only for projects you own.
|
25
|
+
From there, copy the secret token and run this command line:
|
26
|
+
|
27
|
+
```shell
|
28
|
+
hiptest-publisher --token=<YOUR TOKEN>
|
29
|
+
```
|
30
|
+
|
31
|
+
This will create a Ruby tests suite. For the moment, we support the following languages and frameworks:
|
32
|
+
|
33
|
+
- Ruby (rspec / minitest)
|
34
|
+
- Python (unittest)
|
35
|
+
- Java (JUnit)
|
36
|
+
|
37
|
+
You can specify the output language and framework in the command line, for example:
|
38
|
+
|
39
|
+
```shell
|
40
|
+
hiptest-publisher --token=<YOUR TOKEN> --language=ruby --framework=minitest
|
41
|
+
```
|
42
|
+
|
43
|
+
|
44
|
+
For more information on the available options, use the following command:
|
45
|
+
|
46
|
+
```shell
|
47
|
+
hiptest-publisher --help
|
48
|
+
```
|
49
|
+
|
50
|
+
You could obtain for example:
|
51
|
+
|
52
|
+
```shell
|
53
|
+
Specific options:
|
54
|
+
-t, --token=TOKEN Secret token (available in your project settings)
|
55
|
+
-l, --language=LANG Target language (default: ruby)
|
56
|
+
-f, --framework=FRAMEWORK Test framework to use
|
57
|
+
-o, --output-directory=PATH Output directory (default: .)
|
58
|
+
-c, --config-file=PATH Configuration file (default: config)
|
59
|
+
--scenario-ids=IDS Filter scenarios by ids
|
60
|
+
--scenario-tags=TAGS Filter scenarios by tags
|
61
|
+
--tests-only Export only the tests (default: false)
|
62
|
+
--actionwords-only Export only the actionwords (default: false)
|
63
|
+
--split-scenarios Export each scenario in a single file (default: false)
|
64
|
+
--leafless-export Use only last level action word (default: false)
|
65
|
+
-s, --site=SITE Site to fetch from (default: https://hiptest.net)
|
66
|
+
-v, --verbose Run verbosely (default: false)
|
67
|
+
-H, --languages-help Show languages and framework options
|
68
|
+
-F, --filters-help Show help about scenario filtering
|
69
|
+
-h, --help Show this message
|
70
|
+
```
|
71
|
+
|
72
|
+
Configuration
|
73
|
+
-------------
|
74
|
+
|
75
|
+
You have the possibility to store some configuration in a file named 'config'. Copy the file config.sample provided here and update the values with the values you use.
|
76
|
+
|
77
|
+
If you have multiple projects, you can have multiple config files and select one using the --config-file option:
|
78
|
+
|
79
|
+
```shell
|
80
|
+
# Use the default config file
|
81
|
+
hiptest-publisher
|
82
|
+
# Use the one to export as minitest
|
83
|
+
hiptest-publisher --config-file=config_minitest
|
84
|
+
```
|
85
|
+
|
86
|
+
For example, for java you can use this config file content:
|
87
|
+
|
88
|
+
```
|
89
|
+
token = '<YOUR TOKEN>'
|
90
|
+
language = 'java'
|
91
|
+
output_directory = '<YOUR OUTPUT DIRECTORY>'
|
92
|
+
package = 'com.youcompagny'
|
93
|
+
```
|
94
|
+
|
95
|
+
Adding support for other languages and framework
|
96
|
+
------------------------------------------------
|
97
|
+
|
98
|
+
See the [CONTRIBUTING](https://github.com/hiptest/hiptest-publisher/blob/master/docs/CONTRIBUTING.md>) help page for more information.
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'colorize'
|
2
|
+
|
3
|
+
require 'hiptest-publisher/string'
|
4
|
+
require 'hiptest-publisher/utils'
|
5
|
+
require 'hiptest-publisher/options_parser'
|
6
|
+
require 'hiptest-publisher/xml_parser'
|
7
|
+
require 'hiptest-publisher/parent_adder'
|
8
|
+
require 'hiptest-publisher/parameter_type_adder'
|
9
|
+
require 'hiptest-publisher/call_arguments_adder'
|
10
|
+
|
11
|
+
module Hiptest
|
12
|
+
class Publisher
|
13
|
+
def initialize(args)
|
14
|
+
@options = OptionsParser.parse(args)
|
15
|
+
|
16
|
+
xml = fetch_xml_file
|
17
|
+
return if xml.nil?
|
18
|
+
|
19
|
+
@project = get_project(xml)
|
20
|
+
end
|
21
|
+
|
22
|
+
def fetch_xml_file
|
23
|
+
show_status_message "Fetching data from Hiptest"
|
24
|
+
xml = fetch_project_export(@options)
|
25
|
+
show_status_message "Fetching data from Hiptest", :success
|
26
|
+
|
27
|
+
return xml
|
28
|
+
rescue Exception => err
|
29
|
+
show_status_message "Fetching data from Hiptest", :failure
|
30
|
+
puts "Unable to open the file, please check that the token is correct".red
|
31
|
+
trace_exception(err) if @options.verbose
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_project(xml)
|
35
|
+
show_status_message "Extracting data"
|
36
|
+
parser = Hiptest::XMLParser.new(xml, @options)
|
37
|
+
show_status_message "Extracting data", :success
|
38
|
+
|
39
|
+
return parser.build_project
|
40
|
+
end
|
41
|
+
|
42
|
+
def write_node_to_file(path, node, context, message)
|
43
|
+
status_message = "#{message}: #{path}"
|
44
|
+
begin
|
45
|
+
show_status_message status_message
|
46
|
+
File.open(path, 'w') do |file|
|
47
|
+
file.write(Hiptest::Renderer.render(node, @options.language, context))
|
48
|
+
end
|
49
|
+
|
50
|
+
show_status_message status_message, :success
|
51
|
+
rescue Exception => err
|
52
|
+
show_status_message status_message, :failure
|
53
|
+
trace_exception(err) if @options.verbose
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def export_tests
|
58
|
+
if @options.split_scenarios
|
59
|
+
@project.children[:tests].children[:tests].each do |test|
|
60
|
+
context = @language_config.tests_render_context
|
61
|
+
context[:test_file_name] = @language_config.scenario_output_file(test.children[:name])
|
62
|
+
|
63
|
+
write_node_to_file(
|
64
|
+
@language_config.scenario_output_dir(test.children[:name]),
|
65
|
+
test,
|
66
|
+
context,
|
67
|
+
"Exporting test \"#{test.children[:name]}\"")
|
68
|
+
end
|
69
|
+
else
|
70
|
+
write_node_to_file(
|
71
|
+
@language_config.tests_output_dir,
|
72
|
+
@project.children[:tests],
|
73
|
+
@language_config.tests_render_context,
|
74
|
+
"Exporting tests")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def export_scenarios
|
79
|
+
if @options.split_scenarios
|
80
|
+
@project.children[:scenarios].children[:scenarios].each do |scenario|
|
81
|
+
context = @language_config.tests_render_context
|
82
|
+
context[:test_file_name] = @language_config.scenario_output_file(scenario.children[:name])
|
83
|
+
|
84
|
+
write_node_to_file(
|
85
|
+
@language_config.scenario_output_dir(scenario.children[:name]),
|
86
|
+
scenario,
|
87
|
+
context,
|
88
|
+
"Exporting scenario \"#{scenario.children[:name]}\"")
|
89
|
+
end
|
90
|
+
else
|
91
|
+
write_node_to_file(
|
92
|
+
@language_config.tests_output_dir,
|
93
|
+
@project.children[:scenarios],
|
94
|
+
@language_config.tests_render_context,
|
95
|
+
"Exporting scenarios")
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def export_actionwords
|
100
|
+
write_node_to_file(
|
101
|
+
@language_config.aw_output_dir,
|
102
|
+
@project.children[:actionwords],
|
103
|
+
@language_config.actionword_render_context,
|
104
|
+
"Exporting actionwords"
|
105
|
+
)
|
106
|
+
end
|
107
|
+
|
108
|
+
def export
|
109
|
+
@language_config = LanguageConfigParser.new(@options)
|
110
|
+
Hiptest::Nodes::ParentAdder.add(@project)
|
111
|
+
Hiptest::Nodes::ParameterTypeAdder.add(@project)
|
112
|
+
Hiptest::DefaultArgumentAdder.add(@project)
|
113
|
+
|
114
|
+
unless @options.actionwords_only
|
115
|
+
@options.leafless_export ? export_tests : export_scenarios
|
116
|
+
end
|
117
|
+
|
118
|
+
export_actionwords unless @options.tests_only
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'hiptest-publisher/nodes'
|
2
|
+
|
3
|
+
module Hiptest
|
4
|
+
class DefaultArgumentAdder
|
5
|
+
def self.add(project)
|
6
|
+
DefaultArgumentAdder.new(project).update_calls
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(project)
|
10
|
+
@project = project
|
11
|
+
@indexer = ActionwordIndexer.new(project)
|
12
|
+
end
|
13
|
+
|
14
|
+
def update_calls
|
15
|
+
@project.find_sub_nodes(Hiptest::Nodes::Call).each do |call|
|
16
|
+
aw_data = @indexer.get_index(call.children[:actionword])
|
17
|
+
next if aw_data.nil?
|
18
|
+
|
19
|
+
arguments = {}
|
20
|
+
call.children[:arguments].each do |arg|
|
21
|
+
arguments[arg.children[:name]] = arg.children[:value]
|
22
|
+
end
|
23
|
+
|
24
|
+
call.children[:all_arguments] = aw_data[:parameters].map do |p_name, default_value|
|
25
|
+
Hiptest::Nodes::Argument.new(
|
26
|
+
p_name,
|
27
|
+
arguments.has_key?(p_name) ? arguments[p_name] : default_value
|
28
|
+
)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class ActionwordIndexer
|
35
|
+
def initialize(project)
|
36
|
+
@project = project
|
37
|
+
@indexed = {}
|
38
|
+
index_actionwords
|
39
|
+
end
|
40
|
+
|
41
|
+
def index_actionwords
|
42
|
+
@project.find_sub_nodes(Hiptest::Nodes::Actionword).each do |aw|
|
43
|
+
aw_name = aw.children[:name]
|
44
|
+
indexed_parameters = {}
|
45
|
+
|
46
|
+
aw.children[:parameters].map do |param|
|
47
|
+
param_name = param.children[:name]
|
48
|
+
indexed_parameters[param_name] = param.children[:default]
|
49
|
+
end
|
50
|
+
|
51
|
+
@indexed[aw_name] = {
|
52
|
+
:actionword => aw,
|
53
|
+
:parameters => indexed_parameters
|
54
|
+
}
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def get_index(name)
|
60
|
+
@indexed[name]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module Hiptest
|
2
|
+
class HandlebarsHelper
|
3
|
+
def self.register_helpers(handlebars, context)
|
4
|
+
instance = Hiptest::HandlebarsHelper.new(handlebars, context)
|
5
|
+
instance.register_string_helpers
|
6
|
+
instance.register_custom_helpers
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(handlebars, context)
|
10
|
+
@handlebars = handlebars
|
11
|
+
@context = context
|
12
|
+
end
|
13
|
+
|
14
|
+
def register_string_helpers
|
15
|
+
string_helpers = [
|
16
|
+
:literate,
|
17
|
+
:normalize,
|
18
|
+
:normalize_lower,
|
19
|
+
:underscore,
|
20
|
+
:camelize,
|
21
|
+
:camelize_lower,
|
22
|
+
:clear_extension
|
23
|
+
]
|
24
|
+
|
25
|
+
string_helpers.each do |helper|
|
26
|
+
@handlebars.register_helper(helper) do |context, value|
|
27
|
+
"#{value.to_s.send(helper)}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def register_custom_helpers
|
33
|
+
self.class.instance_methods.each do |method_name|
|
34
|
+
next unless method_name.to_s.start_with? 'hh_'
|
35
|
+
@handlebars.register_helper(method_name.to_s.gsub(/hh_/, '')) do |*args|
|
36
|
+
send(method_name, *args)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def hh_to_string(context, value, block)
|
42
|
+
"#{value.to_s}"
|
43
|
+
end
|
44
|
+
|
45
|
+
def hh_join(context, items, joiner, block)
|
46
|
+
joiner = "\t" if joiner == '\t'
|
47
|
+
"#{items.join(joiner)}"
|
48
|
+
end
|
49
|
+
|
50
|
+
def hh_indent(context, block)
|
51
|
+
indentation = @context[:indentation] || ' '
|
52
|
+
indentation = "\t" if indentation == '\t'
|
53
|
+
|
54
|
+
block.fn(context).split("\n").map do |line|
|
55
|
+
indented = "#{indentation}#{line}"
|
56
|
+
indented = "" if indented.strip.empty?
|
57
|
+
indented
|
58
|
+
end.join("\n")
|
59
|
+
end
|
60
|
+
|
61
|
+
def hh_clear_empty_lines(context, block)
|
62
|
+
block.fn(context).split("\n").map do |line|
|
63
|
+
line unless line.strip.empty?
|
64
|
+
end.compact.join("\n")
|
65
|
+
end
|
66
|
+
|
67
|
+
def hh_remove_quotes (context, s, block)
|
68
|
+
"#{s.gsub('"', '')}"
|
69
|
+
end
|
70
|
+
|
71
|
+
def hh_escape_quotes (context, s, block)
|
72
|
+
"#{s.gsub(/"/) {|_| '\\"' }}"
|
73
|
+
end
|
74
|
+
|
75
|
+
def hh_comment (context, commenter, block)
|
76
|
+
block.fn(context).split("\n").map do |line|
|
77
|
+
"#{commenter} #{line}"
|
78
|
+
end.join("\n")
|
79
|
+
end
|
80
|
+
|
81
|
+
def hh_curly (context, block)
|
82
|
+
"{#{block.fn(context)}}"
|
83
|
+
end
|
84
|
+
|
85
|
+
def hh_open_curly (context, block)
|
86
|
+
"{"
|
87
|
+
end
|
88
|
+
|
89
|
+
def hh_close_curly (context, block)
|
90
|
+
"}"
|
91
|
+
end
|
92
|
+
|
93
|
+
def hh_tab (context, block)
|
94
|
+
"\t"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,380 @@
|
|
1
|
+
require 'hiptest-publisher/string'
|
2
|
+
require 'hiptest-publisher/utils'
|
3
|
+
require 'hiptest-publisher/renderer'
|
4
|
+
|
5
|
+
module Hiptest
|
6
|
+
module Nodes
|
7
|
+
class Node
|
8
|
+
attr_reader :children, :parent
|
9
|
+
attr_writer :parent
|
10
|
+
|
11
|
+
def render(language = 'ruby', context = {})
|
12
|
+
return Hiptest::Renderer.render(self, language, context)
|
13
|
+
end
|
14
|
+
|
15
|
+
def find_sub_nodes(types = [])
|
16
|
+
sub_nodes = all_sub_nodes
|
17
|
+
types = [types] unless types.is_a?(Array)
|
18
|
+
|
19
|
+
if types.empty?
|
20
|
+
sub_nodes
|
21
|
+
else
|
22
|
+
sub_nodes.keep_if do |node|
|
23
|
+
types.map {|type| node.is_a?(type)}.include?(true)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def direct_children
|
29
|
+
direct = []
|
30
|
+
|
31
|
+
children.each do |key, child|
|
32
|
+
if child.is_a? Hiptest::Nodes::Node
|
33
|
+
direct << child
|
34
|
+
elsif child.is_a? Array
|
35
|
+
child.each {|c| direct << c if c.is_a? Hiptest::Nodes::Node }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
direct
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def all_sub_nodes
|
45
|
+
path = [self]
|
46
|
+
children = []
|
47
|
+
|
48
|
+
until path.empty?
|
49
|
+
current_node = path.pop
|
50
|
+
|
51
|
+
if current_node.is_a?(Node)
|
52
|
+
next if children.include? current_node
|
53
|
+
|
54
|
+
children << current_node
|
55
|
+
current_node.children.values.reverse.each {|item| path << item}
|
56
|
+
elsif current_node.is_a?(Array)
|
57
|
+
current_node.reverse.each {|item| path << item}
|
58
|
+
end
|
59
|
+
end
|
60
|
+
children
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class Literal < Node
|
65
|
+
def initialize(value)
|
66
|
+
super()
|
67
|
+
@children = {:value => value}
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
class NullLiteral < Node
|
72
|
+
def initialize
|
73
|
+
super()
|
74
|
+
@children = {}
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
class StringLiteral < Literal
|
79
|
+
end
|
80
|
+
|
81
|
+
class NumericLiteral < Literal
|
82
|
+
end
|
83
|
+
|
84
|
+
class BooleanLiteral < Literal
|
85
|
+
end
|
86
|
+
|
87
|
+
class Variable < Node
|
88
|
+
def initialize(name)
|
89
|
+
super()
|
90
|
+
@children = {:name => name}
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
class Property < Node
|
95
|
+
def initialize(key, value)
|
96
|
+
super()
|
97
|
+
@children = {:key => key, :value => value}
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
class Field < Node
|
102
|
+
def initialize(base, name)
|
103
|
+
super()
|
104
|
+
@children = {:base => base, :name => name}
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
class Index < Node
|
109
|
+
def initialize(base, expression)
|
110
|
+
super()
|
111
|
+
@children = {:base => base, :expression => expression}
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
class BinaryExpression < Node
|
116
|
+
def initialize(left, operator, right)
|
117
|
+
super()
|
118
|
+
@children = {:operator => operator, :left => left, :right => right}
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
class UnaryExpression < Node
|
123
|
+
def initialize(operator, expression)
|
124
|
+
super()
|
125
|
+
@children = {:operator => operator, :expression => expression}
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
class Parenthesis < Node
|
130
|
+
def initialize(content)
|
131
|
+
super()
|
132
|
+
@children = {:content => content}
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
class List < Node
|
137
|
+
def initialize(items)
|
138
|
+
super()
|
139
|
+
@children = {:items => items}
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
class Dict < Node
|
144
|
+
def initialize(items)
|
145
|
+
super()
|
146
|
+
@children = {:items => items}
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
class Template < Node
|
151
|
+
def initialize(chunks)
|
152
|
+
super()
|
153
|
+
@children = {:chunks => chunks}
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
class Assign < Node
|
158
|
+
def initialize(to, value)
|
159
|
+
super()
|
160
|
+
@children = {:to => to, :value => value}
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
class Argument < Node
|
165
|
+
def initialize(name, value)
|
166
|
+
super()
|
167
|
+
@children = {:name => name, :value => value}
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
class Call < Node
|
172
|
+
def initialize(actionword, arguments = [])
|
173
|
+
super()
|
174
|
+
@children = {:actionword => actionword, :arguments => arguments}
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
class IfThen < Node
|
179
|
+
def initialize(condition, then_, else_ = [])
|
180
|
+
super()
|
181
|
+
@children = {:condition => condition, :then => then_, :else => else_}
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
class Step < Node
|
186
|
+
def initialize(key, value)
|
187
|
+
super()
|
188
|
+
@children = {:key => key, :value => value}
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
class While < Node
|
193
|
+
def initialize(condition, body)
|
194
|
+
super()
|
195
|
+
@children = {:condition => condition, :body => body}
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
class Tag < Node
|
200
|
+
def initialize(key, value = nil)
|
201
|
+
super()
|
202
|
+
@children = {:key => key, :value => value}
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
class Parameter < Node
|
207
|
+
def initialize(name, default = nil)
|
208
|
+
super()
|
209
|
+
@children = {:name => name, :default => default}
|
210
|
+
end
|
211
|
+
|
212
|
+
def type
|
213
|
+
if @children[:type].nil?
|
214
|
+
'String'
|
215
|
+
else
|
216
|
+
@children[:type].to_s
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
class Item < Node
|
222
|
+
attr_reader :variables, :non_valued_parameters, :valued_parameters
|
223
|
+
|
224
|
+
def initialize(name, tags = [], parameters = [], body = [])
|
225
|
+
super()
|
226
|
+
@children = {
|
227
|
+
:name => name,
|
228
|
+
:tags => tags,
|
229
|
+
:parameters => parameters,
|
230
|
+
:body => body
|
231
|
+
}
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
class Actionword < Item
|
236
|
+
end
|
237
|
+
|
238
|
+
class Scenario < Item
|
239
|
+
attr_reader :folder_uid
|
240
|
+
|
241
|
+
def initialize(name, description = '', tags = [], parameters = [], body = [], folder_uid = nil, datatable = Datatable.new)
|
242
|
+
super(name, tags, parameters, body)
|
243
|
+
@children[:description] = description
|
244
|
+
@children[:datatable] = datatable
|
245
|
+
|
246
|
+
@folder_uid = folder_uid
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
class Test < Node
|
251
|
+
def initialize(name, description = '', tags = [], body = [])
|
252
|
+
super()
|
253
|
+
|
254
|
+
@children = {
|
255
|
+
:name => name,
|
256
|
+
:description => description,
|
257
|
+
:tags => tags,
|
258
|
+
:body => body
|
259
|
+
}
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
class Datatable < Node
|
264
|
+
def initialize(datasets = [])
|
265
|
+
super()
|
266
|
+
|
267
|
+
@children = {
|
268
|
+
:datasets => datasets
|
269
|
+
}
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
class Dataset < Node
|
274
|
+
def initialize(name, arguments = [])
|
275
|
+
super()
|
276
|
+
|
277
|
+
@children = {
|
278
|
+
:name => name,
|
279
|
+
:arguments => arguments
|
280
|
+
}
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
class Actionwords < Node
|
285
|
+
def initialize(actionwords = [])
|
286
|
+
super()
|
287
|
+
@children = {:actionwords => actionwords}
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
class Scenarios < Node
|
292
|
+
def initialize(scenarios = [])
|
293
|
+
super()
|
294
|
+
@children = {:scenarios => scenarios}
|
295
|
+
scenarios.each {|sc| sc.parent = self}
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
class Tests < Node
|
300
|
+
def initialize(tests = [])
|
301
|
+
super()
|
302
|
+
@children = {:tests => tests}
|
303
|
+
tests.each {|test| test.parent = self}
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
class Folder < Node
|
308
|
+
attr_reader :uid, :parent, :parent_uid
|
309
|
+
attr_writer :parent
|
310
|
+
|
311
|
+
def initialize(uid, parent_uid, name)
|
312
|
+
super()
|
313
|
+
|
314
|
+
@uid = uid
|
315
|
+
@parent_uid = parent_uid
|
316
|
+
|
317
|
+
@children = {
|
318
|
+
:name => name,
|
319
|
+
:subfolders => [],
|
320
|
+
:scenarios => []
|
321
|
+
}
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
325
|
+
class TestPlan < Node
|
326
|
+
def initialize(folders = [])
|
327
|
+
super()
|
328
|
+
@uids_mapping = {}
|
329
|
+
@children = {
|
330
|
+
:root_folder => nil,
|
331
|
+
:folders => folders
|
332
|
+
}
|
333
|
+
end
|
334
|
+
|
335
|
+
def organize_folders
|
336
|
+
@children[:folders].each do |folder|
|
337
|
+
@uids_mapping[folder.uid] = folder
|
338
|
+
parent = find_folder_by_uid folder.parent_uid
|
339
|
+
if parent.nil?
|
340
|
+
@children[:root_folder] = folder
|
341
|
+
next
|
342
|
+
end
|
343
|
+
|
344
|
+
folder.parent = parent
|
345
|
+
parent.children[:subfolders] << folder
|
346
|
+
end
|
347
|
+
end
|
348
|
+
|
349
|
+
def find_folder_by_uid(uid)
|
350
|
+
return @uids_mapping[uid]
|
351
|
+
end
|
352
|
+
end
|
353
|
+
|
354
|
+
class Project < Node
|
355
|
+
def initialize(name, description = '', test_plan = TestPlan.new, scenarios = Scenarios.new, actionwords = Actionwords.new, tests = Tests.new)
|
356
|
+
super()
|
357
|
+
scenarios.parent = self
|
358
|
+
tests.parent = self
|
359
|
+
|
360
|
+
@children = {
|
361
|
+
:name => name,
|
362
|
+
:description => description,
|
363
|
+
:test_plan => test_plan,
|
364
|
+
:scenarios => scenarios,
|
365
|
+
:actionwords => actionwords,
|
366
|
+
:tests => tests
|
367
|
+
}
|
368
|
+
end
|
369
|
+
|
370
|
+
def assign_scenarios_to_folders
|
371
|
+
@children[:scenarios].children[:scenarios].each do |scenario|
|
372
|
+
folder = @children[:test_plan].find_folder_by_uid(scenario.folder_uid)
|
373
|
+
next if folder.nil?
|
374
|
+
|
375
|
+
folder.children[:scenarios] << scenario
|
376
|
+
end
|
377
|
+
end
|
378
|
+
end
|
379
|
+
end
|
380
|
+
end
|