import os
import platform
from time import sleep, time

from src.framework.common import file_abspath

from selenium import webdriver
from selenium.webdriver.chrome import service
from selenium.webdriver.chrome.webdriver import WebDriver

# web_driver_path = os.path.join(
#     "./chromedriver")
if platform.system().lower() == "windows":
    service = webdriver.chrome.service.Service(file_abspath() + "/tools/chromedriver.exe")
elif platform.system().lower() == "darwin":
    service = webdriver.chrome.service.Service(file_abspath() + "/tools/chromedriver")
    os.system('chmod 777 {}'.format(file_abspath() + "/tools/chromedriver"))

service.start()


def get_app_driver(PATH_TO_BINARY_APP):
    driver: WebDriver = webdriver.remote.webdriver.WebDriver(
        command_executor=service.service_url,
        desired_capabilities={
            'browserName': 'chrome',
            'goog:chromeOptions': {
                'args': [],
                'binary': PATH_TO_BINARY_APP,
                'extensions': [],
                'windowTypes': ['webview']},
            'platform': 'ANY',
            'version': ''},
        browser_profile=None,
        proxy=None,
        keep_alive=False)
    sleep(5)
    return driver


if __name__ == '__main__':
    get_app_driver()
    # driver = get_app_driver(PATH_TO_BINARY_APP)
    # driver.find_element_by_id("rc-tabs-0-tab-2").click()
