Пример #1
0
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()
Пример #2
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.')
Пример #3
0
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()
Пример #4
0
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()
Пример #5
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.')