Module: Allure

Extended by:
Allure
Included in:
Allure
Defined in:
lib/allure-ruby-commons.rb,
lib/allure_ruby_commons/config.rb,
lib/allure_ruby_commons/testplan.rb,
lib/allure_ruby_commons/model/link.rb,
lib/allure_ruby_commons/file_writer.rb,
lib/allure_ruby_commons/model/label.rb,
lib/allure_ruby_commons/model/stage.rb,
lib/allure_ruby_commons/_json_helper.rb,
lib/allure_ruby_commons/model/status.rb,
lib/allure_ruby_commons/result_utils.rb,
lib/allure_ruby_commons/model/globals.rb,
lib/allure_ruby_commons/model/category.rb,
lib/allure_ruby_commons/model/parameter.rb,
lib/allure_ruby_commons/allure_lifecycle.rb,
lib/allure_ruby_commons/model/attachment.rb,
lib/allure_ruby_commons/model/01_jsonable.rb,
lib/allure_ruby_commons/model/step_result.rb,
lib/allure_ruby_commons/model/test_result.rb,
lib/allure_ruby_commons/model/content_type.rb,
lib/allure_ruby_commons/model/global_error.rb,
lib/allure_ruby_commons/model/fixture_result.rb,
lib/allure_ruby_commons/model/status_details.rb,
lib/allure_ruby_commons/model/executable_item.rb,
lib/allure_ruby_commons/model/global_attachment.rb,
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, GlobalAttachment, GlobalError, Globals, 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:



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

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



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

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:



200
201
202
# File 'lib/allure-ruby-commons.rb', line 200

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)


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

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)


191
192
193
# File 'lib/allure-ruby-commons.rb', line 191

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

#add_global_attachment(name:, source:, type:) ⇒ void

This method returns an undefined value.

Add run-level attachment not bound to a test or fixture

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



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

def add_global_attachment(name:, source:, type:)
  lifecycle.add_global_attachment(name: name, source: source, type: type)
end

#add_global_error(**details) ⇒ void

This method returns an undefined value.

Add run-level error not bound to a test or fixture

Parameters:

  • details (Hash)

Options Hash (**details):

  • :known (Boolean)
  • :muted (Boolean)
  • :flaky (Boolean)
  • :message (String)
  • :trace (String)


182
183
184
# File 'lib/allure-ruby-commons.rb', line 182

def add_global_error(**details)
  lifecycle.add_global_error(**details)
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



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

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:



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

def configuration
  Config.instance
end

#configure {|| ... } ⇒ void

This method returns an undefined value.

Set allure configuration

Yield Parameters:

Yield Returns:

  • (void)


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

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)


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

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)


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

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)


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

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)


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

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)


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

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:



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

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

#parameter(name, value, excluded: false, mode: Allure::Parameter::DEFAULT) ⇒ void

This method returns an undefined value.

Add parameter to current test case

Parameters:

  • name (String)
  • value (String)


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

def parameter(name, value, excluded: false, mode: Allure::Parameter::DEFAULT)
  lifecycle.update_test_case do |test_case|
    test_case.parameters.push(Parameter.new(name, value, excluded: excluded, mode: mode))
  end
end

#replace_label(name, value) ⇒ void

This method returns an undefined value.

Replace label in current test case

Parameters:

  • name (String)
  • value (String)


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

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)


244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/allure-ruby-commons.rb', line 244

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, configuration.failure_exception => 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



207
208
209
210
211
# File 'lib/allure-ruby-commons.rb', line 207

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



225
226
227
228
229
# File 'lib/allure-ruby-commons.rb', line 225

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



216
217
218
219
220
# File 'lib/allure-ruby-commons.rb', line 216

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:



235
236
237
238
# File 'lib/allure-ruby-commons.rb', line 235

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, excluded: false, mode: Allure::Parameter::DEFAULT) ⇒ void

This method returns an undefined value.

Add parameter to current test step

Parameters:

  • name (String)
  • value (String)


264
265
266
267
268
# File 'lib/allure-ruby-commons.rb', line 264

def step_parameter(name, value, excluded: false, mode: Allure::Parameter::DEFAULT)
  lifecycle.update_test_step do |step|
    step.parameters.push(Parameter.new(name, value, excluded: excluded, mode: mode))
  end
end

#story(value) ⇒ void

This method returns an undefined value.

Add story to current test case

Parameters:

  • value (String)


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

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

#suite(value) ⇒ void

This method returns an undefined value.

Add suite to current test case

Parameters:

  • value (String)


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

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)


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

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)


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

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