Class: Applitools::TestResults

Inherits:
Object
  • Object
show all
Defined in:
lib/applitools/core/test_results.rb

Defined Under Namespace

Classes: AccessibilityStatus

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(init_results = {}) ⇒ TestResults

Returns a new instance of TestResults.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/applitools/core/test_results.rb', line 22

def initialize(init_results = {})
  environment = init_results[:environment] || {}
  @renderer = Applitools::Utils.deep_stringify_keys(Applitools::Utils.underscore_hash_keys(environment[:requested]))
  @browser_info = JSON.parse(@renderer.to_json, object_class: OpenStruct)
  results = Applitools::Utils.deep_stringify_keys(init_results[:result] ? init_results[:result] : init_results)
  @original_results = results
  @steps = results.fetch('steps', 0)
  @matches = results.fetch('matches', 0)
  @mismatches = results.fetch('mismatches', 0)
  @missing = results.fetch('missing', 0)
  @status = results.fetch('status', 0)
  @is_new = results.fetch('isNew', nil)
  @url = results.fetch('url', nil)
end

Instance Attribute Details

#browser_infoObject (readonly)

Returns the value of attribute browser_info.



20
21
22
# File 'lib/applitools/core/test_results.rb', line 20

def browser_info
  @browser_info
end

#is_newObject

Returns the value of attribute is_new.



19
20
21
# File 'lib/applitools/core/test_results.rb', line 19

def is_new
  @is_new
end

#matchesObject (readonly)

Returns the value of attribute matches.



20
21
22
# File 'lib/applitools/core/test_results.rb', line 20

def matches
  @matches
end

#mismatchesObject (readonly)

Returns the value of attribute mismatches.



20
21
22
# File 'lib/applitools/core/test_results.rb', line 20

def mismatches
  @mismatches
end

#missingObject (readonly)

Returns the value of attribute missing.



20
21
22
# File 'lib/applitools/core/test_results.rb', line 20

def missing
  @missing
end

#original_resultsObject (readonly)

Returns the value of attribute original_results.



20
21
22
# File 'lib/applitools/core/test_results.rb', line 20

def original_results
  @original_results
end

#rendererObject (readonly)

Returns the value of attribute renderer.



20
21
22
# File 'lib/applitools/core/test_results.rb', line 20

def renderer
  @renderer
end

#screenshotObject

Returns the value of attribute screenshot.



19
20
21
# File 'lib/applitools/core/test_results.rb', line 19

def screenshot
  @screenshot
end

#statusObject (readonly)

Returns the value of attribute status.



20
21
22
# File 'lib/applitools/core/test_results.rb', line 20

def status
  @status
end

#stepsObject (readonly)

Returns the value of attribute steps.



20
21
22
# File 'lib/applitools/core/test_results.rb', line 20

def steps
  @steps
end

#urlObject

Returns the value of attribute url.



19
20
21
# File 'lib/applitools/core/test_results.rb', line 19

def url
  @url
end

Instance Method Details

#==(other) ⇒ Object



89
90
91
92
93
94
95
96
97
98
# File 'lib/applitools/core/test_results.rb', line 89

def ==(other)
  if other.is_a? self.class
    result = true
    %w(is_new url steps matches mismatches missing).each do |field|
      result &&= send(field) == other.send(field)
    end
    return result if result
  end
  false
end

#aborted?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/applitools/core/test_results.rb', line 61

def aborted?
  original_results['isAborted'] || !errors.nil?
end

#api_session_urlObject



65
66
67
# File 'lib/applitools/core/test_results.rb', line 65

def api_session_url
  original_results['apiUrls']['session']
end

#app_nameObject



81
82
83
# File 'lib/applitools/core/test_results.rb', line 81

def app_name
  original_results['appName']
end

#different?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/applitools/core/test_results.rb', line 57

def different?
  original_results['isDifferent']
end

#errorsObject



77
78
79
# File 'lib/applitools/core/test_results.rb', line 77

def errors
  original_results['error']
end

#failed?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/applitools/core/test_results.rb', line 45

def failed?
  status == 'Failed'
end

#nameObject



73
74
75
# File 'lib/applitools/core/test_results.rb', line 73

def name
  original_results['name']
end

#new?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/applitools/core/test_results.rb', line 53

def new?
  original_results['isNew']
end

#passed?Boolean Also known as: is_passed, as_expected?

Returns:

  • (Boolean)


41
42
43
# File 'lib/applitools/core/test_results.rb', line 41

def passed?
  status == 'Passed'
end

#secret_tokenObject



69
70
71
# File 'lib/applitools/core/test_results.rb', line 69

def secret_token
  original_results['secretToken']
end

#session_accessibility_statusObject



85
86
87
# File 'lib/applitools/core/test_results.rb', line 85

def session_accessibility_status
  @accessibility_status ||= original_results['accessibilityStatus'] && AccessibilityStatus.new(original_results['accessibilityStatus'] || {})
end

#test_resultsObject



37
38
39
# File 'lib/applitools/core/test_results.rb', line 37

def test_results
  self
end

#to_s(advanced = false) ⇒ Object



104
105
106
107
108
109
110
111
112
# File 'lib/applitools/core/test_results.rb', line 104

def to_s(advanced = false)
  is_new_str = ''
  is_new_str = is_new ? 'New test' : 'Existing test' unless is_new.nil?

  return @original_results.to_yaml if advanced

  "#{is_new_str} [ steps: #{steps}, matches: #{matches}, mismatches: #{mismatches}, missing: #{missing} ], " \
    "URL: #{url}"
end

#unresolved?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/applitools/core/test_results.rb', line 49

def unresolved?
  status == 'Unresolved'
end