diff --git a/docs/type_conversions.md b/docs/type_conversions.md index c75a90b9d..8c6a5d8b8 100644 --- a/docs/type_conversions.md +++ b/docs/type_conversions.md @@ -85,31 +85,6 @@ to make this more complete): | `x == y` | `x == y` | | `x.typeof` | `typeof x` | -One important difference between Python objects and Javascript objects is that -if you access a missing member in Python, an exception is raised. In Javascript, -it returns `undefined`. Since we can't make any assumptions about whether the -Javascript member is missing or simply set to `undefined`, Python mirrors the -Javascript behavior. For example: - -```javascript -// Javascript -class Point { - constructor(x, y) { - this.x = x; - this.y = y; - } -} -point = new Point(42, 43)) -``` - -```python -# python -from js import point -assert point.y == 43 -del point.y -assert point.y is None -``` - ### Python from Javascript When passing a Python object to Javascript, the Javascript [Proxy diff --git a/src/tests/test_typeconversions.py b/src/tests/test_typeconversions.py index 34f0f658e..40e1a1b7d 100644 --- a/src/tests/test_typeconversions.py +++ b/src/tests/test_typeconversions.py @@ -1,5 +1,6 @@ # See also test_pyproxy, test_jsproxy, and test_python. import pytest +from selenium.common.exceptions import WebDriverException def test_python2js(selenium): @@ -240,3 +241,33 @@ def test_error_from_js(selenium): def test_error_from_python(selenium): selenium.run("err = Exception('hello there?');") assert_py_to_js_to_py(selenium, "err") + + +def test_jsproxy_attribute_error(selenium): + selenium.run_js( + """ + class Point { + constructor(x, y) { + this.x = x; + this.y = y; + } + } + window.point = new Point(42, 43) + """ + ) + selenium.run( + """ + from js import point + assert point.y == 43 + """ + ) + + msg = "AttributeError: z" + with pytest.raises(WebDriverException, match=msg): + selenium.run("point.z") + + selenium.run("del point.y") + msg = "AttributeError: y" + with pytest.raises(WebDriverException, match=msg): + selenium.run("point.y") + assert selenium.run_js("return point.y;") is None