require "selenium-webdriver"
require "test/unit"
class Mspy < Test::Unit::TestCase
  def setup
    @driver = Selenium::WebDriver.for :firefox
    @base_url = "http://mspy.com"
    @driver.manage.timeouts.implicit_wait = 30
    @verification_errors = []
  end

  def teardown
    @driver.quit
    assert_equal [], @verification_errors
  end

  # def mspy_buynow_prices
  # 	@driver.get(@base_url)
  # 	@driver.find_element(:xpath, "//*[@id='homepageid']/div[2]/div[1]/div[1]/div/div[2]/a").click
  #   assert_equal @driver.find_element(:xpath, "//*[@id='buyP']/aside[1]/div[1]/div[2]/form/div[1]/div/div[1]/div").text, "$39.99"
  #   assert_equal @driver.find_element(:xpath, "//*[@id='buyP']/aside[1]/div[1]/div[2]/form/div[1]/div/div[2]/div").text, "$59.99"
  #   assert_equal @driver.find_element(:xpath, "//*[@id='buyP']/aside[1]/div[2]/div[2]/form/div[1]/div/div[1]/div").text, "$69.99"
  #   assert_equal @driver.find_element(:xpath, "//*[@id='buyP']/aside[1]/div[2]/div[2]/form/div[1]/div/div[2]/div").text, "$119.99"
  #   assert_equal @driver.find_element(:xpath, "//*[@id='buyP']/aside[1]/div[2]/div[2]/form/div[1]/div/div[3]/div").text, "$149.99"
  #   assert_equal @driver.find_element(:xpath, "//*[@id='buyP']/aside[1]/div[2]/div[2]/form/div[1]/div/div[4]/div").text, "$199.99"
  #   assert_equal @driver.find_element(:xpath, "//*[@id='buyP']/aside[2]/div[1]/div[2]/form/div[1]/div/div[1]/div").text, "$19.99"
  #   assert_equal @driver.find_element(:xpath, "//*[@id='buyP']/aside[2]/div[1]/div[2]/form/div[1]/div/div[2]/div").text, "$33.99"
  #   assert_equal @driver.find_element(:xpath, "//*[@id='buyP']/aside[2]/div[1]/div[2]/form/div[1]/div/div[3]/div").text, "$41.99"
  #   assert_equal @driver.find_element(:xpath, "//*[@id='buyP']/aside[2]/div[1]/div[2]/form/div[1]/div/div[4]/div").text, "$59.99"

  # end

 def mspy_months
  	@driver.get(@base_url + "/buynow.html")
  	assert_equal @driver.find_element(:xpath, "//*[@id='buyP']/aside[1]/div[1]/div[2]/form/div[1]/div/div[1]/span[1]").text, "1 month"
  	element_present?(:xpath, "//*[@id='buyP']/aside[2]/div[1]/div[2]/form/div[1]/div/div[4]/div")
  end

  def element_present?(how, what)
     @driver.find_element(how, what)
     true
   rescue Selenium::WebDriver::Error::NoSuchElementError
     false
   end

  def verify(&blk)
    yield
  rescue Test::Unit::AssertionFailedError => ex
    @verification_errors << ex
  end
end