#!/usr/bin/env python
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
import unittest, time, re

class TRADLoginLogout(unittest.TestCase):
    def setUp(self):

#Added these three lines
        desired_cap = {'browser': 'firefox', 'browser_version': '31.0', 'os': 'Windows', 'os_version': '8.1', 'resolution': '2048x1536'}

#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_t_r_a_d_login_logout(self):
        driver = self.driver
     #   driver.set_window_size(2000, 2560)
        driver.get(self.base_url + "/")
        driver.save_screenshot('screenshot.png')
        driver.find_element_by_xpath("//div[@id='login_top']/form/div/input").clear()
        driver.save_screenshot('screenshot.png')
        driver.find_element_by_xpath("//div[@id='login_top']/form/div/input").send_keys("dveent@4over.com")
        driver.save_screenshot('screenshot.png')
        driver.find_element_by_xpath("//div[@id='login_top']/form/div[2]/input").clear()
        driver.save_screenshot('screenshot.png')
        driver.find_element_by_xpath("//div[@id='login_top']/form/div[2]/input").send_keys("tehran81")
        driver.save_screenshot('screenshot.png')
        driver.find_element_by_xpath("//div[@id='login_top']/form/div[3]/input").click()
        driver.save_screenshot('screenshot.png')
        driver.find_element_by_xpath("//a[contains(text(),'Business Cards')]").click()
        driver.save_screenshot('screenshot.png')
        driver.find_element_by_xpath(u"//a[contains(text(),'Logout')]").click()
        driver.save_screenshot('screenshot.png')
        print "Succeed"
    
    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()


