def create_session():
    """ Auxiliary (not a testing) function."""
    drv = SessionDriver()
    drv.session.mustsave = True
    drv.mustdelete = False
    drv.launch(new_session=True)
    info = drv.session.contents
    return info
def test_session_connect():
    session_info = create_session()
    drv = SessionDriver()
    drv.client_connect(session_info)
    drv.get('https://www.breitbart.com/')
    assert drv.title == 'Breitbart News Network'
    drv.quit()
def test_launch_brand_new_session():
    drv = SessionDriver()
    drv.launch(new_session=True)
    assert not drv.session.is_empty(), 'Session info is empty!'
    drv.get('https://en.wikipedia.org/wiki/Sevastopol')
    assert drv.title == 'Sevastopol - Wikipedia', 'Wikipedia page about the legendary city not diplayed.'
    drv.quit()
Exemple #4
0
def main():

    headless = True
    fpath = dir_session_default
    savetofile = True

    try:
        opts, args = getopt.getopt(sys.argv[1:], 'l:', [])
    except getopt.GetoptError as err:
        logger.error(err)
        logger.info(__doc__)
        sys.exit(2)
    for opt, args in opts:
        if opt == '-l':
            fpath = args

    drv = SessionDriver()
    drv.session.mustdelete = True
    drv.options.headless = headless
    if fpath != dir_session_default:
        drv.session.location = fpath
    if not drv.session.file_exists():
        logger.critical('No session found.')
    else:
        drv.session.destroy()
def test_launch_connect_to_existing_session():
    session_info = create_session()
    drv = SessionDriver()
    drv.launch(new_session=False)
    exp = session_info[kwd_sessionid]
    act = drv.session.id
    assert act == exp, 'Expected session id: ' + exp + 'actual: ' + act
    drv.quit()
Exemple #6
0
def main():
    fpath = dir_session_default
    try:
        opts, args = getopt.getopt(sys.argv[1:], 'l:dhv', [])
    except getopt.GetoptError as err:
        logger.error(err)
        logger.info(__doc__)
        sys.exit(2)
    for opt, args in opts:
        if opt == '-h':
            logger.critical(__doc__)
            sys.exit()
        if opt == '-l':
            fpath = args
        if opt == '-v':
            loggers_set(logging.DEBUG)
    drv = SessionDriver()
    drv.session.location = fpath
    if drv.session.file_exists():
        drv.launch(new_session=False)
        drv.quit()
    else:
        logger.critical('No saved session found.')
Exemple #7
0
def main():
    drv = SessionDriver()
    drv.options.headless = False  # start viperdriver in visible mode

    if drv.session.file_exists():  # if previous session exists, connect to it
        print('Session file found: ' + drv.session.full_path())
        drv.launch(new_session=False)
        print('Will now navigate to Google in:')
        x = range(5)
        for i in x:
            print('\b', x[-1 - i], sep='', end='', flush=True)
            sleep(1)
        print('\n')
        drv.get('http://google.com')
        print('Will now close the browser.')
        for i in range(10):
            print('.', sep='', end='', flush=True)
            sleep(0.5)
        print('\n')
        drv.quit()
    else:  # if session does not exist, create new one and save to file
        drv.launch(new_session=True)
        drv.set_window_size(600, 300)
        drv.session.save_to_file()
        print('Exiting. Please start again.')