我已创建邮件功能来发送报告
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中使用此功能,则每次执行每种方案后它都会每次发送电子邮件
at_exit do
# your email logic goes here
end