Skip to content

Instantly share code, notes, and snippets.

@friscodelrosario
Last active August 29, 2015 14:23
Show Gist options
  • Save friscodelrosario/d1a1b8eba8eb24589127 to your computer and use it in GitHub Desktop.
Save friscodelrosario/d1a1b8eba8eb24589127 to your computer and use it in GitHub Desktop.
Distil Networks automator assessment
Cache-Control step isn't done. I did the easiest thing that should work:
curl -I http://www.swedishfurnitureparts.com
expecting 'no-cache', but it's not there. So I spent an entire day screwing with browsermob-proxy in order to get the HTTP headers, but it wouldn't play nicely with the Java environments on either of my computers.
Suggested ecommerce test cases
Discount codes
Behaviors after refresh and back button (kind of a unicorn, because when do automated testers ever have time to get off the happy path)
Social sharings
Notifications of restocked items
class Checkout
def go
$driver.get('http://www.swedishfurnitureparts.com/products/ikea-cam-lock-nut-103114')
end
def add_two_locknuts
$driver.find_element(:id, 'add-to-cart').click
$driver.find_element(:css, '.text.quantity').send_keys($data['quantity']) #how embarrassing — at first, I'd just hard-coded '2', but figured I'd make it data-driven from a hash in env.rb; then I couldn't remember how to access that hash non-globally
$driver.find_element(:name, 'update').click #name locator because Update Quantities and Proceed to Checkout buttons have the same ID
end
def checkout
$driver.find_element(:name, 'checkout').click
end
end
{
"cookie": "_shopify_s",
"search_item": "Cam Lock Nut #103114",
"quantity": 2
}
file = File.read(Dir.pwd + '/features/objects/data.json')
$data = JSON.parse(file)
Feature: Swedish Furniture Parts homepage
As a furniture parts buyer, to ensure a pleasant online shopping session, I want to find and purchase items without delay
@load
Scenario: Load time
When I go to the Swedish Furniture Parts shopping page
Then the page should load within 500ms
And the page should set the _shopify_s cookie which expires at session end
@search
Scenario: Search
Given my visit to the SFP page
When I search for Cam Lock Nut 103114
Then I should get one search hit
@checkout
Scenario: Checkout
Given a successful search for Cam Lock Nut 103114
When I add two to my shopping cart
Then I can checkout
class Homepage
def go
$start_time = Time.now #for performance test
$driver.get("http://www.swedishfurnitureparts.com")
$end_time = Time.now
end
def manage_cookies
@cookies = $driver.manage.all_cookies
#iterate cookies, if shopify_s cookie exists, check for its expiry
@cookies.each {|cookie|
if cookie.values_at(:name)[0] == $data['cookie']
then
@shopify_s_cookie_exists = true
@cookie_expires_at_close = true if cookie.values_at(:expires)[0].to_s != ""
end
}
end
def verify_shopify_s_cookie
manage_cookies
@shopify_s_cookie_exists.should == true
end
def verify_cookie_expire
manage_cookies
@cookie_expires_at_close.should == true
end
def search_locknut
@search_field = $driver.find_element(:id, 'top-search-input')
@search_field.send_keys($data['search_item'])
@search_field.find_element(:id, 'top-search-input').send_keys(:return)
end
def verify_one_search_hit
#I did this twice — some can't stand xpath locators, but I think it would've been the right thing to do here because the search-excerpt div will be the locator without regard to the searched item
$driver.find_elements(:xpath, "//div[@class='search-excerpt']").size.should == 1
$driver.find_elements(:link_text, 'IKEA Cam Lock Nut #103114').size.should == 1
end
def verify_load_time(start,finish)
@load_time = ((finish - start) * 1000)
@load_time.should <= 5000
end
end
When(/^I go to the Swedish Furniture Parts shopping page$/) do
@homepage = Homepage.new
@homepage.go
end
Then(/^the page should load within (\d+)ms$/) do |arg1|
@homepage.verify_load_time($start_time,$end_time)
end
Then(/^the page should set the _shopify_s cookie which expires at session end$/) do
@homepage.verify_shopify_s_cookie
@homepage.verify_cookie_expire
end
Given(/^my visit to the SFP page$/) do
@homepage = Homepage.new
@homepage.go
end
When(/^I search for Cam Lock Nut (\d+)$/) do |arg1|
@homepage.search_locknut
end
Then(/^I should get one search hit$/) do
@homepage.verify_one_search_hit
end
Given(/^a successful search for Cam Lock Nut (\d+)$/) do |arg1|
@checkout_page = Checkout.new
@checkout_page.go
end
When(/^I add two to my shopping cart$/) do
@checkout_page.add_two_locknuts
end
Then(/^I can checkout$/) do
@checkout_page.checkout
end
require 'selenium-webdriver'
require 'rspec'
require 'json'
Before do |scenario|
$driver = Selenium::WebDriver.for(:chrome)
end
After do |scenario|
$driver.quit
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment