Module: Allure

Extended by:
Allure
Included in:
Allure
Defined in:
allure-ruby-commons/lib/allure-ruby-commons.rb,
allure-ruby-commons/lib/allure_ruby_commons/config.rb,
allure-ruby-commons/lib/allure_ruby_commons/testplan.rb,
allure-ruby-commons/lib/allure_ruby_commons/model/link.rb,
allure-ruby-commons/lib/allure_ruby_commons/file_writer.rb,
allure-ruby-commons/lib/allure_ruby_commons/model/label.rb,
allure-ruby-commons/lib/allure_ruby_commons/model/stage.rb,
allure-ruby-commons/lib/allure_ruby_commons/_json_helper.rb,
allure-ruby-commons/lib/allure_ruby_commons/model/status.rb,
allure-ruby-commons/lib/allure_ruby_commons/result_utils.rb,
allure-ruby-commons/lib/allure_ruby_commons/model/category.rb,
allure-ruby-commons/lib/allure_ruby_commons/model/parameter.rb,
allure-ruby-commons/lib/allure_ruby_commons/allure_lifecycle.rb,
allure-ruby-commons/lib/allure_ruby_commons/model/attachment.rb,
allure-ruby-commons/lib/allure_ruby_commons/model/01_jsonable.rb,
allure-ruby-commons/lib/allure_ruby_commons/model/step_result.rb,
allure-ruby-commons/lib/allure_ruby_commons/model/test_result.rb,
allure-ruby-commons/lib/allure_ruby_commons/model/content_type.rb,
allure-ruby-commons/lib/allure_ruby_commons/model/fixture_result.rb,
allure-ruby-commons/lib/allure_ruby_commons/model/status_details.rb,
allure-ruby-commons/lib/allure_ruby_commons/model/executable_item.rb,
allure-ruby-commons/lib/allure_ruby_commons/model/test_result_container.rb

Overview

Namespace for classes that handle allure report generation and different framework adaptors

Defined Under Namespace

Modules: JsonHelper, ResultUtils Classes: AllureLifecycle, Attachment, Category, Config, ContentType, ExecutableItem, FileWriter, FixtureResult, JSONable, Label, Link, Parameter, Stage, Status, StatusDetails, StepResult, TestPlan, TestResult, TestResultContainer

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.lifecycle=(lifecycle) ⇒ void

This method returns an undefined value.

Set lifecycle object

Parameters:



14
15
16
# File 'allure-ruby-commons/lib/allure-ruby-commons.rb', line 14

def self.lifecycle=(lifecycle)
  Thread.current[:lifecycle] = lifecycle
end

Instance Method Details

#add_attachment(name:, source:, type:, test_case: false) ⇒ void

This method returns an undefined value.

Add attachment to current test case or step

Parameters:

  • name (String)

    Attachment name

  • source (File, String)

    File or string to save as attachment

  • type (String)

    attachment type defined in ContentType or any other valid mime type

  • test_case (Boolean) (defaults to: false)

    add attachment to current test case instead of test step



160
161
162
# File 'allure-ruby-commons/lib/allure-ruby-commons.rb', line 160

def add_attachment(name:, source:, type:, test_case: false)
  lifecycle.add_attachment(name: name, source: source, type: type, test_case: test_case)
end

#add_categories(categories) ⇒ void

This method returns an undefined value.

Manually create categories.json file

if this method is called before test run started and
option clean_results_directory is enabled, the file will be deleted

Parameters:



178
179
180
# File 'allure-ruby-commons/lib/allure-ruby-commons.rb', line 178

def add_categories(categories)
  lifecycle.write_categories(categories)
end

#add_description(description) ⇒ void

This method returns an undefined value.

Add description to current test case

Parameters:

  • description (String)


102
103
104
105
106
# File 'allure-ruby-commons/lib/allure-ruby-commons.rb', line 102

def add_description(description)
  lifecycle.update_test_case do |test_case|
    test_case.description = description
  end
end

#add_environment(environment) ⇒ void

This method returns an undefined value.

Manually create environment.properties file

if this method is called before test run started and
option clean_results_directory is enabled, the file will be deleted

Parameters:

  • environment (Hash<Symbol, String>, Proc)


169
170
171
# File 'allure-ruby-commons/lib/allure-ruby-commons.rb', line 169

def add_environment(environment)
  lifecycle.write_environment(environment)
end

This method returns an undefined value.

Add link to current test case

Parameters:

  • url (String)
  • name (String) (defaults to: nil)
  • type (String) (defaults to: "custom")

    type of the link used to display link icon



148
149
150
151
152
# File 'allure-ruby-commons/lib/allure-ruby-commons.rb', line 148

def add_link(url:, name: nil, type: "custom")
  lifecycle.update_test_case do |test_case|
    test_case.links.push(Link.new(type, name || url, url))
  end
end

#configurationConfig

Get allure configuration

Returns:



28
29
30
# File 'allure-ruby-commons/lib/allure-ruby-commons.rb', line 28

def configuration
  Config.instance
end

#configure {|| ... } ⇒ void

This method returns an undefined value.

Set allure configuration

Yield Parameters:

Yield Returns:

  • (void)


36
37
38
# File 'allure-ruby-commons/lib/allure-ruby-commons.rb', line 36

def configure
  yield(configuration)
end

#description_html(description_html) ⇒ void

This method returns an undefined value.

Add html description to current test case

Parameters:

  • description_html (String)


111
112
113
114
115
# File 'allure-ruby-commons/lib/allure-ruby-commons.rb', line 111

def description_html(description_html)
  lifecycle.update_test_case do |test_case|
    test_case.description_html = description_html
  end
end

#epic(value) ⇒ void

This method returns an undefined value.

Add epic to current test case

Parameters:

  • value (String)


43
44
45
# File 'allure-ruby-commons/lib/allure-ruby-commons.rb', line 43

def epic(value)
  replace_label(ResultUtils::EPIC_LABEL_NAME, value)
end

#feature(value) ⇒ void

This method returns an undefined value.

Add feature to current test case

Parameters:

  • value (String)


50
51
52
# File 'allure-ruby-commons/lib/allure-ruby-commons.rb', line 50

def feature(value)
  replace_label(ResultUtils::FEATURE_LABEL_NAME, value)
end

#issue(name, url) ⇒ void

This method returns an undefined value.

Add issue linkt to current test case

Parameters:

  • name (String)
  • url (String)


139
140
141
# File 'allure-ruby-commons/lib/allure-ruby-commons.rb', line 139

def issue(name, url)
  add_link(name: name, url: url, type: ResultUtils::ISSUE_LINK_TYPE)
end

#label(name, value) ⇒ void

This method returns an undefined value.

Add label to current test case

Parameters:

  • name (String)
  • value (String)


79
80
81
82
83
# File 'allure-ruby-commons/lib/allure-ruby-commons.rb', line 79

def label(name, value)
  lifecycle.update_test_case do |test_case|
    test_case.labels.push(Label.new(name, value))
  end
end

#lifecycleAllureLifecycle

Get thread specific allure lifecycle object

Returns:



22
23
24
# File 'allure-ruby-commons/lib/allure-ruby-commons.rb', line 22

def lifecycle
  Thread.current[:lifecycle] ||= AllureLifecycle.new
end

#parameter(name, value) ⇒ void

This method returns an undefined value.

Add parameter to current test case

Parameters:

  • name (String)
  • value (String)


121
122
123
124
125
# File 'allure-ruby-commons/lib/allure-ruby-commons.rb', line 121

def parameter(name, value)
  lifecycle.update_test_case do |test_case|
    test_case.parameters.push(Parameter.new(name, value))
  end
end

#replace_label(name, value) ⇒ void

This method returns an undefined value.

Replace label in current test case

Parameters:

  • name (String)
  • value (String)


90
91
92
93
94
95
96
97
# File 'allure-ruby-commons/lib/allure-ruby-commons.rb', line 90

