# -----------------------------------------------------------------------------
# Class to load settings from the seleniumsettings.json file
# ----------------------------------------------------------------------------

import json
import os
from robot.api import logger


class DesiredCapabilities:
    """
    Class that loads and exposes the selenium settings from the seleniumsettings.json file
    """
    __json_data = None
    __desired_cap = None

    @staticmethod
    def __get_json_value(key):
        if DesiredCapabilities.__json_data is None:
            filename = os.path.abspath(os.path.join(os.path.dirname(__file__), 'desiredcapabilities.json'))
            with open(filename, 'r') as json_file:
                raw_data = json_file.read()
                DesiredCapabilities.__json_data = json.loads(raw_data)
                logger.info("Selenium settings json file loaded")
        return DesiredCapabilities.__json_data[key]

    @staticmethod
    def get_browser_desired_capabilities(keyvalue):
        
        try:
            DesiredCapabilities.__desired_cap = DesiredCapabilities.__get_json_value(keyvalue)
            print(DesiredCapabilities.__desired_cap)
            return DesiredCapabilities.__desired_cap
        except KeyError as error:
            raise Exception(error)