import os
import configparser
from engine.logger import Logger

'''
proDir = os.path.split(os.path.realpath(__file__))[0]
print(proDir)
configPath = os.path.join(proDir, "config.ini")
print(configPath)
'''


# logger = logging.getLogger('read_config')


class ReadConfig(Logger):
    __log_name = 'read_config'

    def __init__(self, log_name=__log_name):
        super().__init__(log_name)
        self._configPath = ''
        self.join_config_path()
        self.cf = configparser.ConfigParser()
        self.cf.read(self._configPath, encoding="utf-8-sig")

    def join_config_path(self):
        # proDir = os.path.dirname(os.path.abspath('.'))
        self._configPath = os.path.dirname(os.path.abspath('..')) + r'\config\config.ini'
        self.logger.info("the configPath: %s" % self._configPath)

    def get_browserType(self, param):
        value = self.cf.get("browserType", param)
        self.logger.info("the browserType : %s" % value)
        return value

    def get_testUrl(self, param):
        value = self.cf.get("testUrl", param)
        # self.logger.info("the testUrl : %s" % value)
        return value

    def get_userInfo(self, param):
        value = self.cf.get("userInfo", param)
        self.logger.info("the userInfo : %s" % value)
        return value

    def get_caseId(self, param):
        value = self.cf.get("gsjdCase", param)
        self.logger.info("the gsjdCase : %s" % value)
        return value


'''
if __name__ == '__main__':
    test = ReadConfig()
    browser = test.get_browserType('browserName')
    username =  test.get_userInfo('username')
    password = test.get_userInfo('password')
    print(browser,username,password)
'''
