示例#1
0
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")
    assert "" == await output.get_text()

    mouse = Mouse()
    keyboard = Keyboard()
    canvas = await session.get_element("#canvas")

    # keyboard actions cannot be emulated in non-w3c drivers
    ctx = (pytest.raises(OperationNotSupported) if isinstance(
        session, CompatSession) else null_context())

    with ctx:
        actions = chain(
            mouse.move_to(canvas),
            mouse.down() & keyboard.down("a"),
            mouse.move_by(10, 20) & keyboard.up("a"),
            mouse.up(),
        )
        await check(actions, "")

        actions = chain(
            mouse.move_to(canvas),
            mouse.down(),
            mouse.move_by(10, 20) & keyboard.down("a"),
            mouse.up(),
            keyboard.up("a"),
        )
        await check(actions, "a" * 30)

        actions = chain(
            mouse.move_to(canvas),
            mouse.down() & keyboard.down("a"),
            mouse.move_by(10, 20) & keyboard.up("a"),
            mouse.up(),
        )
        await check(actions, "")
示例#2
0
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 isinstance(
        session, CompatSession) else null_context)
    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')

    # keyboard actions cannot be emulated in non-w3c drivers
    ctx = (pytest.raises(OperationNotSupported) if isinstance(
        session, CompatSession) else null_context())

    with ctx:
        actions = chain(mouse.move_to(canvas),
                        mouse.down() & keyboard.down('a'),
                        mouse.move_by(10, 20) & keyboard.up('a'), mouse.up())
        await check(actions, '')

        actions = chain(
            mouse.move_to(canvas),
            mouse.down(),
            mouse.move_by(10, 20) & keyboard.down('a'),
            mouse.up(),
            keyboard.up('a'),
        )
        await check(actions, 'a' * 30)

        actions = chain(mouse.move_to(canvas),
                        mouse.down() & keyboard.down('a'),
                        mouse.move_by(10, 20) & keyboard.up('a'), mouse.up())
        await check(actions, '')
示例#3
0
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")
    assert "" == await output.get_text()

    mouse = Mouse()
    keyboard = Keyboard()
    canvas = await session.get_element("#canvas")

    actions = chain(
        mouse.move_to(canvas),
        mouse.down() & keyboard.down("a"),
        mouse.move_by(10, 20) & keyboard.up("a"),
        mouse.up(),
    )
    await check(actions, "")

    actions = chain(
        mouse.move_to(canvas),
        mouse.down(),
        mouse.move_by(10, 20) & keyboard.down("a"),
        mouse.up(),
        keyboard.up("a"),
    )
    await check(actions, "a" * 30)

    actions = chain(
        mouse.move_to(canvas),
        mouse.down() & keyboard.down("a"),
        mouse.move_by(10, 20) & keyboard.up("a"),
        mouse.up(),
    )
    await check(actions, "")
示例#4
0
async def drag_and_drop(session: Session, source_element: Element,
                        x_offset: int, y_offset: int):
    mouse = Mouse()
    actions = chain(
        mouse.move_to(source_element),
        mouse.down(),
        mouse.move_by(x_offset, y_offset),
        mouse.up(),
    )
    await session.perform_actions(actions)
示例#5
0
def test_drag_n_drop():
    mouse = Mouse()
    actions = chain(mouse.move_to(ELEMENT_ONE), mouse.down(),
                    mouse.move_by(100, 100), mouse.up())
    assert actions == {
        "actions": [{
            "parameters": {
                "pointerType": "mouse"
            },
            "id":
            "pointer1",
            "type":
            "pointer",
            "actions": [
                {
                    "type": "pointerMove",
                    "duration": 250,
                    "origin": {
                        constants.WEB_ELEMENT: "1"
                    },
                    "x": 0,
                    "y": 0,
                },
                {
                    "type": "pointerDown",
                    "duration": 0,
                    "button": 0
                },
                {
                    "type": "pointerMove",
                    "duration": 250,
                    "origin": "pointer",
                    "x": 100,
                    "y": 100,
                },
                {
                    "type": "pointerUp",
                    "duration": 0,
                    "button": 0
                },
            ],
        }]
    }
