Case Study: User Sign up Automated Test in Selenium WebDriver

Using temporary mail services to support a typical user signup test scenario

  • MailCatcher: fake SMTP server
  • TempMailO: an online temporary email provider

Test Design

  1. Create a new user via the sign up form
  2. Try to login with the new account, expect “the user not activated yet” message
  3. Wait for the activation email with the account activation link
  4. Click the activation link in the email
  5. Log in as the new user successfully

Email checking with MailCatcher

it "User sign up with email" do
sign_up_page = SignUpPage.new(browser)
new_email = Faker::Internet.email
puts new_email
try_for(2) { sign_up_page.enter_email(new_email) }
sign_up_page.enter_password("test02")
fail_safe{ sign_up_page.enter_captcha("wise") }
sign_up_page.click_create_account
expect(page_text).to include("Please check your email to activate your account.")
visit("/sign-in")
sign_in(new_email, "test02")
try_for(3, 0.5) { expect(page_text).to include("not activated yet") }
activate_url = nil
try_for(10, 5) {
open_email("Account activation") { |email_body_html|
activate_url = Nokogiri::HTML(email_body_html).at_css("a#activate-link")["href"]
}
driver.get(activate_url)
try_for(3, 0.5) { expect(toast_text).to include("Account activated, you can sign in now.") }
}
sign_in(new_email, "test02")
expect(page_text).to include("Find Business")
end
open_email("Account activation") { |email_body_html|
activate_url = Nokogiri::HTML(email_body_html).at_css("a#activate-link")["href"]
}
driver.get(activate_url)
try_for(3) { expect(toast_text).to include("Account activated, you can sign in now.") }
}

Email checking with TempMailO

https://tempmailo.com/

  1. Extract the email address from TempMailo
driver.get("https://tempmailo.com/")
email_address = driver.find_element(:id, "i-email")["value"]
driver.execute_script("window.open('https://whenwise.agileway.net/sign-up', '_blank')")
driver.switch_to.window(driver.window_handles[-1])
driver.find_element(:id, "email").send_keys(email_address)
driver.find_element(:id, "password").send_keys("test01")
driver.find_element(:id, "create-account").click
sleep 0.2
expect(page_text).to include("Please check your email to activate your account.")
sign_in_page = SignInPage.new(driver)
sign_in_page.enter_email(email_address)
sign_in_page.enter_password("test01")
sign_in_page.click_login
try_for(2) { expect(page_text).to include("The account is not activated yet") }
driver.close
driver.switch_to.window(driver.window_handles[0]) # first tab
# Wait for email to appear 
wait = Selenium::WebDriver::Wait.new(:timeout => 25)
wait.until { driver.find_element(:xpath, "//li[@class='mail-item']/div[@class='title' and text()='noreply@whenwise.com']") }
driver.find_element(:xpath, "//ul[@class='mail-items-list']/li[1]").click
frame = driver.find_element(:id, "fullmessage")
driver.switch_to.frame(frame)
driver.find_element(:partial_link_text, "account_activations").click
driver.switch_to.default_content
driver.switch_to.window(driver.window_handles[-1]) # last tab
expect(page_text).to include("Account activated, you can sign in now.")login_page = LoginPage.new(driver)
login_page.enter_email(email_address)
login_page.enter_password("test01")
login_page.click_login
expect(page_text).to include("You have signed in successfully")

Complete Test Script (TempMailo)

it "Sign up new user" do
driver.get("https://tempmailo.com/")
email_address = driver.find_element(:id, "i-email")["value"]
puts "New user: #{email_address}"
driver.execute_script("window.open('https://whenwise.agileway.net/sign-up', '_blank')")
driver.switch_to.window(driver.window_handles[-1])
driver.find_element(:id, "email").send_keys(email_address)
driver.find_element(:id, "password").send_keys("test01")
driver.find_element(:id, "create-account").click
sleep 0.2
expect(page_text).to include("Please check your email to activate your account.")

sign_in_page = SignInPage.new(driver)
sign_in_page.enter_email(email_address)
sign_in_page.enter_password("test01")
sign_in_page.click_login
try_for(2) { expect(page_text).to include("The account is not activated yet") }

driver.close
driver.switch_to.window(driver.window_handles[0])
temp_mail_page = TempMailPage.new(driver)
temp_mail_page.click_refresh_emails
# wait for email to come in, timeout: 25 seconds
wait = Selenium::WebDriver::Wait.new(:timeout => 25)
wait.until { driver.find_element(:xpath, "//li[@class='mail-item']/div[@class='title' and text()='noreply@whenwise.com']") }
temp_mail_page.click_refresh_emails
temp_mail_page.click_first_email
frame = driver.find_element(:id, "fullmessage")
driver.switch_to.frame(frame)
driver.find_element(:partial_link_text, "account_activations").click
driver.switch_to.default_content
driver.switch_to.window(driver.window_handles[-1])
expect(page_text).to include("Account activated, you can sign in now.")
login_page = LoginPage.new(driver)
login_page.enter_email(email_address)
login_page.enter_password("test01")
login_page.click_login

expect(page_text).to include("You have signed in successfully")
end

Another Temporary Free Email Provider, Temp-Mail

At first, I tried to use tempail.com, this temporary mail service is free, but it has unpredictable behaviour. Occasionally there are Captchas (once completed manually it doesn’t appear the next 2–3 times).

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store