Example #1
0
def browsers(*br: Browser):
    if len(br) == 0:
        br = (FF, FFH, CH)
    if not has_x():
        br = tuple(b for b in br if b.headless)

    from functools import wraps

    def dec(f):
        if len(br) == 0:
            dec_ = pytest.mark.skip(
                'Filtered out all browsers (because of no GUI/non-interactive mode)'
            )
        else:
            dec_ = pytest.mark.parametrize(
                'browser',
                br,
                ids=lambda b: b.dist.replace('-', '_') +
                ('_headless' if b.headless else ''))

        @with_browser_tests
        @dec_
        @wraps(f)
        def ff(*args, **kwargs):
            return f(*args, **kwargs)

        return ff

    return dec
Example #2
0
def test_stress(tmp_path, browser) -> None:
    url = 'https://www.reddit.com/'
    urls = [(f'{url}/subpath/{i}.html', f'context {i}' if i > 10000 else None)
            for i in range(50000)]
    with _test_helper(tmp_path, index_urls(urls), url,
                      browser=browser) as helper:
        if has_x():
            helper.activate()

        manual.confirm('''
Is performance reasonable?
The sidebar should show up, and update gradually.
You should be able to scroll the page, trigger tooltips, etc., without any lags.
'''.strip())
Example #3
0
    def confirm(self, what: str) -> None:
        confirm(what)


class Headless(Manual):
    def confirm(self, what: str) -> None:
        logger.warning('"%s": headless mode, responding "yes"', what)


'''
Helper for tests that are not yet fully automated and require a human to check...
- if running with the GUI, will be interactive
- if running in headless mode, will automatically assume 'yes'.
  of course it's not very robust, but at least we're testing some codepaths then
'''
manual = Interactive() if has_x() else Headless()


@contextmanager
def _test_helper(tmp_path,
                 indexer,
                 test_url: Optional[str],
                 browser: Browser = FFH,
                 **kwargs):
    tdir = Path(tmp_path)

    indexer(tdir)
    with wserver(db=tdir / 'promnesia.sqlite') as srv, get_webdriver(
            browser=browser) as driver:
        port = srv.port
        configure(driver, port=port, **kwargs)