import unittest

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support import expected_conditions as EC

class SkippTest(unittest.TestCase):
    def setUp(self):

        self.testing_target = int(input('TESTING TARGET - [0]: development | [1]: production \n'))
        self.targets = ['http://localhost:3000', 'http://www.softwareontheshore.com']

        self.test_url = self.targets[self.testing_target]

        chrome_options = webdriver.ChromeOptions()
        chrome_options.add_argument('--incognito')

        self.browser = webdriver.Chrome('/bin/chromedriver', chrome_options=chrome_options)
        self.browser.implicitly_wait(10)

        self.addCleanup(self.browser.quit)

    ## Organizer Login, Search, Create Collab
    def testShoresideSoftware(self):
        self.logs = []
        self.wait = WebDriverWait(self.browser, 10)

        try:
            print 'TESTING: ' + str(self.test_url).upper()

            ## LANDING
            self.browser.get(self.test_url)
            self.logs.extend(self.browser.get_log('browser'))

            print 'LANDING PASS'

            ## PORTFOLIO
            self.browser.find_element_by_id('sidebar-toggle').click()
            self.browser.find_element_by_id('navigation-portfolio').click()
            self.logs.extend(self.browser.get_log('browser'))

            print 'PORTFOLIO PASS'

            ## APPS
            self.browser.find_element_by_id('sidebar-toggle').click()
            self.browser.find_element_by_id('navigation-apps').click()
            self.logs.extend(self.browser.get_log('browser'))

            print 'APPS PASS'

            ## LINKS
            self.browser.find_element_by_id('sidebar-toggle').click()
            self.browser.find_element_by_id('navigation-links').click()
            self.logs.extend(self.browser.get_log('browser'))

            print 'LINKS PASS'
            print 'SITE FUNCTIONAL ALL PASS'

            print 'ISSUES FOUND: ' + str(len(self.logs))

            if len(self.logs) > 0:
                for i, x in enumerate(self.logs):
                    print '----------- LOG ' + str(i) + ' --------------------'
                    print '----------- LEVEL: '  + str(x['level'])
                    print '----------- MESSAGE: ' + str(x['message'])

        except Exception as error:
            print error

            if len(self.logs) > 0:
                for i, x in enumerate(self.logs):
                    print '----------- LOG ' + str(i) + ' --------------------'
                    print '----------- LEVEL: '  + str(x['level'])
                    print '----------- MESSAGE: ' + str(x['message'])

            raise error


if __name__ == '__main__':
    unittest.main(verbosity=1)
