# Path: xpathwebdriver/base.py
# class XpathWdBase(object):
#     log = Logger('xpath root', color=solve_settings().get('log_color'))
# 
#     @property
#     def global_settings(self):
#         return solve_settings()
# 
# class singleton_decorator(object):
# 
#     '''
#       Singleton pattern decorator.
#       There will be only one instance of the decorated class.
#     '''
# 
#     def __init__(self, class_):
#         self.class_ = class_
#         self.instance = None
# 
#     def __call__(self, *a, **ad):
#         if self.instance is None:
#             self.instance = self.class_(*a, **ad)
#         return self.instance
# 
# Path: xpathwebdriver/levels.py
# TEST_ROUND_LIFE = -2
# 
# MANAGER_LIFE = -3


import rel_imp; rel_imp.init()
import os
import logging
import json
import shlex
    import time
from selenium import webdriver
from pyvirtualdisplay import Display
from threading import RLock
from functools import wraps
from selenium.common.exceptions import UnexpectedAlertPresentException, WebDriverException
from .base import XpathWdBase, singleton_decorator
from xpathwebdriver.levels import TEST_ROUND_LIFE, MANAGER_LIFE
from selenium.webdriver.remote.webdriver import WebDriver
from collections import namedtuple
                from selenium.webdriver.chrome.options import Options
        from .logger import Logger
        from .xpath_browser import XpathBrowser
    from .logger import log_test

    def acquire_driver(self):
        if not self.webdriver:
            self.webdriver = self.parent.acquire_driver(self.level, self.browser_name, self.name)
        return self.webdriver

    def get_xpathbrowser(self, base_url=None, name=''):
        base_url = base_url or self.base_url or self.global_settings.get('base_url')
        name = name or self.name
        # Initialize the XpathBrowser class
        return XpathBrowser(self.acquire_driver(), base_url,
                            Logger(name), settings=self.global_settings)

    def release_driver(self):
        if self.webdriver:
            self.parent.release_driver(self.webdriver, self.level)
            self.webdriver = None


def get_browser(context_name='default', browser=None):
    '''
    :param name: optional context's name (mainly for logging purposes)
    :param browser: optional browser name string (eg: 'Firefox', 'Chrome', 'PhantomJs')
    '''
    return WebdriverManager().get_browser(context_name, browser)


def smoke_test_module():
    mngr = WebdriverManager()
#    import ipdb; ipdb.set_trace()

# Path: xpathwebdriver/base.py
# class XpathWdBase(object):
#     log = Logger('xpath root', color=solve_settings().get('log_color'))
# 
#     @property
#     def global_settings(self):
#         return solve_settings()
# 
# class singleton_decorator(object):
# 
#     '''
#       Singleton pattern decorator.
#       There will be only one instance of the decorated class.
#     '''
# 
#     def __init__(self, class_):
#         self.class_ = class_
#         self.instance = None
# 
#     def __call__(self, *a, **ad):
#         if self.instance is None:
#             self.instance = self.class_(*a, **ad)
#         return self.instance
# 
# Path: xpathwebdriver/levels.py
# TEST_ROUND_LIFE = -2
# 
# MANAGER_LIFE = -3


# Path: xpathwebdriver/webdriver_manager.py
import rel_imp; rel_imp.init()
import os
import logging
import json
import shlex
    import time
from selenium import webdriver
from pyvirtualdisplay import Display
from threading import RLock
from functools import wraps
from selenium.common.exceptions import UnexpectedAlertPresentException, WebDriverException
from .base import XpathWdBase, singleton_decorator
from xpathwebdriver.levels import TEST_ROUND_LIFE, MANAGER_LIFE
from selenium.webdriver.remote.webdriver import WebDriver
from collections import namedtuple
                from selenium.webdriver.chrome.options import Options
        from .logger import Logger
        from .xpath_browser import XpathBrowser
    from .logger import log_test


    def acquire_driver(self):
        if not self.webdriver:
            self.webdriver = self.parent.acquire_driver(self.level, self.browser_name, self.name)
        return self.webdriver

    def get_xpathbrowser(self, base_url=None, name=''):
        base_url = base_url or self.base_url or self.global_settings.get('base_url')
        name = name or self.name
        # Initialize the XpathBrowser class
        return XpathBrowser(self.acquire_driver(), base_url,
                            Logger(name), settings=self.global_settings)

    def release_driver(self):
        if self.webdriver:
            self.parent.release_driver(self.webdriver, self.level)
            self.webdriver = None


def get_browser(context_name='default', browser=None):
    '''
    :param name: optional context's name (mainly for logging purposes)
    :param browser: optional browser name string (eg: 'Firefox', 'Chrome', 'PhantomJs')
    '''
    return WebdriverManager().get_browser(context_name, browser)


def smoke_test_module():
    mngr = WebdriverManager()
#    import ipdb; ipdb.set_trace()

    lvl = mngr.enter_level(level=TEST_ROUND_LIFE)