from helium.bfs10077.bfs10104 import bfs10154
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.chrome.service import Service as bfs10164
from selenium.webdriver.common import utils
from time import sleep
import os
import selenium
import selenium.webdriver.chrome.webdriver
import subprocess
import sys
def bfs10167():
  global bfs10165
  if (not bfs10166()):
    return 

  if (sys.version_info[:2] < (2, 7)):
    from _subprocess import STARTF_USESTDHANDLES, STARTF_USESHOWWINDOW, SW_HIDE, CREATE_NEW_CONSOLE
  else:
    from subprocess import STARTF_USESTDHANDLES, STARTF_USESHOWWINDOW, SW_HIDE, CREATE_NEW_CONSOLE

  class _SilentChromeDriverService(bfs10164):
    def start(self):
      env = (self.env or os.environ)
      try:
        bfs10170 = subprocess.STARTUPINFO()
        bfs10170.dwFlags = (STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW)
        bfs10170.wShowWindow = SW_HIDE
        bfs10170.hStdInput = open(os.devnull, 'r').fileno()
        bfs10170.hStdOutput = open(os.devnull, 'w').fileno()
        bfs10170.hStdError = open(os.devnull, 'w').fileno()
        self.process = subprocess.Popen(([self.path, ('--port=%d' % self.port)] + self.service_args), env=env, close_fds=True, creationflags=CREATE_NEW_CONSOLE, startupinfo=bfs10170)
      except:
        raise WebDriverException(('Could not execute ChromeDriver located at %s.' % self.path))

      count = 0
      while (not utils.is_connectable(self.port)):
        count += 1
        sleep(1)
        if (count == 30):
          raise WebDriverException('Can not connect to the ChromeDriver')




  selenium.webdriver.chrome.webdriver.Service = _SilentChromeDriverService
  bfs10165 = True

def bfs10166():
  if bfs10165:
    return False

  if (not bfs10154()):
    return False

  try:
    bfs10171 = tuple(map(int, selenium.__version__.split('.')))
  except:
    return False
  else:
    return (bfs10171 >= (2, 32, 0))


bfs10165 = False
