示例#1
0
def chrome_launch():
    """Launch the Chrome browser using Selenium and ChromeDriver

    This function launches Chrome with the CFG options and makes the
    browser object (driver) global so that this same browser instance
    can be controlled by other functions based on other UDP messages

    Returns:
        The selenium webdriver object, which can be referenced
        for browser control
    """
    # Chrome startup options
    options = webdriver.ChromeOptions()
    user_agent = '--user-agent="' + CFG['browser']['user_agent'] + '"'
    options.add_argument(user_agent)

    if check_true(CFG['browser']['kiosk']) is True:
        options.add_argument('--kiosk')

    if check_true(CFG['browser']['touch']) is True:
        options.add_argument('--touch-events')

    if check_true(CFG['browser']['camera']) is True:
        options.add_argument('--use-fake-ui-for-media-stream')

    options.add_argument('--allow-file-access-from-files')
    options.add_argument('--enable-logging --v=1')
    options.add_argument('--disable-accelerated-video-decode')
    # Prevent infobars from appearing
    # This stops the yellow warning bar from appearing and complaining about
    # being offline or Chrome not being able to update itself.
    options.add_argument('--disable-infobars')
    options.add_argument('--silent-debugger-extension-api')

    # Prevent Chrome security messages
    options.add_argument('--test-type')

    # Launch Chrome in default location or with some alternate options
    # for common Windows paths
    try:
        driver = webdriver.Chrome(chrome_options=options)
    except webdriver.chrome.webdriver.WebDriverException:
        chrome_paths = ('/opt/boxen/homebrew/bin/chromedriver',
                        'c:\Program Files\chromedriver.exe',
                        'c:\Program Files (x86)\chromedriver.exe')
        for chrome_path in chrome_paths:
            try:
                driver = webdriver.Chrome(chrome_path, chrome_options=options)
            except webdriver.chrome.webdriver.WebDriverException:
                pass
            else:
                break

    # Visit the homepage
    driver.get(CFG['browser']['home_url'])

    return driver
示例#2
0
def main():
    """Launch the browser and run checks """

    stele_dir = get_stele_dir()
    print stele_dir
    log.info('Launching the browser')
    driver = chrome_launch()

    if check_true(CFG['browser']['restrict_domain']) is True:
        watch_browser(driver, .5)
示例#3
0
# Rotate logs daily. Keep 30 days.
handler = TimedRotatingFileHandler(
    LOG_FILENAME,
    when="d",
    interval=1,
    backupCount=30)

formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
handler.setFormatter(formatter)
log.addHandler(handler)

#
# Custom imports based on configuration
#
CFG = get_machines_config()
if check_true(CFG['browser']['delay']) is True:
    print (
        'Waiting ' +
        CFG['browser']['delay_seconds'] +
        ' seconds before launching.')

    time.sleep(float(CFG['browser']['delay_seconds']))
if check_true(CFG['browser']['custom_check']) is True:
    from custom import custom_check


def chrome_launch():
    """Launch the Chrome browser using Selenium and ChromeDriver

    This function launches Chrome with the CFG options and makes the
    browser object (driver) global so that this same browser instance