Skip to content

Instantly share code, notes, and snippets.

@tk5446
Created November 25, 2015 07:19
Show Gist options
  • Save tk5446/948d1d17c073d731a300 to your computer and use it in GitHub Desktop.
Save tk5446/948d1d17c073d731a300 to your computer and use it in GitHub Desktop.
require 'watir-webdriver'
require 'spec_helper'
RSpec.describe "emberlight" do
let(:browser) {
# @browser ||= Watir::Browser.new :firefox
caps = Selenium::WebDriver::Remote::Capabilities.chrome
caps.version = "31"
caps.platform = "Mac OS X 10.9"
caps[:name] = "Emberlight Purchases"
sauce_endpoint = "http://pitchtop:359d0eb8-17ab-4a5d-8d34-e274fcbd78e7@ondemand.saucelabs.com:80/wd/hub"
browser ||= Watir::Browser.new(:remote, :url => "#{sauce_endpoint}", :desired_capabilities => caps)
}
context "user gets to shipping page without issue" do
after { browser.close }
before do
browser.driver.manage.window.maximize;
# browser.driver.manage.window.maximize; browser.goto "http://0ccafdba.ngrok.io/widgets/demo/emberlight"
browser.goto "https://pitchtop-staging-rfyj5fwfkh.elasticbeanstalk.com/widgets/demo/emberlight"
buy_button = browser.li(:class => 'pitchtop-add-to-cart')
buy_button.click
@shopping_cart_iframe = browser.iframe(:id => "stripe_payment_iframe")
@shopping_cart_iframe.a(id: "shipping_info_button").wait_until_present
go_to_shipping_button = @shopping_cart_iframe.a(id: "shipping_info_button")
go_to_shipping_button.click
go_to_shipping_button.wait_while_present
end#before
it "should require user to enter a valid email address" do
#SHIPPING FORM
email_field = @shopping_cart_iframe.text_field(:id => "email_address_input")
email_field.wait_until_present
email_field.text_field(:id => "email_address_input").set "incomplete"
@shopping_cart_iframe.text_field(:name => "shipping_address[first_name]").set "Test"
@shopping_cart_iframe.text_field(:name => "shipping_address[last_name]").set "Tester"
@shopping_cart_iframe.text_field(:name => "shipping_address[address_one]").set "1 Main St"
@shopping_cart_iframe.text_field(:name => "shipping_address[city]").set "San Francisco"
@shopping_cart_iframe.text_field(:name => "shipping_address[state]").set "CA"
@shopping_cart_iframe.text_field(:name => "shipping_address[postal_code]").set "94105"
@shopping_cart_iframe.select_list(:name => "shipping_address[country]").select 'United States'
review_order_button = @shopping_cart_iframe.button(id: "review_order_button")
review_order_button.click
# review_order_button.wait_while_present
#ERROR MESSAGE
# Watir::Wait.until { !(class_name: "payment-errors").text.blank? }
expect(@shopping_cart_iframe.text_field(:id => "email_address_input", class_name: "error").exists?).to be_truthy
end#it
it "should require user to enter a first name" do
#SHIPPING FORM
email_field = @shopping_cart_iframe.text_field(:id => "email_address_input")
email_field.wait_until_present
email_field.text_field(:id => "email_address_input").set "no@firstName.com"
# @shopping_cart_iframe.text_field(:name => "shipping_address[first_name]").set "Test"
@shopping_cart_iframe.text_field(:name => "shipping_address[last_name]").set "Tester"
@shopping_cart_iframe.text_field(:name => "shipping_address[address_one]").set "1 Main St"
@shopping_cart_iframe.text_field(:name => "shipping_address[city]").set "San Francisco"
@shopping_cart_iframe.text_field(:name => "shipping_address[state]").set "CA"
@shopping_cart_iframe.text_field(:name => "shipping_address[postal_code]").set "94105"
@shopping_cart_iframe.select_list(:name => "shipping_address[country]").select 'United States'
review_order_button = @shopping_cart_iframe.button(id: "review_order_button")
review_order_button.click
expect(@shopping_cart_iframe.text_field(:name => "shipping_address[first_name]").focused?).to be_truthy
end#it
it "should require user to enter a last name" do
#SHIPPING FORM
email_field = @shopping_cart_iframe.text_field(:id => "email_address_input")
email_field.wait_until_present
email_field.text_field(:id => "email_address_input").set "no@lastName.com"
@shopping_cart_iframe.text_field(:name => "shipping_address[first_name]").set "Test"
# @shopping_cart_iframe.text_field(:name => "shipping_address[last_name]").set "Tester"
@shopping_cart_iframe.text_field(:name => "shipping_address[address_one]").set "1 Main St"
@shopping_cart_iframe.text_field(:name => "shipping_address[city]").set "San Francisco"
@shopping_cart_iframe.text_field(:name => "shipping_address[state]").set "CA"
@shopping_cart_iframe.text_field(:name => "shipping_address[postal_code]").set "94105"
@shopping_cart_iframe.select_list(:name => "shipping_address[country]").select 'United States'
review_order_button = @shopping_cart_iframe.button(id: "review_order_button")
review_order_button.click
expect(@shopping_cart_iframe.text_field(:name => "shipping_address[last_name]").focused?).to be_truthy
end#it
end#context
context "user get to payment page without issue" do
after { browser.close }
before do
browser.driver.manage.window.maximize;
# browser.goto "http://0ccafdba.ngrok.io/widgets/demo/emberlight"
browser.goto "https://pitchtop-staging-rfyj5fwfkh.elasticbeanstalk.com/widgets/demo/emberlight"
buy_button = browser.li(:class => 'pitchtop-add-to-cart')
buy_button.click
@shopping_cart_iframe = browser.iframe(:id => "stripe_payment_iframe")
@shopping_cart_iframe.a(id: "shipping_info_button").wait_until_present
go_to_shipping_button = @shopping_cart_iframe.a(id: "shipping_info_button")
go_to_shipping_button.click
go_to_shipping_button.wait_while_present
#SHIPPING FORM
@shopping_cart_iframe.text_field(:id => "email_address_input").wait_until_present
@shopping_cart_iframe.text_field(:id => "email_address_input").set "tom+webdriver@somewehereelse12313.co"
@shopping_cart_iframe.text_field(:name => "shipping_address[first_name]").set "Test"
@shopping_cart_iframe.text_field(:name => "shipping_address[last_name]").set "Tester"
@shopping_cart_iframe.text_field(:name => "shipping_address[address_one]").set "1 Main St"
@shopping_cart_iframe.text_field(:name => "shipping_address[city]").set "San Francisco"
@shopping_cart_iframe.text_field(:name => "shipping_address[state]").set "CA"
@shopping_cart_iframe.text_field(:name => "shipping_address[postal_code]").set "94105"
@shopping_cart_iframe.select_list(:name => "shipping_address[country]").select 'United States'
review_order_button = @shopping_cart_iframe.button(id: "review_order_button")
review_order_button.click
review_order_button.wait_while_present
end
it "should submit a successful order with an Order ID displayed to user" do
#PAYMENT FORM
@shopping_cart_iframe.text_field(:name => "number").wait_until_present
@shopping_cart_iframe.text_field(:name => "number").set "4242424242424242"
@shopping_cart_iframe.text_field(:name => "expiry").set "1118"
@shopping_cart_iframe.text_field(:name => "cvc").set "123"
place_payment_button = @shopping_cart_iframe.button(id: "place_payment_button")
place_payment_button.click
place_payment_button.wait_while_present
#CONFIRMATION PAGE
@shopping_cart_iframe.strong(id: "order_id").wait_until_present
assert_equal("Order ID:", @shopping_cart_iframe.strong(id: "order_id").text)
end#end it
it "should render a bad credit card error message on payment page" do
#PAYMENT FORM
@shopping_cart_iframe.text_field(:name => "number").wait_until_present
@shopping_cart_iframe.text_field(:name => "number").set "4000000000000002"
@shopping_cart_iframe.text_field(:name => "expiry").set "1118"
@shopping_cart_iframe.text_field(:name => "cvc").set "123"
place_payment_button = @shopping_cart_iframe.button(id: "place_payment_button")
place_payment_button.click
#ERROR MESSAGE
Watir::Wait.until { !@shopping_cart_iframe.span(class_name: "payment-errors").text.blank? }
assert_equal("Your card was declined.", @shopping_cart_iframe.span(class_name: "payment-errors").text)
end#end it
it "should render a bad expiration date error message on payment page" do
#PAYMENT FORM
@shopping_cart_iframe.text_field(:name => "number").wait_until_present
@shopping_cart_iframe.text_field(:name => "number").set "4242424242424242"
@shopping_cart_iframe.text_field(:name => "expiry").set "1112"
@shopping_cart_iframe.text_field(:name => "cvc").set "123"
place_payment_button = @shopping_cart_iframe.button(id: "place_payment_button")
place_payment_button.click
#ERROR MESSAGE
Watir::Wait.until { !@shopping_cart_iframe.span(class_name: "payment-errors").text.blank? }
assert_equal("Your card's expiration year is invalid.", @shopping_cart_iframe.span(class_name: "payment-errors").text)
end#end it
it "should render a bad cvc error message on payment page" do
#PAYMENT FORM
@shopping_cart_iframe.text_field(:name => "number").wait_until_present
@shopping_cart_iframe.text_field(:name => "number").set "4242424242424242"
@shopping_cart_iframe.text_field(:name => "expiry").set "1118"
@shopping_cart_iframe.text_field(:name => "cvc").set "99"
place_payment_button = @shopping_cart_iframe.button(id: "place_payment_button")
place_payment_button.click
#ERROR MESSAGE
Watir::Wait.until { !@shopping_cart_iframe.span(class_name: "payment-errors").text.blank? }
assert_equal("Your card's security code is invalid.", @shopping_cart_iframe.span(class_name: "payment-errors").text)
end#end it
end#context
end #describe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment