{"action":"created","comment":{"url":"https://api.github.com/repos/w3c/web-platform-tests/pulls/comments/115596890","pull_request_review_id":37149045,"id":115596890,"diff_hunk":"@@ -83,54 +88,88 @@ def create_window():\n         return new_windows.pop()\n     return create_window\n \n+\n def http(session):\n     return HTTPRequest(session.transport.host, session.transport.port)\n \n+\n def server_config():\n     return json.loads(os.environ.get(\"WD_SERVER_CONFIG\"))\n \n-def create_session(request):\n-    \"\"\"Provide a factory function that produces wdclient `Session` instances.\n-    If the `WD_CAPABILITIES` environment variable is set, it will be parsed as\n-    JSON and the resulting object will be included in the WebDriver \"Create\n-    Session\" command. Additional capabilities may be specified as an optional\n-    argument to this function, but the operation will fail if any values\n-    conflict with those specified via the environment. If the session is still\n-    active at the completion of the test, it will be destroyed\n-    automatically.\"\"\"\n-\n-    def create_session(test_capabilities=None):\n-        host = os.environ.get(\"WD_HOST\", default_host)\n-        port = int(os.environ.get(\"WD_PORT\", default_port))\n-        if test_capabilities is None:\n-            test_capabilities = {}\n-        env_capabilities = json.loads(os.environ.get(\"WD_CAPABILITIES\", \"{}\"))\n-\n-        capabilities = merge_dictionaries(env_capabilities, test_capabilities)\n-        session = webdriver.Session(host, port, capabilities=capabilities)\n-\n-        def destroy():\n-            if session.session_id is not None:\n-                session.end()\n-\n-        # finalisers are popped off a stack, making their ordering reverse\n-        request.addfinalizer(destroy)\n-        request.addfinalizer(lambda: _switch_to_top_level_browsing_context(session))\n-        request.addfinalizer(lambda: _restore_windows(session))\n-        request.addfinalizer(lambda: _dismiss_user_prompts(session))\n-        request.addfinalizer(lambda: _ensure_valid_window(session))\n-\n-        return session\n+\n+def configuration():\n+    host = os.environ.get(\"WD_HOST\", default_host)\n+    port = int(os.environ.get(\"WD_PORT\", default_port))\n+    capabilities = json.loads(os.environ.get(\"WD_CAPABILITIES\", \"{}\"))\n+\n+    return {\n+        \"host\": host,\n+        \"port\": port,\n+        \"capabilities\": capabilities\n+    }\n+\n+\n+_current_session = None\n+\n+\n+def session(configuration, request):\n+    \"\"\"Create and start a session for a test that does not itself test session creation.\n+\n+    By default the session will stay open after each test, but we always try to start a\n+    new one and assume that if that fails there is already a valid session. This makes it\n+    possible to recover from some errors that might leave the session in a bad state, but\n+    does not demand that we start a new session per test.\"\"\"\n+    global _current_session\n+    if _current_session is None:\n+        _current_session = webdriver.Session(configuration[\"host\"],\n+                                             configuration[\"port\"],\n+                                             capabilities=configuration[\"capabilities\"])\n+    try:\n+        _current_session.start()\n+    except webdriver.errors.SessionNotCreatedException:\n+        if not _current_session.session_id:\n+            raise\n+\n+    # finalisers are popped off a stack,\n+    # making their ordering reverse\n+    request.addfinalizer(lambda: _switch_to_top_level_browsing_context(_current_session))\n+    request.addfinalizer(lambda: _restore_windows(_current_session))\n+    request.addfinalizer(lambda: _dismiss_user_prompts(_current_session))\n+    request.addfinalizer(lambda: _ensure_valid_window(_current_session))\n+\n+    return _current_session\n+\n+\n+def new_session(configuration, request):\n+    \"\"\"Return a factory function that will attempt to start a session with a given body.\n+\n+    This is intended for tests that are themselves testing new session creation, and the\n+    session created is closed at the end of the test.\"\"\"\n+    def end():\n+        global _current_session\n+        if _current_session is not None and _current_session.session_id:\n+            _current_session.end()\n+            _current_session = None\n+\n+    def create_session(body):\n+        global _current_session\n+        _session = webdriver.Session(configuration[\"host\"],\n+                                     configuration[\"port\"],\n+                                     capabilities=None)\n+        # TODO: merge in some capabilities from the confguration capabilities\n+        # since these might be needed to start the browser\n+        value = _session.send_command(\"POST\", \"session\", body=body)","path":"webdriver/support/fixtures.py","position":146,"original_position":146,"commit_id":"4275271119514df38e92d3e46f45570bd7b66f43","original_commit_id":"72eb3edad19f94ccfc06ea9eb5f2def048796036","user":{"login":"jugglinmike","id":677252,"avatar_url":"https://avatars1.githubusercontent.com/u/677252?v=3","gravatar_id":"","url":"https://api.github.com/users/jugglinmike","html_url":"https://github.com/jugglinmike","followers_url":"https://api.github.com/users/jugglinmike/followers","following_url":"https://api.github.com/users/jugglinmike/following{/other_user}","gists_url":"https://api.github.com/users/jugglinmike/gists{/gist_id}","starred_url":"https://api.github.com/users/jugglinmike/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jugglinmike/subscriptions","organizations_url":"https://api.github.com/users/jugglinmike/orgs","repos_url":"https://api.github.com/users/jugglinmike/repos","events_url":"https://api.github.com/users/jugglinmike/events{/privacy}","received_events_url":"https://api.github.com/users/jugglinmike/received_events","type":"User","site_admin":false},"body":"It's been a while since I made that suggestion, so I'm not sure if I've had a\r\nchange of heart, or if I just understand this patch better than I did back\r\nthen. In any event, I'm happy to give this a shot and iterate when/if we feel\r\nmodifications are necessary.","created_at":"2017-05-09T20:41:30Z","updated_at":"2017-05-09T20:41:30Z","html_url":"https://github.com/w3c/web-platform-tests/pull/5506#discussion_r115596890","pull_request_url":"https://api.github.com/repos/w3c/web-platform-tests/pulls/5506","_links":{"self":{"href":"https://api.github.com/repos/w3c/web-platform-tests/pulls/comments/115596890"},"html":{"href":"https://github.com/w3c/web-platform-tests/pull/5506#discussion_r115596890"},"pull_request":{"href":"https://api.github.com/repos/w3c/web-platform-tests/pulls/5506"}}},"pull_request":{"url":"https://api.github.com/repos/w3c/web-platform-tests/pulls/5506","id":114835048,"html_url":"https://github.com/w3c/web-platform-tests/pull/5506","diff_url":"https://github.com/w3c/web-platform-tests/pull/5506.diff","patch_url":"https://github.com/w3c/web-platform-tests/pull/5506.patch","issue_url":"https://api.github.com/repos/w3c/web-platform-tests/issues/5506","number":5506,"state":"open","locked":false,"title":"Clean up fixtures for session creation in wdspec.","user":{"login":"jgraham","id":294864,"avatar_url":"https://avatars2.githubusercontent.com/u/294864?v=3","gravatar_id":"","url":"https://api.github.com/users/jgraham","html_url":"https://github.com/jgraham","followers_url":"https://api.github.com/users/jgraham/followers","following_url":"https://api.github.com/users/jgraham/following{/other_user}","gists_url":"https://api.github.com/users/jgraham/gists{/gist_id}","starred_url":"https://api.github.com/users/jgraham/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jgraham/subscriptions","organizations_url":"https://api.github.com/users/jgraham/orgs","repos_url":"https://api.github.com/users/jgraham/repos","events_url":"https://api.github.com/users/jgraham/events{/privacy}","received_events_url":"https://api.github.com/users/jgraham/received_events","type":"User","site_admin":false},"body":"This introduces two fixtures for creating a multi-test session and a\r\nlonglived session. For performance it is important that we don't\r\nordinarily create a new session for each test, but it's also important\r\nthat specific tests are able to create new sessions with arbitary\r\ncapabilities.\n\n<!-- Reviewable:start -->\n---\nThis change is [<img src=\"https://reviewable.io/review_button.svg\" height=\"34\" align=\"absmiddle\" alt=\"Reviewable\"/>](https://reviewable.io/reviews/w3c/web-platform-tests/5506)\n<!-- Reviewable:end -->\n","created_at":"2017-04-07T15:01:04Z","updated_at":"2017-05-09T20:41:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"279c22e20fc1ea048d2b424444976eb4a1d28e79","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/w3c/web-platform-tests/pulls/5506/commits","review_comments_url":"https://api.github.com/repos/w3c/web-platform-tests/pulls/5506/comments","review_comment_url":"https://api.github.com/repos/w3c/web-platform-tests/pulls/comments{/number}","comments_url":"https://api.github.com/repos/w3c/web-platform-tests/issues/5506/comments","statuses_url":"https://api.github.com/repos/w3c/web-platform-tests/statuses/4275271119514df38e92d3e46f45570bd7b66f43","head":{"label":"w3c:wdspec_new_session_fixtures","ref":"wdspec_new_session_fixtures","sha":"4275271119514df38e92d3e46f45570bd7b66f43","user":{"login":"w3c","id":379216,"avatar_url":"https://avatars1.githubusercontent.com/u/379216?v=3","gravatar_id":"","url":"https://api.github.com/users/w3c","html_url":"https://github.com/w3c","followers_url":"https://api.github.com/users/w3c/followers","following_url":"https://api.github.com/users/w3c/following{/other_user}","gists_url":"https://api.github.com/users/w3c/gists{/gist_id}","starred_url":"https://api.github.com/users/w3c/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/w3c/subscriptions","organizations_url":"https://api.github.com/users/w3c/orgs","repos_url":"https://api.github.com/users/w3c/repos","events_url":"https://api.github.com/users/w3c/events{/privacy}","received_events_url":"https://api.github.com/users/w3c/received_events","type":"Organization","site_admin":false},"repo":{"id":3618133,"name":"web-platform-tests","full_name":"w3c/web-platform-tests","owner":{"login":"w3c","id":379216,"avatar_url":"https://avatars1.githubusercontent.com/u/379216?v=3","gravatar_id":"","url":"https://api.github.com/users/w3c","html_url":"https://github.com/w3c","followers_url":"https://api.github.com/users/w3c/followers","following_url":"https://api.github.com/users/w3c/following{/other_user}","gists_url":"https://api.github.com/users/w3c/gists{/gist_id}","starred_url":"https://api.github.com/users/w3c/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/w3c/subscriptions","organizations_url":"https://api.github.com/users/w3c/orgs","repos_url":"https://api.github.com/users/w3c/repos","events_url":"https://api.github.com/users/w3c/events{/privacy}","received_events_url":"https://api.github.com/users/w3c/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/w3c/web-platform-tests","description":"Test suites for Web-platform specs — including WHATWG, W3C and others","fork":false,"url":"https://api.github.com/repos/w3c/web-platform-tests","forks_url":"https://api.github.com/repos/w3c/web-platform-tests/forks","keys_url":"https://api.github.com/repos/w3c/web-platform-tests/keys{/key_id}","collaborators_url":"https://api.github.com/repos/w3c/web-platform-tests/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/w3c/web-platform-tests/teams","hooks_url":"https://api.github.com/repos/w3c/web-platform-tests/hooks","issue_events_url":"https://api.github.com/repos/w3c/web-platform-tests/issues/events{/number}","events_url":"https://api.github.com/repos/w3c/web-platform-tests/events","assignees_url":"https://api.github.com/repos/w3c/web-platform-tests/assignees{/user}","branches_url":"https://api.github.com/repos/w3c/web-platform-tests/branches{/branch}","tags_url":"https://api.github.com/repos/w3c/web-platform-tests/tags","blobs_url":"https://api.github.com/repos/w3c/web-platform-tests/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/w3c/web-platform-tests/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/w3c/web-platform-tests/git/refs{/sha}","trees_url":"https://api.github.com/repos/w3c/web-platform-tests/git/trees{/sha}","statuses_url":"https://api.github.com/repos/w3c/web-platform-tests/statuses/{sha}","languages_url":"https://api.github.com/repos/w3c/web-platform-tests/languages","stargazers_url":"https://api.github.com/repos/w3c/web-platform-tests/stargazers","contributors_url":"https://api.github.com/repos/w3c/web-platform-tests/contributors","subscribers_url":"https://api.github.com/repos/w3c/web-platform-tests/subscribers","subscription_url":"https://api.github.com/repos/w3c/web-platform-tests/subscription","commits_url":"https://api.github.com/repos/w3c/web-platform-tests/commits{/sha}","git_commits_url":"https://api.github.com/repos/w3c/web-platform-tests/git/commits{/sha}","comments_url":"https://api.github.com/repos/w3c/web-platform-tests/comments{/number}","issue_comment_url":"https://api.github.com/repos/w3c/web-platform-tests/issues/comments{/number}","contents_url":"https://api.github.com/repos/w3c/web-platform-tests/contents/{+path}","compare_url":"https://api.github.com/repos/w3c/web-platform-tests/compare/{base}...{head}","merges_url":"https://api.github.com/repos/w3c/web-platform-tests/merges","archive_url":"https://api.github.com/repos/w3c/web-platform-tests/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/w3c/web-platform-tests/downloads","issues_url":"https://api.github.com/repos/w3c/web-platform-tests/issues{/number}","pulls_url":"https://api.github.com/repos/w3c/web-platform-tests/pulls{/number}","milestones_url":"https://api.github.com/repos/w3c/web-platform-tests/milestones{/number}","notifications_url":"https://api.github.com/repos/w3c/web-platform-tests/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/w3c/web-platform-tests/labels{/name}","releases_url":"https://api.github.com/repos/w3c/web-platform-tests/releases{/id}","deployments_url":"https://api.github.com/repos/w3c/web-platform-tests/deployments","created_at":"2012-03-04T12:58:11Z","updated_at":"2017-05-09T15:07:21Z","pushed_at":"2017-05-09T20:36:38Z","git_url":"git://github.com/w3c/web-platform-tests.git","ssh_url":"git@github.com:w3c/web-platform-tests.git","clone_url":"https://github.com/w3c/web-platform-tests.git","svn_url":"https://github.com/w3c/web-platform-tests","homepage":"http://irc.w3.org/?channels=testing","size":261714,"stargazers_count":1039,"watchers_count":1039,"language":"HTML","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":1101,"mirror_url":null,"open_issues_count":598,"forks":1101,"open_issues":598,"watchers":1039,"default_branch":"master"}},"base":{"label":"w3c:master","ref":"master","sha":"7cf23bed1c298388ebf350b5c1dd65eca92401cf","user":{"login":"w3c","id":379216,"avatar_url":"https://avatars1.githubusercontent.com/u/379216?v=3","gravatar_id":"","url":"https://api.github.com/users/w3c","html_url":"https://github.com/w3c","followers_url":"https://api.github.com/users/w3c/followers","following_url":"https://api.github.com/users/w3c/following{/other_user}","gists_url":"https://api.github.com/users/w3c/gists{/gist_id}","starred_url":"https://api.github.com/users/w3c/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/w3c/subscriptions","organizations_url":"https://api.github.com/users/w3c/orgs","repos_url":"https://api.github.com/users/w3c/repos","events_url":"https://api.github.com/users/w3c/events{/privacy}","received_events_url":"https://api.github.com/users/w3c/received_events","type":"Organization","site_admin":false},"repo":{"id":3618133,"name":"web-platform-tests","full_name":"w3c/web-platform-tests","owner":{"login":"w3c","id":379216,"avatar_url":"https://avatars1.githubusercontent.com/u/379216?v=3","gravatar_id":"","url":"https://api.github.com/users/w3c","html_url":"https://github.com/w3c","followers_url":"https://api.github.com/users/w3c/followers","following_url":"https://api.github.com/users/w3c/following{/other_user}","gists_url":"https://api.github.com/users/w3c/gists{/gist_id}","starred_url":"https://api.github.com/users/w3c/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/w3c/subscriptions","organizations_url":"https://api.github.com/users/w3c/orgs","repos_url":"https://api.github.com/users/w3c/repos","events_url":"https://api.github.com/users/w3c/events{/privacy}","received_events_url":"https://api.github.com/users/w3c/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/w3c/web-platform-tests","description":"Test suites for Web-platform specs — including WHATWG, W3C and others","fork":false,"url":"https://api.github.com/repos/w3c/web-platform-tests","forks_url":"https://api.github.com/repos/w3c/web-platform-tests/forks","keys_url":"https://api.github.com/repos/w3c/web-platform-tests/keys{/key_id}","collaborators_url":"https://api.github.com/repos/w3c/web-platform-tests/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/w3c/web-platform-tests/teams","hooks_url":"https://api.github.com/repos/w3c/web-platform-tests/hooks","issue_events_url":"https://api.github.com/repos/w3c/web-platform-tests/issues/events{/number}","events_url":"https://api.github.com/repos/w3c/web-platform-tests/events","assignees_url":"https://api.github.com/repos/w3c/web-platform-tests/assignees{/user}","branches_url":"https://api.github.com/repos/w3c/web-platform-tests/branches{/branch}","tags_url":"https://api.github.com/repos/w3c/web-platform-tests/tags","blobs_url":"https://api.github.com/repos/w3c/web-platform-tests/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/w3c/web-platform-tests/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/w3c/web-platform-tests/git/refs{/sha}","trees_url":"https://api.github.com/repos/w3c/web-platform-tests/git/trees{/sha}","statuses_url":"https://api.github.com/repos/w3c/web-platform-tests/statuses/{sha}","languages_url":"https://api.github.com/repos/w3c/web-platform-tests/languages","stargazers_url":"https://api.github.com/repos/w3c/web-platform-tests/stargazers","contributors_url":"https://api.github.com/repos/w3c/web-platform-tests/contributors","subscribers_url":"https://api.github.com/repos/w3c/web-platform-tests/subscribers","subscription_url":"https://api.github.com/repos/w3c/web-platform-tests/subscription","commits_url":"https://api.github.com/repos/w3c/web-platform-tests/commits{/sha}","git_commits_url":"https://api.github.com/repos/w3c/web-platform-tests/git/commits{/sha}","comments_url":"https://api.github.com/repos/w3c/web-platform-tests/comments{/number}","issue_comment_url":"https://api.github.com/repos/w3c/web-platform-tests/issues/comments{/number}","contents_url":"https://api.github.com/repos/w3c/web-platform-tests/contents/{+path}","compare_url":"https://api.github.com/repos/w3c/web-platform-tests/compare/{base}...{head}","merges_url":"https://api.github.com/repos/w3c/web-platform-tests/merges","archive_url":"https://api.github.com/repos/w3c/web-platform-tests/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/w3c/web-platform-tests/downloads","issues_url":"https://api.github.com/repos/w3c/web-platform-tests/issues{/number}","pulls_url":"https://api.github.com/repos/w3c/web-platform-tests/pulls{/number}","milestones_url":"https://api.github.com/repos/w3c/web-platform-tests/milestones{/number}","notifications_url":"https://api.github.com/repos/w3c/web-platform-tests/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/w3c/web-platform-tests/labels{/name}","releases_url":"https://api.github.com/repos/w3c/web-platform-tests/releases{/id}","deployments_url":"https://api.github.com/repos/w3c/web-platform-tests/deployments","created_at":"2012-03-04T12:58:11Z","updated_at":"2017-05-09T15:07:21Z","pushed_at":"2017-05-09T20:36:38Z","git_url":"git://github.com/w3c/web-platform-tests.git","ssh_url":"git@github.com:w3c/web-platform-tests.git","clone_url":"https://github.com/w3c/web-platform-tests.git","svn_url":"https://github.com/w3c/web-platform-tests","homepage":"http://irc.w3.org/?channels=testing","size":261714,"stargazers_count":1039,"watchers_count":1039,"language":"HTML","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":1101,"mirror_url":null,"open_issues_count":598,"forks":1101,"open_issues":598,"watchers":1039,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/w3c/web-platform-tests/pulls/5506"},"html":{"href":"https://github.com/w3c/web-platform-tests/pull/5506"},"issue":{"href":"https://api.github.com/repos/w3c/web-platform-tests/issues/5506"},"comments":{"href":"https://api.github.com/repos/w3c/web-platform-tests/issues/5506/comments"},"review_comments":{"href":"https://api.github.com/repos/w3c/web-platform-tests/pulls/5506/comments"},"review_comment":{"href":"https://api.github.com/repos/w3c/web-platform-tests/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/w3c/web-platform-tests/pulls/5506/commits"},"statuses":{"href":"https://api.github.com/repos/w3c/web-platform-tests/statuses/4275271119514df38e92d3e46f45570bd7b66f43"}}}}
{"actor":{"display_login":"jugglinmike"}}