Skip to content

Commit

Permalink
Create dedicated tests for script.evaluate exceptionDetails
Browse files Browse the repository at this point in the history
  • Loading branch information
juliandescottes authored and pull[bot] committed Sep 7, 2023
1 parent 0c81808 commit 8815898
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 45 deletions.
46 changes: 1 addition & 45 deletions webdriver/tests/bidi/script/evaluate/evaluate.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import pytest
from webdriver.bidi.modules.script import ContextTarget, ScriptEvaluateResultException

from ... import any_int, any_string, recursive_compare
from .. import any_stack_trace
from webdriver.bidi.modules.script import ContextTarget


@pytest.mark.asyncio
Expand All @@ -17,47 +14,6 @@ async def test_eval(bidi_session, top_context):
"value": 3}


@pytest.mark.asyncio
async def test_params_expression_invalid_script(bidi_session, top_context):
with pytest.raises(ScriptEvaluateResultException) as exception:
await bidi_session.script.evaluate(
expression='))) !!@@## some invalid JS script (((',
target=ContextTarget(top_context["context"]),
await_promise=True)
recursive_compare({
'realm': any_string,
'exceptionDetails': {
'columnNumber': any_int,
'exception': {
'handle': any_string,
'type': 'error'},
'lineNumber': any_int,
'stackTrace': any_stack_trace,
'text': any_string}},
exception.value.result)


@pytest.mark.asyncio
async def test_exception(bidi_session, top_context):
with pytest.raises(ScriptEvaluateResultException) as exception:
await bidi_session.script.evaluate(
expression="throw Error('SOME_ERROR_MESSAGE')",
target=ContextTarget(top_context["context"]),
await_promise=True)

recursive_compare({
'realm': any_string,
'exceptionDetails': {
'columnNumber': any_int,
'exception': {
'handle': any_string,
'type': 'error'},
'lineNumber': any_int,
'stackTrace': any_stack_trace,
'text': any_string}},
exception.value.result)


@pytest.mark.asyncio
async def test_interact_with_dom(bidi_session, top_context):
result = await bidi_session.script.evaluate(
Expand Down
122 changes: 122 additions & 0 deletions webdriver/tests/bidi/script/evaluate/exception_details.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import pytest

from webdriver.bidi.modules.script import ContextTarget, ScriptEvaluateResultException

from ... import any_int, any_string, recursive_compare
from .. import any_stack_trace


@pytest.mark.asyncio
async def test_invalid_script(bidi_session, top_context):
with pytest.raises(ScriptEvaluateResultException) as exception:
await bidi_session.script.evaluate(
expression='))) !!@@## some invalid JS script (((',
target=ContextTarget(top_context["context"]),
await_promise=True)
recursive_compare({
'realm': any_string,
'exceptionDetails': {
'columnNumber': any_int,
'exception': {
'handle': any_string,
'type': 'error'},
'lineNumber': any_int,
'stackTrace': any_stack_trace,
'text': any_string}},
exception.value.result)


@pytest.mark.asyncio
async def test_reject_complex_value(bidi_session, top_context):
with pytest.raises(ScriptEvaluateResultException) as exception:
await bidi_session.script.evaluate(
expression="Promise.reject(new Set(['SOME_REJECTED_RESULT']))",
target=ContextTarget(top_context["context"]),
await_promise=True,
)

recursive_compare(
{
"realm": any_string,
"exceptionDetails": {
"columnNumber": any_int,
"exception": {
"type": "set", "value": [
{"type": "string", "value": "SOME_REJECTED_RESULT"}
]
},
"lineNumber": any_int,
"stackTrace": any_stack_trace,
"text": any_string,
},
},
exception.value.result,
)


@pytest.mark.asyncio
async def test_reject_error(bidi_session, top_context):
with pytest.raises(ScriptEvaluateResultException) as exception:
await bidi_session.script.evaluate(
expression="Promise.reject(new Error('SOME_ERROR_MESSAGE'))",
target=ContextTarget(top_context["context"]),
await_promise=True,
)

recursive_compare(
{
"realm": any_string,
"exceptionDetails": {
"columnNumber": any_int,
"exception": {
"handle": any_string,
"type": "error"},
"lineNumber": any_int,
"stackTrace": any_stack_trace,
"text": any_string,
},
},
exception.value.result,
)


@pytest.mark.asyncio
async def test_throw_error(bidi_session, top_context):
with pytest.raises(ScriptEvaluateResultException) as exception:
await bidi_session.script.evaluate(
expression="throw Error('SOME_ERROR_MESSAGE')",
target=ContextTarget(top_context["context"]),
await_promise=True)

recursive_compare({
'realm': any_string,
'exceptionDetails': {
'columnNumber': any_int,
'exception': {
'handle': any_string,
'type': 'error'},
'lineNumber': any_int,
'stackTrace': any_stack_trace,
'text': any_string}},
exception.value.result)


@pytest.mark.asyncio
async def test_throw_string(bidi_session, top_context):
with pytest.raises(ScriptEvaluateResultException) as exception:
await bidi_session.script.evaluate(
expression="throw 'SOME_STRING_ERROR'",
target=ContextTarget(top_context["context"]),
await_promise=True)

recursive_compare({
'realm': any_string,
'exceptionDetails': {
'columnNumber': any_int,
'exception': {
'value': 'SOME_STRING_ERROR',
'type': 'string'},
'lineNumber': any_int,
'stackTrace': any_stack_trace,
'text': any_string}},
exception.value.result)

0 comments on commit 8815898

Please sign in to comment.