def replace_label(name, value)
  lifecycle.update_test_case do |test_case|
    present = test_case.labels.detect { |l| l.name == name }
    return label(name, value) unless present

    test_case.labels.map! { |l| l.name == name ? Label.new(name, value) : l }
  end
end

#run_step(name) { ... } ⇒ Object

Run passed block as step with given name and return result of yield

Parameters:

  • name (String)

Yields:

  • step block

Returns:

  • (Object)


222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'allure-ruby-commons/lib/allure-ruby-commons.rb', line 222

def run_step(name)
  lifecycle.start_test_step(StepResult.new(name: name, stage: Stage::RUNNING))
  result = yield
  lifecycle.update_test_step { |step| step.status = Status::PASSED }

  result
rescue StandardError, RSpec::Expectations::ExpectationNotMetError => e
  lifecycle.update_test_step do |step|
    step.status = ResultUtils.status(e)
    step.status_details = ResultUtils.status_details(e)
  end
  raise(e)
ensure
  lifecycle.stop_test_step
end

#set_flakyvoid

This method returns an undefined value.

Set test case status detail to flaky



185
186
187
188
189
# File 'allure-ruby-commons/lib/allure-ruby-commons.rb', line 185

def set_flaky
  lifecycle.update_test_case do |test_case|
    test_case.status_details.flaky = true
  end
end

#set_knownvoid

This method returns an undefined value.

Set test case status detail to known



203
204
205
206
207
# File 'allure-ruby-commons/lib/allure-ruby-commons.rb', line 203

def set_known
  lifecycle.update_test_case do |test_case|
    test_case.status_details.known = true
  end
end

#set_mutedvoid

This method returns an undefined value.

Set test case status detail to muted



194
195
196
197
198
# File 'allure-ruby-commons/lib/allure-ruby-commons.rb', line 194

def set_muted
  lifecycle.update_test_case do |test_case|
    test_case.status_details.muted = true
  end
end

#step(name:, status: nil) ⇒ void

This method returns an undefined value.

Add step with provided name and optional status to current test step, fixture or test case

Parameters:



213
214
215
216
# File 'allure-ruby-commons/lib/allure-ruby-commons.rb', line 213

def step(name:, status: nil)
  lifecycle.add_test_step(StepResult.new(name: name, status: status || Status::PASSED, stage: Stage::FINISHED))
  lifecycle.stop_test_step
end

#step_parameter(name, value) ⇒ void

This method returns an undefined value.

Add parameter to current test step

Parameters:

  • name (String)
  • value (String)


242
243
244
245
246
# File 'allure-ruby-commons/lib/allure-ruby-commons.rb', line 242

def step_parameter(name, value)
  lifecycle.update_test_step do |step|
    step.parameters.push(Parameter.new(name, value))
  end
end

#story(value) ⇒ void

This method returns an undefined value.

Add story to current test case

Parameters:

  • value (String)


57
58
59
# File 'allure-ruby-commons/lib/allure-ruby-commons.rb', line 57

def story(value)
  replace_label(ResultUtils::STORY_LABEL_NAME, value)
end

#suite(value) ⇒ void

This method returns an undefined value.

Add suite to current test case

Parameters:

  • value (String)


64
65
66
# File 'allure-ruby-commons/lib/allure-ruby-commons.rb', line 64

def suite(value)
  replace_label(ResultUtils::SUITE_LABEL_NAME, value)
end

#tag(value) ⇒ void

This method returns an undefined value.

Add tag to current test case

Parameters:

  • value (String)


71
72
73
# File 'allure-ruby-commons/lib/allure-ruby-commons.rb', line 71

def tag(value)
  label(ResultUtils::TAG_LABEL_NAME, value)
end

#tms(name, url) ⇒ void

This method returns an undefined value.

Add tms link to current test case

Parameters:

  • name (String)
  • url (String)


131
132
133
# File 'allure-ruby-commons/lib/allure-ruby-commons.rb', line 131

def tms(name, url)
  add_link(name: name, url: url, type: ResultUtils::TMS_LINK_TYPE)
end