Skip to content

Instantly share code, notes, and snippets.

@jamesmichiemo
Created April 22, 2015 22:18
Show Gist options
  • Select an option

  • Save jamesmichiemo/b1df729bf0e52f25f5b3 to your computer and use it in GitHub Desktop.

Select an option

Save jamesmichiemo/b1df729bf0e52f25f5b3 to your computer and use it in GitHub Desktop.
pizza
require 'capybara'
class PizzaOrderer
def initialize
@session = Capybara::Session.new(:selenium)
end
def order_pizza
open_pizza_page
if @session.has_content?('Papa')
start_order
enter_delivery_address
select_pizza
checkout
else
puts "something is broken"
end
end
def open_pizza_page
@session.visit 'https://papajohns.com'
end
def start_order
@session.click_link 'Order Now'
end
def enter_delivery_address
@session.find('#streetAddress').set(ENV['STREET'])
@session.find('#zip').set ENV['ZIP']
@session.click_button 'setLocationSubmit'
end
def select_toppings
puts 'Which topping?'
STDOUT.flush
topping = gets.chomp
if topping == 'philly'
@session.find('#topping_506-img').click
elsif topping == 'provolone'
@session.find('#topping_506-img').click
elsif topping == 'pepperoni'
@session.find('#topping_35-img').click
elsif topping == 'sausage'
@session.find('#topping_27-img').click
elsif topping == 'spicy'
@session.find('#topping_23-img').click
elsif topping == 'beef'
@session.find('#topping_20-img').click
elsif topping == 'grilled'
@session.find('#topping_33-img').click
elsif topping == 'bacon'
@session.find('#topping_24-img').click
elsif topping == 'extra'
@session.find('#topping_21-img').click
elsif topping == 'three'
@session.find('#topping_54-img').click
elsif topping == 'parmesan'
@session.find('#topping_61-img').click
elsif topping == 'anchovies'
@session.find('#topping_28-img').click
elsif topping == 'canadian'
@session.find('#topping_62-img').click
elsif topping == 'green'
@session.find('#topping_47-img').click
elsif topping == 'onions'
@session.find('#topping_25-img').click
elsif topping == 'baby'
@session.find('#topping_48-img').click
elsif topping == 'black'
@session.find('#topping_26-img').click
elsif topping == 'roma'
@session.find('#topping_50-img').click
elsif topping == 'jalapeno'
@session.find('#topping_29-img').click
elsif topping == 'banana'
@session.find('#topping_30-img').click
end
end
def select_pizza
@session.first(:css, 'a.customizeBtn').click
@session.find('#switchToBasic').click
@session.driver.browser.switch_to.alert.accept
3.times { select_toppings }
@session.first('#orderBuilderContinueBtn').click
sleep 2
end
def checkout
@session.find('#readyToCheckoutBtn').click
@session.visit 'https://order.papajohns.com/secure/checkout.html'
@session.fill_in 'nameFirst', with: ENV['FIRST_NAME']
@session.fill_in 'nameLast', with: ENV['LAST_NAME']
@session.fill_in 'phoneAreaCode', with: 407
@session.fill_in 'phonePrefix', with: 463
@session.fill_in 'phoneSuffix', with: 2114
@session.fill_in 'customer.email', with: ENV['EMAIL']
@session.fill_in 'customer.confirmationEmail', with: ENV['EMAIL']
@session.find('#paymentCash-img').click
@session.find('#minAgeConfirmation-img').click
@session.click_button('placeOrderBtn').click
sleep 100
end
end
PizzaOrderer.new.order_pizza
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment