Created
August 15, 2019 07:51
-
-
Save Niall47/f45457e3791ce4645220ce761c7da417 to your computer and use it in GitHub Desktop.
Mailosaur Ruby email test template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Feature: I look through emails | |
Scenario: I look through emails | |
Given I check the email has been recieved | |
And I search for an email with a "subject" of "Notification of application" | |
Then I delete all emails from my inbox | |
And I check the email has been recieved |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "mailosaur" | |
module Mailosaur | |
APIkey = "XXXXXXXXXXX" | |
Server = "XXXXXXXXXXX" | |
Base_url = "https://mailosaur.com/" | |
end | |
And(/^I check the email has been recieved$/) do | |
all_mail = get_all_emails | |
unless all_mail.nil? | |
all_mail.each do |email| | |
p email if $Debug | |
end | |
end | |
end | |
And(/^I delete all emails from my inbox$/) do | |
delete_all_emails | |
end | |
def get_all_emails | |
client = Mailosaur::MailosaurClient.new(Mailosaur::APIkey, "https://mailosaur.com/") | |
client.messages.list(Mailosaur::Server).items.each do |item| | |
summary = item.summary.gsub!("\n", '') && item.summary.gsub!(" ", '') #Removes double spaces and newlines | |
@email_list = [] unless @email_list | |
each_email = {} | |
each_email[:subject] = item.subject | |
each_email[:summary] = summary | |
each_email[:from] = item.from[0].email | |
each_email[:to] = item.to[0].email | |
each_email[:attatchments] = item.attachments | |
@email_list.push(each_email) | |
end | |
return @email_list | |
end | |
def delete_all_emails | |
client = Mailosaur::MailosaurClient.new(Mailosaur::APIkey, Mailosaur::Base_url) | |
client.messages.delete_all(Mailosaur::Server) | |
end | |
And(/^I search for an email with a "([^"]*)" of "([^"]*)"$/) do |type, search_criteria| | |
client = Mailosaur::MailosaurClient.new(Mailosaur::APIkey, Mailosaur::Base_url) | |
criteria = Mailosaur::Models::SearchCriteria.new() | |
case type | |
when "sentTo" | |
criteria.sent_to = search_criteria | |
when "subject" | |
criteria.subject = search_criteria | |
when "body" | |
criteria.body = search_criteria | |
end | |
returned = client.messages.search(Mailosaur::Server, criteria) | |
p "Found #{returned.items.count} matching emails" | |
returned.items.each do |individual_email| | |
p individual_email.from[0].email if $Debug | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment