Bug 1486793 - [wdspec] Add basic tests for "Take Screenshot" command. r=ato
authorHenrik Skupin <mail@hskupin.info>
Tue, 28 Aug 2018 19:13:59 +0200
changeset 482247 e2251ddcafd236d667b5ebb4908429bc88c99de8
parent 482246 21ee44075725031af6d66389a4e58ae0d13c2e15
child 482248 46011d6f389df1f1f41a862c73e59b1716e92e55
push id232
push userfmarier@mozilla.com
push dateWed, 05 Sep 2018 20:45:54 +0000
reviewersato
bugs1486793
milestone63.0a1
Bug 1486793 - [wdspec] Add basic tests for "Take Screenshot" command. r=ato
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/webdriver/tests/take_screenshot/__init__.py
testing/web-platform/tests/webdriver/tests/take_screenshot/screenshot.py
testing/web-platform/tests/webdriver/tests/take_screenshot/user_prompts.py
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -311074,16 +311074,21 @@
      {}
     ]
    ],
    "webdriver/tests/switch_to_window/__init__.py": [
     [
      {}
     ]
    ],
+   "webdriver/tests/take_screenshot/__init__.py": [
+    [
+     {}
+    ]
+   ],
    "webgl/META.yml": [
     [
      {}
     ]
    ],
    "webgl/common.js": [
     [
      {}
@@ -424226,16 +424231,30 @@
      {}
     ]
    ],
    "webdriver/tests/switch_to_window/switch.py": [
     [
      "/webdriver/tests/switch_to_window/switch.py",
      {}
     ]
+   ],
+   "webdriver/tests/take_screenshot/screenshot.py": [
+    [
+     "/webdriver/tests/take_screenshot/screenshot.py",
+     {}
+    ]
+   ],
+   "webdriver/tests/take_screenshot/user_prompts.py": [
+    [
+     "/webdriver/tests/take_screenshot/user_prompts.py",
+     {
+      "timeout": "long"
+     }
+    ]
    ]
   }
  },
  "paths": {
   ".codecov.yml": [
    "904cf85a4fd7576bb470172ade7317de94435dd0",
    "support"
   ],
@@ -650046,16 +650065,28 @@
   "webdriver/tests/switch_to_window/__init__.py": [
    "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391",
    "support"
   ],
   "webdriver/tests/switch_to_window/switch.py": [
    "907be66a149e8196c87760544140636d9625bbb9",
    "wdspec"
   ],
+  "webdriver/tests/take_screenshot/__init__.py": [
+   "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391",
+   "support"
+  ],
+  "webdriver/tests/take_screenshot/screenshot.py": [
+   "d3153710f7b108f167a4ff82b9ef288bcfa9440c",
+   "wdspec"
+  ],
+  "webdriver/tests/take_screenshot/user_prompts.py": [
+   "4d4840f08ba6f57f3e22bda72a0071128bea9be0",
+   "wdspec"
+  ],
   "webgl/META.yml": [
    "8e6b680d91c9b81b85e3ce010c5fb9fe338f37bf",
    "support"
   ],
   "webgl/bufferSubData.html": [
    "a97df9062d6ea964e500059e155b29604edc21b6",
    "testharness"
   ],
new file mode 100644
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webdriver/tests/take_screenshot/screenshot.py
@@ -0,0 +1,25 @@
+import base64
+import imghdr
+
+from tests.support.asserts import assert_error, assert_success
+from tests.support.inline import inline
+
+
+def take_screenshot(session):
+    return session.transport.send(
+        "GET", "session/{session_id}/screenshot".format(**vars(session)))
+
+
+def test_no_browsing_context(session, closed_window):
+    response = take_screenshot(session)
+    assert_error(response, "no such window")
+
+
+def test_screenshot(session):
+    session.url = inline("<input>")
+
+    response = take_screenshot(session)
+    value = assert_success(response)
+
+    image = base64.decodestring(value)
+    assert imghdr.what("", image) == "png"
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webdriver/tests/take_screenshot/user_prompts.py
@@ -0,0 +1,68 @@
+# META: timeout=long
+
+import base64
+import imghdr
+
+import pytest
+
+from tests.support.asserts import assert_success
+from tests.support.inline import inline
+
+
+def take_screenshot(session):
+    return session.transport.send(
+        "GET", "session/{session_id}/screenshot".format(**vars(session)))
+
+
+@pytest.fixture
+def check_user_prompt_not_closed_without_exception(session, create_dialog):
+    def check_user_prompt_not_closed_without_exception(dialog_type):
+        session.url = inline("<input/>")
+
+        create_dialog(dialog_type, text=dialog_type)
+
+        response = take_screenshot(session)
+        value = assert_success(response)
+
+        image = base64.decodestring(value)
+        assert imghdr.what("", image) == "png"
+
+        assert session.alert.text == dialog_type
+        session.alert.dismiss()
+
+    return check_user_prompt_not_closed_without_exception
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "accept"})
+@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
+def test_accept(check_user_prompt_not_closed_without_exception, dialog_type):
+    check_user_prompt_not_closed_without_exception(dialog_type)
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "accept and notify"})
+@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
+def test_accept_and_notify(check_user_prompt_not_closed_without_exception, dialog_type):
+    check_user_prompt_not_closed_without_exception(dialog_type)
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss"})
+@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
+def test_dismiss(check_user_prompt_not_closed_without_exception, dialog_type):
+    check_user_prompt_not_closed_without_exception(dialog_type)
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss and notify"})
+@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
+def test_dismiss_and_notify(check_user_prompt_not_closed_without_exception, dialog_type):
+    check_user_prompt_not_closed_without_exception(dialog_type)
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "ignore"})
+@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
+def test_ignore(check_user_prompt_not_closed_without_exception, dialog_type):
+    check_user_prompt_not_closed_without_exception(dialog_type)
+
+
+@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
+def test_default(check_user_prompt_not_closed_without_exception, dialog_type):
+    check_user_prompt_not_closed_without_exception(dialog_type)