黄瓜:我想在执行所有方案后通过电子邮件发送报告,是否有像'AfterAll'这样的方法可以在hooks.rb中使用?

问题描述 投票:1回答:1

我已创建邮件功能来发送报告

class Email
  include PageObject
  require 'mail'

  def mailsender
      Mail.defaults do
        delivery_method :smtp,{ 
          address: "smtp.gmail.com",
          openssl_verify_mode: "none",
          port: 587,
          domain: 'gmail.com',
          user_name: '[email protected]' ,
          password: '*******' ,
          authentication: 'plain'
        }
      end

      Mail.deliver do
        from     'xxxxxxx.com'
        to       '[email protected]'
        subject  'Execution report'
        body     'PFA'
        add_file 'Automation_report.html'
      end
  end
end

我希望此功能在所有方案执行后执行。

这是我的挂钩文件

# frozen_string_literal: true

require watir

Before do |scenario|
  DataMagic.load_for_scenario(scenario)
  @browser = Watir::Browser.new :chrome
  @browser.driver.manage.window.maximize
end

After do |scenario|
  if scenario.failed?
    screenshot = "./screenshot.png"
    @browser.driver.save_screenshot(screenshot)
    embed(screenshot, "image/png",)
  end
  @browser.close
end

如果我在After After中使用此功能,则每次执行每种方案后它都会每次发送电子邮件

ruby cucumber watir
1个回答
0
投票
at_exit do # your email logic goes here end
© www.soinside.com 2019 - 2024. All rights reserved.