Skip to content

Instantly share code, notes, and snippets.

@arabyniuk
Created November 1, 2016 13:43
Show Gist options
  • Save arabyniuk/b42519adb5b8a896c692a78f45a0dce7 to your computer and use it in GitHub Desktop.
Save arabyniuk/b42519adb5b8a896c692a78f45a0dce7 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'selenium-webdriver'
LOGIN = "[email protected]"
PASSWORD = "***"
DOMAINS = ["example1.myshopify.com", "example2.myshopify.com"]
CUSTOM_MESSAGE = "custom message"
LOGIN_PATH = "https://app.shopify.com/services/partners/auth/login?return_to=shopify-experts"
TESTIMONIALS_PATH = "https://experts.shopify.com/account/testimonials"
#LOGIN_PATH ='http://localhost:3000'
#TESTIMONIALS_PATH = 'http://localhost:3000/step_3'
class SeleniumShopify
attr_reader :driver
def initialize
#Selenium::WebDriver::Firefox.path = "/usr/bin/firefox"
@driver = Selenium::WebDriver.for :firefox
end
def login
driver.find_element(:css, '#sign-in-form #login-input').send_keys(LOGIN)
driver.find_element(:css, '#sign-in-form #password').send_keys(PASSWORD)
driver.find_element(:css, '#sign-in-form .dialog-btn').click
rescue => e
puts e
end
def move_to(path)
driver.get(path)
end
def quit
driver.quit
end
def testimonials_item
driver.find_element(:id, 'account-header')
.find_element(:text, 'Testimonials')
end
def testimonials_page?
wait = Selenium::WebDriver::Wait.new(:timeout => 10)
wait.until { driver.find_element(:id, 'shop') }
driver.find_element(:css, '#account-header .active').text == "Testimonials"
end
def page_contain_domain?(domain)
wait = Selenium::WebDriver::Wait.new(:timeout => 10)
wait.until { driver.find_element(:css, '#account h3') }
#domain = "beer-rau137.myshopify.com"
driver.find_element(:css, '#account h3').text.include?(domain)
end
def perform_shop_domains(domain)
driver.find_element(:id, 'shop').send_keys(domain)
driver.find_element(:css, 'form > input[name=commit]').click
end
def perform_custom_message
driver.find_element(:tag_name, 'textarea').send_keys(CUSTOM_MESSAGE)
driver.find_element(:css, 'form input[name=commit]').click
end
def has_success_msg?(domain)
wait = Selenium::WebDriver::Wait.new(:timeout => 10)
wait.until { driver.find_element(:id, 'flash-notice') }
#domain = "beer-rau137.myshopify.com"
driver.find_element(:id, 'flash-notice').text.include?(domain)
rescue => e
puts e
end
end
selenium_shopify = SeleniumShopify.new
selenium_shopify.move_to(LOGIN_PATH)
selenium_shopify.login
DOMAINS.each do |domain|
next if domain.empty?
print "#{domain}..."
selenium_shopify.move_to(TESTIMONIALS_PATH)
if selenium_shopify.testimonials_page?
selenium_shopify.perform_shop_domains(domain)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment