Class: Scoutui::Base::QApplitools
- Inherits:
-
Object
- Object
- Scoutui::Base::QApplitools
- Defined in:
- lib/scoutui/base/q_applitools.rb
Instance Attribute Summary collapse
-
#eyes ⇒ Object
Returns the value of attribute eyes.
Instance Method Summary collapse
- #download_diffs(results, view_key, destination) ⇒ Object
- #download_images(diff_urls, destination) ⇒ Object
- #get_diff_urls(session_id, view_key) ⇒ Object
- #get_session_id(url) ⇒ Object
-
#initialize ⇒ QApplitools
constructor
A new instance of QApplitools.
- #print_results(results, view_key) ⇒ Object
- #report(results) ⇒ Object
- #setup ⇒ Object
-
#teardown ⇒ Object
Called after every test method runs.
-
#xxxtestit ⇒ Object
Fake test.
Constructor Details
#initialize ⇒ QApplitools
Returns a new instance of QApplitools.
13 14 15 |
# File 'lib/scoutui/base/q_applitools.rb', line 13 def initialize @eyes=nil end |
Instance Attribute Details
#eyes ⇒ Object
Returns the value of attribute eyes.
11 12 13 |
# File 'lib/scoutui/base/q_applitools.rb', line 11 def eyes @eyes end |
Instance Method Details
#download_diffs(results, view_key, destination) ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/scoutui/base/q_applitools.rb', line 78 def download_diffs(results, view_key, destination) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " download_diffs()" session_id = get_session_id(results.url) diff_urls = get_diff_urls(session_id, view_key) download_images(diff_urls, destination) end |
#download_images(diff_urls, destination) ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/scoutui/base/q_applitools.rb', line 86 def download_images(diff_urls, destination) diff_urls.each do |index, url| File.open("#{destination}/step_#{index}_diff.png", 'wb') do |file| file.write HTTParty.get(url) end end end |
#get_diff_urls(session_id, view_key) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/scoutui/base/q_applitools.rb', line 94 def get_diff_urls(session_id, view_key) info = "https://eyes.applitools.com/api/sessions/#{session_id}/?ApiKey=#{view_key}&format=json" diff_template = "https://eyes.applitools.com/api/sessions/#{session_id}/steps/%s/diff?ApiKey=#{view_key}" diff_urls = Hash.new Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " info => #{info}" response = HTTParty.get(info) begin data = JSON.parse(response.body) index = 1 data['actualOutput'].each do |elem| if (elem['isMatching'] == false) diff_urls[index] = diff_template % [index] index+=1 end end diff_urls rescue JSON::ParserError ; end end |
#get_session_id(url) ⇒ Object
120 121 122 |
# File 'lib/scoutui/base/q_applitools.rb', line 120 def get_session_id(url) /sessions\/(?<session>\d+)/.match(url)[1] end |
#print_results(results, view_key) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/scoutui/base/q_applitools.rb', line 60 def print_results(results, view_key) if results.is_passed print "Your test was passed!\n" elsif results.is_new print "Created new baseline, this is a new test or/and new configuration!" else print "Your test was failed!\n" print "#{results.mismatches} out of #{results.steps} steps failed \n" print "Here are the failed steps:\n" session_id = get_session_id(results.url) diff_urls = get_diff_urls(session_id, view_key) diff_urls.each do |index, diff_url| print "Step #{index} --> #{diff_url} \n" end print "For more details please go to #{results.url} to review the differences! \n" end end |
#report(results) ⇒ Object
35 36 37 |
# File 'lib/scoutui/base/q_applitools.rb', line 35 def report(results) download_diffs(results, "VIEW_KEY", '/tmp/diff_images') end |
#setup ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/scoutui/base/q_applitools.rb', line 18 def setup @eyes = Applitools::Eyes.new # This is your api key, make sure you use it in all your tests. @eyes.api_key = "API_KEY" # Get a selenium web driver object. @driver = Selenium::WebDriver.for :chrome #Eyes.log_handler = Logger.new(STDOUT) end |
#teardown ⇒ Object
Called after every test method runs. Can be used to tear down fixtures information.
31 32 33 |
# File 'lib/scoutui/base/q_applitools.rb', line 31 def teardown @eyes.abort_if_not_closed end |
#xxxtestit ⇒ Object
Fake test
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/scoutui/base/q_applitools.rb', line 40 def xxxtestit #@eyes.baseline_name='my_test_name' wrapped_driver = @eyes.open( app_name: 'Applitools website', test_name: 'Example test', viewport_size: {width: 900, height: 650}, driver: @driver) wrapped_driver.get 'https://www.applitools.com' # Visual validation point #1 @eyes.check_window('Main Page') wrapped_driver.find_element(:css, ".features>a").click # Visual validation point #2 @eyes.check_window('Features Page') results = @eyes.close(false) download_diffs(results, "VIEW_KEY", './diff_images') print_results(results, "VIEW_KEY") end |