Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- require "rubygems"
- gem "rspec"
- require './Helpers/email.rb'
- require './Helpers/utils.rb'
- require './Helpers/selen.rb'
- require '../Settings/data.rb'
- require 'postmark'
- describe "Email through API by IP" do
- attr_accessor :postmarkusername,
- :postmarkpassword,
- :message,
- :emailaccounts,
- :emailaccount
- include Utils
- include Selen
- before(:all) do
- @message = Mail.new
- @message.from = $FROM_EMAIL
- @message.to = $TO_EMAIL
- @servicetype = $API
- @message.content_type = "text/html"
- @message.body = "Test email sent"
- @message.delivery_method Mail::Postmark, {:api_key => $API_TOKEN}
- # read all email accounts to which emails would be sent and checked
- file = File.open("../Settings/emailaccountsettings")
- filecontent = file.read
- file.close
- @email_accounts = filecontent.split("\n")
- @emailaccount = Array.new(@email_accounts.length)
- # go through all email accounts and read settings for every one of them and create array of email account settings
- for i in 0..@email_accounts.length-1
- @emailaccount[i] = @email_accounts[i].split(",")
- end
- @postmarkusername = $USERNAME
- @postmarkpassword = $PASSWORD
- init_selenium($PORT,$BROWSERTYPE + $BROWSERURL,$WEBSITE)
- end
- before(:each) do
- start_selenium_session
- end
- append_after(:each) do
- stop_selenium_session
- end
- it "should be sent to gmail account through #{$WAPI1}" do
- # subject with random number so it's unique
- @message.subject = "Test email sent " + get_random_number(5).to_s + " by #{$WAPI1}"
- Postmark.host = $webapi[$WAPI1]
- puts "check #{@emailaccount[0][0]} account through #{$WAPI1}:"
- @message.to = @emailaccount[0][1]
- send_email(@message.to)
- # check if email arrived
- check_email(@emailaccount[0][2],@emailaccount[0][3],@emailaccount[0][4],@emailaccount[0][5],@emailaccount[0][6],@emailaccount[0][7] == "true")
- # check if email showed up in activity page
- check_email_in_activity_page
- end
- it "should be sent to gmail account through #{$WAPI2}" do
- # subject with random number so it's unique
- @message.subject = "Test email sent " + get_random_number(5).to_s + " by #{$WAPI2}"
- Postmark.host = $webapi[$WAPI2]
- puts "check #{@emailaccount[0][0]} account through #{$WAPI2}:"
- @message.to = @emailaccount[0][1]
- send_email(@message.to)
- # check if email arrived
- check_email(@emailaccount[0][2],@emailaccount[0][3],@emailaccount[0][4],@emailaccount[0][5],@emailaccount[0][6],@emailaccount[0][7] == "true")
- # check if email showed up in activity page
- check_email_in_activity_page
- end
- it "should be sent to gmail account through #{$WAPI3}" do
- # subject with random number so it's unique
- @message.subject = "Test email sent " + get_random_number(5).to_s + " by #{$WAPI3}"
- Postmark.host = $webapi[$WAPI3]
- puts "check #{@emailaccount[0][0]} account through #{$WAPI3}:"
- @message.to = @emailaccount[0][1]
- send_email(@message.to)
- # check if email arrived
- check_email(@emailaccount[0][2],@emailaccount[0][3],@emailaccount[0][4],@emailaccount[0][5],@emailaccount[0][6],@emailaccount[0][7] == "true")
- # check if email showed up in activity page
- check_email_in_activity_page
- end
- it "should be sent to gmail account through #{$WAPI4}" do
- # subject with random number so it's unique
- @message.subject = "Test email sent " + get_random_number(5).to_s + " by #{$WAPI4}"
- Postmark.host = $webapi[$WAPI4]
- puts "check #{@emailaccount[0][0]} account through #{$WAPI4}:"
- @message.to = @emailaccount[0][1]
- send_email(@message.to)
- # check if email arrived
- check_email(@emailaccount[0][2],@emailaccount[0][3],@emailaccount[0][4],@emailaccount[0][5],@emailaccount[0][6],@emailaccount[0][7] == "true")
- # check if email showed up in activity page
- check_email_in_activity_page
- end
- # methods used for scenarios
- # send email through pm API
- def send_email(emailaddress)
- @message.to = emailaddress
- @message.deliver
- end
- # check 5 last emails if email was received in period of $HOWLONGTOCHECK minutes
- def check_email(method,address,port,username,password,ssl)
- # set account to check
- set_email_account(method,address,port,username,password,ssl)
- # check if email is received
- email = ""
- ($HOWLONGTOCHECK*60).times {
- emails = get_last_emails(5)
- for i in 0..emails.length-1 do
- email = emails[i]
- break if ( @message.subject.include? email.subject)
- end
- break if ( @message.subject.include? email.subject)
- sleep 1
- }
- # verify email was received
- (@message.subject.include? email.subject).should == true
- end
- # check if email appeared in activity page
- def check_email_in_activity_page
- login_to_postmark(@postmarkusername,@postmarkpassword)
- page.click "link=Details"
- page.wait_for_page_to_load "30000"
- page.click "link=Activity"
- page.wait_for_page_to_load "30000"
- page.type "bounces-filter", @message.subject
- page.click "//input[@value='Search']"
- page.wait_for_page_to_load "30000"
- emailto = convert_email_to_string(@message.to)
- # verify message by email address
- page.is_element_present("//div[@class=\"activity-item sent\"]/h3/a[contains(text(),'#{emailto}')]").should be_true
- # verify message by email subject
- page.is_element_present("//div[@class=\"activity-item sent\"]/p[contains(text(),'#{@message.subject}')]").should be_true
- # verify message by status
- page.is_element_present("//div[@class=\"activity-item sent\"]/p[contains(text(),'Email Sent')]").should be_true
- end
- end
Add Comment
Please, Sign In to add comment