Skip to content

Commit

Permalink
Add WebDriver tests for computed label/role
Browse files Browse the repository at this point in the history
This adds tests for the new Get Computed Role and
Get Computed Label endpoints
described in w3c/webdriver#1444
  • Loading branch information
AutomatedTester committed May 27, 2020
1 parent 14401ce commit 16e2edd
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
Empty file.
35 changes: 35 additions & 0 deletions webdriver/tests/get_computed_label/get.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import pytest
from six import text_type

from webdriver.error import NoSuchAlertException

from tests.support.asserts import assert_error, assert_success
from tests.support.inline import inline


def get_computed_label(session, element):
return session.transport.send(
"GET", "session/{session_id}/element/{element_id}/computedlabel".format(
session_id=session.session_id,
element_id=element))


def test_no_browsing_context(session, closed_window):
response = get_computed_label(session)
assert_error(response, "no such window")


def test_no_user_prompt(session):
response = get_computed_label(session)
assert_error(response, "no such alert")


@pytest.mark.parametrize("tag,label", [
("<button>ok</button>", "ok"),
("<button aria-labelledby='one two'></button><div id='one'>ok</div><div id='two'>go</div>", "ok go"),
("<button aria-label='foo'>bar</button>", "foo")]
def test_get_computed_label(session, tag, label):
session.url=inline("{0}".format(tag))
element=session.find.css(tag, all=False)
result=get_computed_label(session, element.id)
assert_success(result, label)
Empty file.
35 changes: 35 additions & 0 deletions webdriver/tests/get_computed_role/get.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import pytest
from six import text_type

from webdriver.error import NoSuchAlertException

from tests.support.asserts import assert_error, assert_success
from tests.support.inline import inline


def get_computed_role(session, element):
return session.transport.send(
"GET", "session/{session_id}/element/{element_id}/computedrole".format(
session_id=session.session_id,
element_id=element))


def test_no_browsing_context(session, closed_window):
response = get_computed_role(session, "id")
assert_error(response, "no such window")


def test_no_user_prompt(session):
response = get_computed_role(session, "id")
assert_error(response, "no such alert")


@pytest.mark.parametrize("tag,role", [
("li", "menuitem"),
("input", "searchbox"),
("img", "presentation")])
def test_computed_roles(session, tag, role):
session.url = inline("<{0} role={1}>".format(tag, role))
element = session.find.css(tag, all=False)
result = get_computed_role(session, element.id)
assert_success(result, role)

0 comments on commit 16e2edd

Please sign in to comment.