How to use arsenic - 10 common examples

To help you get started, we’ve selected a few arsenic examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github HDE / arsenic / tests / infra / services.py View on Github external
}


@attr.s
class ServiceContext:
    driver = attr.ib()
    browser = attr.ib()
    name = attr.ib()


SERVICE_CONTEXTS = []


if shutil.which('geckodriver'):
    SERVICE_CONTEXTS.append(ServiceContext(
        driver=Geckodriver(log_file=sys.stdout),
        browser=Firefox(),
        name='geckofirefox'
    ))


def get_remote_drivers(remotes):
    for remote in remotes.split(' '):
        parsed = urlparse(remote)
        query = dict(parse_qsl(parsed.query))
        browser_name = query.pop('browser', None)
        browser = BROWSERS.get(browser_name, None)
        if browser is not None:
            unparsed = urlunparse((
                parsed.scheme,
                parsed.netloc,
                parsed.path,
github HDE / arsenic / tests / test_real_browsers.py View on Github external
async def test_change_window(session):
    if isinstance(session, CompatSession) or isinstance(
        session.driver.connection, RemoteConnection
    ):
        raise pytest.skip("not supported in compat session at the moment")
    handles = await session.get_window_handles()
    assert len(handles) == 1
    for i in range(4):
        await session.execute_script("window.open();")

    async def checker():
        handles = await session.get_window_handles()
        if len(handles) == 5:
            return handles
        return False

    handles = await session.wait(5, checker)
    await session.switch_to_window(handles[2])
    current = await session.get_window_handle()
github HDE / arsenic / tests / test_aiohttp.py View on Github external
async def test_simple_form_submit(app_port, service):
    async with service.driver.run(Aiohttp) as driver:
        async with driver.session(service.browser) as session:
            await session.get(f'http://127.0.0.1:{app_port}/html/')
            field = await session.get_element('input[name="field"]')
            await field.send_keys('sample input')
            submit = await session.get_element('input[type="submit"]')
            await submit.click()
            assert 'sample input' in await session.get_page_source()
github HDE / arsenic / tests / test_tornado.py View on Github external
async def test_simple_form_submit(base_url, service, http_server):
    async with service.driver.run(Tornado) as driver:
        async with driver.session(service.browser) as session:
            await session.get(f'{base_url}/html/')
            field = await session.get_element('input[name="field"]')
            await field.send_keys('sample input')
            submit = await session.get_element('input[type="submit"]')
            await submit.click()
            assert 'sample input' in await session.get_page_source()
github HDE / arsenic / tests / infra / services.py View on Github external
for remote in remotes.split(' '):
        parsed = urlparse(remote)
        query = dict(parse_qsl(parsed.query))
        browser_name = query.pop('browser', None)
        browser = BROWSERS.get(browser_name, None)
        if browser is not None:
            unparsed = urlunparse((
                parsed.scheme,
                parsed.netloc,
                parsed.path,
                '',
                '',
                ''
            ))
            yield ServiceContext(
                driver=Remote(unparsed),
                browser=browser(**query),
                name=f'remote{browser_name}'
            )
github HDE / arsenic / tests / test_real_browsers.py View on Github external
async def test_change_window(session):
    if isinstance(session, CompatSession) or isinstance(
        session.driver.connection, RemoteConnection
    ):
        raise pytest.skip("not supported in compat session at the moment")
    handles = await session.get_window_handles()
    assert len(handles) == 1
    for i in range(4):
        await session.execute_script("window.open();")

    async def checker():
        handles = await session.get_window_handles()
        if len(handles) == 5:
            return handles
        return False

    handles = await session.wait(5, checker)
    await session.switch_to_window(handles[2])
github HDE / arsenic / tests / test_real_browsers.py View on Github external
async def test_chained_actions(session):
    if isinstance(session.browser, Firefox) and isinstance(
        session.driver.connection, RemoteConnection
    ):
        raise pytest.skip("remote firefox actions do not work")

    async def check(actions, expected):
        await session.perform_actions(actions)
        output = await session.get_element("#output")
        assert expected == await output.get_text()

    await session.get("/actions/")
    output = await session.wait_for_element(5, "#output")
    assert "" == await output.get_text()

    await session.get("/actions/")

    output = await session.wait_for_element(5, "#output")
github HDE / arsenic / tests / test_real_browsers.py View on Github external
async def test_chained_actions(session):
    if isinstance(session.browser, Firefox) and isinstance(session.service, Remote):
        pytest.xfail('remote firefox actions do not work')

    async def check(actions, expected):
        await session.perform_actions(actions)
        output = await session.get_element('#output')
        assert expected == await output.get_text()

    await session.get('/actions/')
    output = await session.wait_for_element(5, '#output')
    assert '' == await output.get_text()
    mouse = Mouse()
    keyboard = Keyboard()
    canvas = await session.get_element('#canvas')
    ctx = (
        pytest.raises(OperationNotSupported)
        if
github HDE / arsenic / tests / infra / services.py View on Github external
import os
from urllib.parse import urlparse, parse_qsl, urlunparse

import attr
import shutil

import sys

from arsenic.browsers import Firefox
from arsenic.services import Geckodriver, Remote


BROWSERS = {
    'firefox': Firefox,
}


@attr.s
class ServiceContext:
    driver = attr.ib()
    browser = attr.ib()
    name = attr.ib()


SERVICE_CONTEXTS = []


if shutil.which('geckodriver'):
    SERVICE_CONTEXTS.append(ServiceContext(
        driver=Geckodriver(log_file=sys.stdout),
github HDE / arsenic / tests / test_services.py View on Github external
async def test_geckodriver_version_ok(tmpdir, version, check, result):
    path = tmpdir.join("geckodriver")
    path.write(f'#!{sys.executable}\nprint("geckodriver {version}")')
    path.chmod(0o755)
    driver = Geckodriver(binary=str(path), version_check=check)
    if result:
        await driver._check_version()
    else:
        with pytest.raises(ValueError):
            await driver._check_version()