Module: CapybaraTypo3Browsertesting::Reports
- Defined in:
- lib/capybara_typo3_browsertesting/reports.rb
Instance Method Summary collapse
- #create_responsive_report(resp_conf, domain, run_method) ⇒ Object
- #get_workdir(domain) ⇒ Object
- #merge_to_pdf(jpg_quality, domain) ⇒ Object
- #send_report(config, domain) ⇒ Object
Instance Method Details
#create_responsive_report(resp_conf, domain, run_method) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/capybara_typo3_browsertesting/reports.rb', line 6 def create_responsive_report resp_conf, domain, run_method workdir = get_workdir domain i = 1 resp_conf['pages'].each do|testpage| url = "#{resp_conf['base']}#{testpage['url']}" print "visiting: #{url}\n" visit url width = page.execute_script("return Math.max(document.body.scrollWidth,document.body.offsetWidth,document.documentElement.clientWidth,document.documentElement.scrollWidth,document.documentElement.offsetWidth);") height = page.execute_script("return Math.max(document.body.scrollHeight,document.body.offsetHeight,document.documentElement.clientHeight,document.documentElement.scrollHeight,document.documentElement.offsetHeight);") width = 2000 if width > 2000 window = Capybara.current_session.current_window window.resize_to(width, height) window.maximize if(testpage['wait']) sleep testpage['wait'].to_i else sleep resp_conf['default_wait'].to_i end iframe_count = 5 iframe_count = resp_conf['iframe_count'] if resp_conf.has_key? 'iframe_count' 1.upto(iframe_count) do |ii| page.driver.switch_to_frame(page.find("#iframe#{ii}")) if run_method send(run_method) end Capybara.current_session.switch_to_window window end page.save_screenshot "#{workdir}/page-#{i}.png", full: true i += 1 end merge_to_pdf resp_conf['jpg_quality'], domain send_report resp_conf['mail'], domain unless resp_conf.has_key? 'skip_headless' and resp_conf['skip_mail'] end |
#get_workdir(domain) ⇒ Object
52 53 54 55 56 |
# File 'lib/capybara_typo3_browsertesting/reports.rb', line 52 def get_workdir domain workdir = "testout/#{domain}/reponsive" system("mkdir -p #{workdir}") workdir end |
#merge_to_pdf(jpg_quality, domain) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/capybara_typo3_browsertesting/reports.rb', line 58 def merge_to_pdf jpg_quality, domain workdir = get_workdir domain system("cd #{workdir} && mogrify -quality #{jpg_quality} -format jpg *.png") system("cd #{workdir} && rm *.png") system("cd #{workdir} && convert *.jpg responsive_report.pdf") system("cd #{workdir} && rm *.jpg") end |
#send_report(config, domain) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/capybara_typo3_browsertesting/reports.rb', line 66 def send_report config, domain workdir = get_workdir domain = { :address => config['server'], :port => config['port'], :user_name => config['username'], :password => config['password'], :authentication => 'login', :enable_starttls_auto => true } Mail.defaults do delivery_method :smtp, end mail = Mail.new do from config['from'] to config['to'] subject config['subject'] body config['body'] add_file :filename => config['report_name'], :content => File.read("#{workdir}/responsive_report.pdf") end mail.deliver! end |