示例#6
0
def test_drag_n_drop():
    mouse = Mouse()
    actions = chain(mouse.move_to(ELEMENT_ONE), mouse.down(),
                    mouse.move_by(100, 100), mouse.up())
    assert actions == {
        'actions': [{
            'parameters': {
                'pointerType': 'mouse'
            },
            'id':
            'pointer1',
            'type':
            'pointer',
            'actions': [{
                'type': 'pointerMove',
                'duration': 250,
                'origin': {
                    constants.WEB_ELEMENT: '1'
                },
                'x': 0,
                'y': 0
            }, {
                'type': 'pointerDown',
                'duration': 0,
                'button': 0
            }, {
                'type': 'pointerMove',
                'duration': 250,
                'origin': 'pointer',
                'x': 100,
                'y': 100
            }, {
                'type': 'pointerUp',
                'duration': 0,
                'button': 0
            }]
        }]
    }
示例#7
0
def test_two_finger():
    finger1 = Touch('pointer1')
    finger2 = Touch('pointer2')
    actions = chain(
        finger1.move_to(ELEMENT_ONE) & finger2.move_to(ELEMENT_TWO),
        finger1.down() & finger2.down(), finger2.move_to(ELEMENT_TRI),
        finger1.up() & finger2.up())
    devices = list(sorted(actions['actions'], key=itemgetter('id')))
    assert devices == [
        {
            'parameters': {
                'pointerType': 'touch'
            },
            'id':
            'pointer1',
            'type':
            'pointer',
            'actions': [
                {
                    'type': 'pointerMove',
                    'duration': 250,
                    'origin': {
                        constants.WEB_ELEMENT: '1'
                    },
                    'x': 0,
                    'y': 0
                },
                {
                    'type': 'pointerDown',
                    'duration': 0,
                    'button': 0,
                },
                # create implicitly
                {
                    'type': 'pause',
                    'duration': 0
                },
                {
                    'type': 'pointerUp',
                    'duration': 0,
                    'button': 0,
                }
            ]
        },
        {
            'parameters': {
                'pointerType': 'touch'
            },
            'id':
            'pointer2',
            'type':
            'pointer',
            'actions': [{
                'type': 'pointerMove',
                'duration': 250,
                'origin': {
                    constants.WEB_ELEMENT: '2'
                },
                'x': 0,
                'y': 0
            }, {
                'type': 'pointerDown',
                'duration': 0,
                'button': 0,
            }, {
                'type': 'pointerMove',
                'duration': 250,
                'origin': {
                    constants.WEB_ELEMENT: '3'
                },
                'x': 0,
                'y': 0
            }, {
                'type': 'pointerUp',
                'duration': 0,
                'button': 0,
            }]
        },
    ]
示例#8
0
def test_two_finger():
    finger1 = Touch("pointer1")
    finger2 = Touch("pointer2")
    actions = chain(
        finger1.move_to(ELEMENT_ONE) & finger2.move_to(ELEMENT_TWO),
        finger1.down() & finger2.down(),
        finger2.move_to(ELEMENT_TRI),
        finger1.up() & finger2.up(),
    )
    devices = list(sorted(actions["actions"], key=itemgetter("id")))
    assert devices == [
        {
            "parameters": {
                "pointerType": "touch"
            },
            "id":
            "pointer1",
            "type":
            "pointer",
            "actions": [
                {
                    "type": "pointerMove",
                    "duration": 250,
                    "origin": {
                        constants.WEB_ELEMENT: "1"
                    },
                    "x": 0,
                    "y": 0,
                },
                {
                    "type": "pointerDown",
                    "duration": 0,
                    "button": 0
                },
                # create implicitly
                {
                    "type": "pause",
                    "duration": 0
                },
                {
                    "type": "pointerUp",
                    "duration": 0,
                    "button": 0
                },
            ],
        },
        {
            "parameters": {
                "pointerType": "touch"
            },
            "id":
            "pointer2",
            "type":
            "pointer",
            "actions": [
                {
                    "type": "pointerMove",
                    "duration": 250,
                    "origin": {
                        constants.WEB_ELEMENT: "2"
                    },
                    "x": 0,
                    "y": 0,
                },
                {
                    "type": "pointerDown",
                    "duration": 0,
                    "button": 0
                },
                {
                    "type": "pointerMove",
                    "duration": 250,
                    "origin": {
                        constants.WEB_ELEMENT: "3"
                    },
                    "x": 0,
                    "y": 0,
                },
                {
                    "type": "pointerUp",
                    "duration": 0,
                    "button": 0
                },
            ],
        },
    ]