Skip to content

Commit

Permalink
Add User Agent for Python (SeleniumHQ#5696)
Browse files Browse the repository at this point in the history
  • Loading branch information
sah authored and lmtierney committed Mar 29, 2018
1 parent 315bf4e commit 9aa6642
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 7 additions & 1 deletion py/selenium/webdriver/remote/remote_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import socket
import string
import base64
import platform

try:
import http.client as httplib
Expand All @@ -30,6 +31,7 @@
import urlparse as parse

from selenium.webdriver.common import utils as common_utils
from selenium import __version__
from .command import Command
from .errorhandler import ErrorCode
from . import utils
Expand Down Expand Up @@ -172,10 +174,14 @@ def get_remote_connection_headers(cls, parsed_url, keep_alive=False):
- keep_alive (Boolean) - Is this a keep-alive connection (default: False)
"""

system = platform.system().lower()
if system == "darwin":
system = "mac"

headers = {
'Accept': 'application/json',
'Content-Type': 'application/json;charset=UTF-8',
'User-Agent': 'Python http auth'
'User-Agent': 'selenium/{} (python {})'.format(__version__, system)
}

if parsed_url.username:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
except ImportError: # above is available in py3+, below is py2.7
import urlparse as parse

from selenium import __version__
from selenium.webdriver.remote.remote_connection import (
RemoteConnection,
)
Expand All @@ -33,7 +34,8 @@ def test_get_remote_connection_headers_defaults():
assert 'Connection' not in headers.keys()
assert headers.get('Accept') == 'application/json'
assert headers.get('Content-Type') == 'application/json;charset=UTF-8'
assert headers.get('User-Agent') == 'Python http auth'
assert headers.get('User-Agent').startswith("selenium/%s (python " % __version__)
assert headers.get('User-Agent').split(' ')[-1] in {'windows)', 'mac)', 'linux)'}


def test_get_remote_connection_headers_adds_auth_header_if_pass():
Expand Down

0 comments on commit 9aa6642

Please sign in to comment.