#!/usr/bin/env python
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re

class TradeSiteTest(unittest.TestCase):
    def setUp(self):
        #Added these three lines
        desired_cap = {'browser': 'Chrome', 'browser_version': '43.0', 'os': 'OS X', 'os_version': 'Yosemite', 'resolution': '1920x1080'}

#Added this line to enable the Visual Logs tab.
        desired_cap['browserstack.debug'] = True
        desired_cap['build'] = 'v1.0'
        desired_cap['project'] = 'Trade'

#To run on BrowserStack's remote machines
        self.driver = webdriver.Remote(command_executor='http://dianesalter1:xXz8vB9ft7A9zjksCyBm@hub.browserstack.com:80/wd/hub', desired_capabilities=desired_cap)
        self.driver.implicitly_wait(30)
        self.base_url = "https://trade.4over.com/"
        self.verificationErrors = []
        self.accept_next_alert = True
    
    def test_trade_site(self):
        driver = self.driver
        driver.get(self.base_url + "")
        driver.maximize_window()
        driver.find_element_by_xpath("//div/input").clear()
        driver.find_element_by_xpath("//div/input").send_keys("andreg@4over.com")
        time.sleep(1)
        driver.find_element_by_xpath("//div[2]/input").clear()
        driver.find_element_by_xpath("//div[2]/input").send_keys("asdasd")
        time.sleep(1)
        driver.find_element_by_xpath("//div[3]/input").click()
        time.sleep(5)
        driver.find_element_by_xpath("//div[2]/div/div/div/div[3]/ul/li[4]/a").click()
        # time.sleep(6)
        # driver.find_element_by_xpath("//div[3]/div[8]/div/a").click()
        # time.sleep(4)
        # Select(driver.find_element_by_xpath("//div/span/select")).select_by_visible_text("500")
        # time.sleep(1)
        # driver.find_element_by_xpath("//div/span/select/option[6]").click()
        # time.sleep(1)
        # Select(driver.find_element_by_xpath("//div/span[2]/select")).select_by_visible_text("4:0")
        # time.sleep(1)
        # driver.find_element_by_xpath("//div/span[2]/select/option[2]").click()
        # time.sleep(1)
        # Select(driver.find_element_by_xpath("//div/span[3]/select")).select_by_visible_text("2-4 Business Days")
        # time.sleep(3)
        # driver.find_element_by_xpath("//div/span[3]/select/option[4]").click()
        # time.sleep(3)
        # driver.find_element_by_xpath("//td[3]/input").clear()
        # driver.find_element_by_xpath("//td[3]/input").send_keys("test")
        # time.sleep(3)
        # driver.find_element_by_xpath("//span/input").click()
        # time.sleep(7)
        # driver.find_element_by_xpath("//div[2]/input").click()
        # time.sleep(5)
        # driver.find_element_by_xpath("//a[2]/img").click()
        # time.sleep(3)
        # driver.find_element_by_xpath("//div[2]/p/input").click()
        time.sleep(3)
        driver.find_element_by_xpath("//html/body/div[1]/div/div/div/div[3]/div[1]/div[2]/div[4]/div[2]/a").click()
        time.sleep(2)
    
    def is_element_present(self, how, what):
        try: self.driver.find_element(by=how, value=what)
        except NoSuchElementException, e: return False
        return True
    
    def is_alert_present(self):
        try: self.driver.switch_to_alert()
        except NoAlertPresentException, e: return False
        return True
    
    def close_alert_and_get_its_text(self):
        try:
            alert = self.driver.switch_to_alert()
            alert_text = alert.text
            if self.accept_next_alert:
                alert.accept()
            else:
                alert.dismiss()
            return alert_text
        finally: self.accept_next_alert = True
    
    def tearDown(self):
        self.driver.quit()
        self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
    unittest.main()
