blob: e8a2cef7ac6f8cb8826cdd8760430ca6a597e53d [file] [log] [blame]
#!/usr/bin/env python
# Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""End to end tests for ChromeDriver."""
# Note that to run Android tests you must have the following line in
# .gclient (in the parent directory of src): target_os = [ 'android' ]
# to get the appropriate adb version for ChromeDriver.
# TODO (crbug.com/857239): Remove above comment when adb version
# is updated in Devil.
from __future__ import print_function
from __future__ import absolute_import
import base64
import json
import math
import optparse
import os
import re
import shutil
import socket
import subprocess
import sys
import tempfile
import threading
import time
import unittest
import six.moves.urllib.request, six.moves.urllib.parse, six.moves.urllib.error
import six.moves.urllib.request, six.moves.urllib.error, six.moves.urllib.parse
import uuid
import imghdr
import struct
from six.moves import map
from six.moves import range
from six.moves import zip
_THIS_DIR = os.path.abspath(os.path.dirname(__file__))
_PARENT_DIR = os.path.join(_THIS_DIR, os.pardir)
_CLIENT_DIR = os.path.join(_PARENT_DIR, "client")
_SERVER_DIR = os.path.join(_PARENT_DIR, "server")
_TEST_DIR = os.path.join(_PARENT_DIR, "test")
sys.path.insert(1, _PARENT_DIR)
import chrome_paths
import util
sys.path.remove(_PARENT_DIR)
sys.path.insert(1, _CLIENT_DIR)
import chromedriver
import websocket_connection
import webelement
sys.path.remove(_CLIENT_DIR)
sys.path.insert(1, _SERVER_DIR)
import server
sys.path.remove(_SERVER_DIR)
sys.path.insert(1, _TEST_DIR)
import unittest_util
import webserver
sys.path.remove(_TEST_DIR)
sys.path.insert(0,os.path.join(chrome_paths.GetSrc(), 'third_party',
'catapult', 'third_party', 'gsutil',
'third_party', 'monotonic'))
from monotonic import monotonic
_TEST_DATA_DIR = os.path.join(chrome_paths.GetTestData(), 'chromedriver')
if util.IsLinux():
sys.path.insert(0, os.path.join(chrome_paths.GetSrc(), 'third_party',
'catapult', 'devil'))
from devil.android import device_utils
from devil.android import forwarder
sys.path.insert(0, os.path.join(chrome_paths.GetSrc(), 'build', 'android'))
import devil_chromium
from pylib import constants
_NEGATIVE_FILTER = [
# This test is too flaky on the bots, but seems to run perfectly fine
# on developer workstations.
'ChromeDriverTest.testEmulateNetworkConditionsNameSpeed',
'ChromeDriverTest.testEmulateNetworkConditionsSpeed',
# https://bugs.chromium.org/p/chromedriver/issues/detail?id=833
'ChromeDriverTest.testAlertOnNewWindow',
# https://bugs.chromium.org/p/chromedriver/issues/detail?id=2532
'ChromeDriverPageLoadTimeoutTest.testRefreshWithPageLoadTimeout',
# https://bugs.chromium.org/p/chromedriver/issues/detail?id=3517
'ChromeDriverTest.testPrint',
'ChromeDriverTest.testPrintInvalidArgument',
]
_OS_SPECIFIC_FILTER = {}
_OS_SPECIFIC_FILTER['win'] = [
# https://bugs.chromium.org/p/chromedriver/issues/detail?id=299
'ChromeLogPathCapabilityTest.testChromeLogPath',
# https://bugs.chromium.org/p/chromium/issues/detail?id=1196363
'ChromeDownloadDirTest.testFileDownloadAfterTabHeadless',
'ChromeDownloadDirTest.testFileDownloadWithClickHeadless',
'ChromeDownloadDirTest.testFileDownloadWithGetHeadless',
'HeadlessChromeDriverTest.testNewTabDoesNotFocus',
'HeadlessChromeDriverTest.testNewWindowDoesNotFocus',
'HeadlessChromeDriverTest.testPrintHeadless',
'HeadlessChromeDriverTest.testPrintInvalidArgumentHeadless',
'HeadlessChromeDriverTest.testWindowFullScreen',
'HeadlessInvalidCertificateTest.testLoadsPage',
'HeadlessInvalidCertificateTest.testNavigateNewWindow',
'RemoteBrowserTest.testConnectToRemoteBrowserLiteralAddressHeadless',
]
_OS_SPECIFIC_FILTER['linux'] = [
]
_OS_SPECIFIC_FILTER['mac'] = [
# https://bugs.chromium.org/p/chromedriver/issues/detail?id=1927
# https://crbug.com/1036636
'MobileEmulationCapabilityTest.testTapElement',
# https://bugs.chromium.org/p/chromium/issues/detail?id=1011225
'ChromeDriverTest.testActionsMultiTouchPoint',
# Flaky: https://crbug.com/1156576.
'ChromeDriverTestLegacy.testContextMenuEventFired',
# Flaky: https://crbug.com/1157533.
'ChromeDriverTest.testShadowDomFindElement',
]
_DESKTOP_NEGATIVE_FILTER = [
# Desktop doesn't support touch (without --touch-events).
'ChromeDriverTestLegacy.testTouchSingleTapElement',
'ChromeDriverTest.testTouchDownMoveUpElement',
'ChromeDriverTestLegacy.testTouchScrollElement',
'ChromeDriverTestLegacy.testTouchDoubleTapElement',
'ChromeDriverTestLegacy.testTouchLongPressElement',
'ChromeDriverTest.testTouchFlickElement',
'ChromeDriverAndroidTest.*',
]
_INTEGRATION_NEGATIVE_FILTER = [
# The following test is flaky on Windows and Mac.
'ChromeDownloadDirTest.testDownloadDirectoryOverridesExistingPreferences',
# ChromeDriverLogTest tests an internal ChromeDriver feature, not needed
# for integration test.
'ChromeDriverLogTest.*',
# ChromeDriverPageLoadTimeoutTest is flaky, particularly on Mac.
'ChromeDriverPageLoadTimeoutTest.*',
# Some trivial test cases that provide no additional value beyond what are
# already tested by other test cases.
'ChromeDriverTest.testGetCurrentWindowHandle',
'ChromeDriverTest.testStartStop',
# PerfTest takes a long time, requires extra setup, and adds little value
# to integration testing.
'PerfTest.*',
# Flaky: https://crbug.com/899919
'SessionHandlingTest.testGetSessions',
# Flaky due to occasional timeout in starting Chrome
'ZChromeStartRetryCountTest.testChromeStartRetryCount',
]
def _GetDesktopNegativeFilter():
filter = _NEGATIVE_FILTER + _DESKTOP_NEGATIVE_FILTER
os = util.GetPlatformName()
if os in _OS_SPECIFIC_FILTER:
filter += _OS_SPECIFIC_FILTER[os]
return filter
_ANDROID_NEGATIVE_FILTER = {}
_ANDROID_NEGATIVE_FILTER['chrome'] = (
_NEGATIVE_FILTER + [
# Android doesn't support switches and extensions.
'ChromeSwitchesCapabilityTest.*',
'ChromeExtensionsCapabilityTest.*',
'MobileEmulationCapabilityTest.*',
'ChromeDownloadDirTest.*',
# https://crbug.com/274650
'ChromeDriverTest.testCloseWindow',
# Most window operations don't make sense on Android.
'ChromeDriverTest.testWindowFullScreen',
'ChromeDriverTest.testWindowPosition',
'ChromeDriverTest.testWindowSize',
'ChromeDriverTest.testWindowRect',
'ChromeDriverTest.testWindowMaximize',
'ChromeDriverTest.testWindowMinimize',
'ChromeLogPathCapabilityTest.testChromeLogPath',
# Connecting to running browser is not supported on Android.
'RemoteBrowserTest.*',
# Don't enable perf testing on Android yet.
'PerfTest.*',
# Android doesn't support multiple sessions on one device.
'SessionHandlingTest.testGetSessions',
# Android doesn't use the chrome://print dialog.
'ChromeDriverTest.testCanSwitchToPrintPreviewDialog',
# Chrome 44+ for Android doesn't dispatch the dblclick event
'ChromeDriverTest.testMouseDoubleClick',
# Page cannot be loaded from file:// URI in Android unless it
# is stored in device.
'ChromeDriverTest.testCanClickAlertInIframes',
# https://bugs.chromium.org/p/chromedriver/issues/detail?id=2081
'ChromeDriverTest.testCloseWindowUsingJavascript',
# Android doesn't support headless mode
'HeadlessInvalidCertificateTest.*',
'HeadlessChromeDriverTest.*',
# Tests of the desktop Chrome launch process.
'LaunchDesktopTest.*',
# https://bugs.chromium.org/p/chromedriver/issues/detail?id=2737
'ChromeDriverTest.testTakeElementScreenshot',
'ChromeDriverTest.testTakeElementScreenshotPartlyVisible',
'ChromeDriverTest.testTakeElementScreenshotInIframe',
# setWindowBounds not supported on Android
'ChromeDriverTest.testTakeLargeElementScreenshot',
# https://bugs.chromium.org/p/chromedriver/issues/detail?id=2786
'ChromeDriverTest.testActionsTouchTap',
'ChromeDriverTest.testTouchDownMoveUpElement',
'ChromeDriverTest.testTouchFlickElement',
# Android has no concept of tab or window, and will always lose focus
# on tab creation. https://crbug.com/chromedriver/3018
'ChromeDriverTest.testNewWindowDoesNotFocus',
'ChromeDriverTest.testNewTabDoesNotFocus',
# Android does not support the virtual authenticator environment.
'ChromeDriverSecureContextTest.*',
# Covered by Desktop tests; can't create 2 browsers in Android
'SupportIPv4AndIPv6.testSupportIPv4AndIPv6',
# Browser context management is not supported by Android
'ChromeDriverTest.testClipboardPermissions',
'ChromeDriverTest.testMidiPermissions',
'ChromeDriverTest.testMultiplePermissions',
'ChromeDriverTest.testNewWindowSameDomainHasSamePermissions',
'ChromeDriverTest.testPermissionStates',
'ChromeDriverTest.testPermissionsOpaqueOriginsThrowError',
'ChromeDriverTest.testPermissionsSameOrigin',
'ChromeDriverTest.testPermissionsSameOriginDoesNotAffectOthers',
'ChromeDriverTest.testPersistentStoragePermissions',
'ChromeDriverTest.testPushAndNotificationsPermissions',
'ChromeDriverTest.testSensorPermissions',
'ChromeDriverTest.testSettingPermissionDoesNotAffectOthers',
# Android does not allow changing window size
'JavaScriptTests.*',
# These tests are failing on Android
# https://bugs.chromium.org/p/chromedriver/issues/detail?id=3560
'ChromeDriverTest.testTakeLargeElementViewportScreenshot',
'ChromeDriverTest.testTakeLargeElementFullPageScreenshot'
]
)
_ANDROID_NEGATIVE_FILTER['chrome_stable'] = (
_ANDROID_NEGATIVE_FILTER['chrome'] + [
# https://bugs.chromium.org/p/chromedriver/issues/detail?id=2350
'ChromeDriverTest.testSlowIFrame',
# https://bugs.chromium.org/p/chromedriver/issues/detail?id=2503
'ChromeDriverTest.testGetLogOnClosedWindow',
'ChromeDriverTest.testGetWindowHandles',
'ChromeDriverTest.testShouldHandleNewWindowLoadingProperly',
'ChromeDriverTest.testSwitchToWindow',
# Feature not yet supported in this version
'ChromeDriverTest.testGenerateTestReport',
]
)
_ANDROID_NEGATIVE_FILTER['chrome_beta'] = (
_ANDROID_NEGATIVE_FILTER['chrome'] + [
# https://bugs.chromium.org/p/chromedriver/issues/detail?id=2503
'ChromeDriverTest.testGetLogOnClosedWindow',
'ChromeDriverTest.testGetWindowHandles',
'ChromeDriverTest.testShouldHandleNewWindowLoadingProperly',
'ChromeDriverTest.testSwitchToWindow',
# Feature not yet supported in this version
'ChromeDriverTest.testGenerateTestReport',
]
)
_ANDROID_NEGATIVE_FILTER['chromium'] = (
_ANDROID_NEGATIVE_FILTER['chrome'] + []
)
_ANDROID_NEGATIVE_FILTER['chromedriver_webview_shell'] = (
_ANDROID_NEGATIVE_FILTER['chrome_stable'] + [
# WebView doesn't support emulating network conditions.
'ChromeDriverTest.testEmulateNetworkConditions',
'ChromeDriverTest.testEmulateNetworkConditionsNameSpeed',
'ChromeDriverTest.testEmulateNetworkConditionsOffline',
'ChromeDriverTest.testEmulateNetworkConditionsSpeed',
'ChromeDriverTest.testEmulateNetworkConditionsName',
# WebView shell doesn't support popups or popup blocking.
'ChromeDriverTest.testPopups',
'ChromeDriverTest.testDontGoBackOrGoForward',
# ChromeDriver WebView shell doesn't support multiple tabs.
'ChromeDriverTest.testCloseWindowUsingJavascript',
'ChromeDriverTest.testGetWindowHandles',
'ChromeDriverTest.testSwitchToWindow',
'ChromeDriverTest.testShouldHandleNewWindowLoadingProperly',
'ChromeDriverTest.testGetLogOnClosedWindow',
# The WebView shell that we test against (on KitKat) does not perform
# cross-process navigations.
# TODO(samuong): reenable when it does.
'ChromeDriverPageLoadTimeoutTest.testPageLoadTimeoutCrossDomain',
'ChromeDriverPageLoadTimeoutTest.'
'testHistoryNavigationWithPageLoadTimeout',
# Webview shell doesn't support Alerts.
'ChromeDriverTest.testAlert',
'ChromeDriverTest.testAlertOnNewWindow',
'ChromeDesiredCapabilityTest.testUnexpectedAlertBehaviour',
'ChromeDriverTest.testAlertHandlingOnPageUnload',
'ChromeDriverTest.testClickElementAfterNavigation',
'ChromeDriverTest.testGetLogOnWindowWithAlert',
'ChromeDriverTest.testSendTextToAlert',
'ChromeDriverTest.testUnexpectedAlertOpenExceptionMessage',
# https://bugs.chromium.org/p/chromedriver/issues/detail?id=2332
'ChromeDriverTestLegacy.testTouchScrollElement',
]
)
class ChromeDriverBaseTest(unittest.TestCase):
"""Base class for testing chromedriver functionalities."""
def __init__(self, *args, **kwargs):
super(ChromeDriverBaseTest, self).__init__(*args, **kwargs)
self._drivers = []
def tearDown(self):
for driver in self._drivers:
try:
driver.Quit()
except:
pass
def CreateDriver(self, server_url=None, server_pid=None,
download_dir=None, **kwargs):
if server_url is None:
server_url = _CHROMEDRIVER_SERVER_URL
if server_pid is None:
server_pid = _CHROMEDRIVER_SERVER_PID
if (not _ANDROID_PACKAGE_KEY and 'debugger_address' not in kwargs and
'_MINIDUMP_PATH' in globals() and _MINIDUMP_PATH):
# Environment required for minidump not supported on Android
# minidumpPath will fail parsing if debugger_address is set
if 'experimental_options' in kwargs:
if 'minidumpPath' not in kwargs['experimental_options']:
kwargs['experimental_options']['minidumpPath'] = _MINIDUMP_PATH
else:
kwargs['experimental_options'] = {'minidumpPath': _MINIDUMP_PATH}
android_package = None
android_activity = None
android_process = None
if _ANDROID_PACKAGE_KEY:
android_package = constants.PACKAGE_INFO[_ANDROID_PACKAGE_KEY].package
if _ANDROID_PACKAGE_KEY == 'chromedriver_webview_shell':
android_activity = constants.PACKAGE_INFO[_ANDROID_PACKAGE_KEY].activity
android_process = '%s:main' % android_package
driver = chromedriver.ChromeDriver(server_url, server_pid,
chrome_binary=_CHROME_BINARY,
android_package=android_package,
android_activity=android_activity,
android_process=android_process,
download_dir=download_dir,
test_name=self.id(),
**kwargs)
self._drivers += [driver]
return driver
def WaitForNewWindow(self, driver, old_handles, check_closed_windows=True):
"""Wait for at least one new window to show up in 20 seconds.
Args:
old_handles: Handles to all old windows before the new window is added.
check_closed_windows: If True, assert that no windows are closed before
the new window is added.
Returns:
Handle to a new window. None if timeout.
"""
deadline = monotonic() + 20
while monotonic() < deadline:
handles = driver.GetWindowHandles()
if check_closed_windows:
self.assertTrue(set(old_handles).issubset(handles))
new_handles = set(handles).difference(set(old_handles))
if len(new_handles) > 0:
return new_handles.pop()
time.sleep(0.01)
return None
def WaitForCondition(self, predicate, timeout=5, timestep=0.1):
"""Wait for a condition to become true.
Args:
predicate: A function that returns a boolean value.
"""
deadline = monotonic() + timeout
while monotonic() < deadline:
if predicate():
return True
time.sleep(timestep)
return False
class ChromeDriverBaseTestWithWebServer(ChromeDriverBaseTest):
@staticmethod
def GlobalSetUp():
ChromeDriverBaseTestWithWebServer._http_server = webserver.WebServer(
chrome_paths.GetTestData())
ChromeDriverBaseTestWithWebServer._sync_server = webserver.SyncWebServer()
cert_path = os.path.join(chrome_paths.GetTestData(),
'chromedriver/invalid_ssl_cert.pem')
ChromeDriverBaseTestWithWebServer._https_server = webserver.WebServer(
chrome_paths.GetTestData(), cert_path)
def respondWithUserAgentString(request):
return {}, """
<html>
<body>%s</body>
</html>""" % request.GetHeader('User-Agent')
def respondWithUserAgentStringUseDeviceWidth(request):
return {}, """
<html>
<head>
<meta name="viewport" content="width=device-width,minimum-scale=1.0">
</head>
<body>%s</body>
</html>""" % request.GetHeader('User-Agent')
ChromeDriverBaseTestWithWebServer._http_server.SetCallbackForPath(
'/userAgent', respondWithUserAgentString)
ChromeDriverBaseTestWithWebServer._http_server.SetCallbackForPath(
'/userAgentUseDeviceWidth', respondWithUserAgentStringUseDeviceWidth)
if _ANDROID_PACKAGE_KEY:
ChromeDriverBaseTestWithWebServer._device = (
device_utils.DeviceUtils.HealthyDevices()[0])
http_host_port = (
ChromeDriverBaseTestWithWebServer._http_server._server.server_port)
sync_host_port = (
ChromeDriverBaseTestWithWebServer._sync_server._server.server_port)
https_host_port = (
ChromeDriverBaseTestWithWebServer._https_server._server.server_port)
forwarder.Forwarder.Map(
[(http_host_port, http_host_port), (sync_host_port, sync_host_port),
(https_host_port, https_host_port)],
ChromeDriverBaseTestWithWebServer._device)
@staticmethod
def GlobalTearDown():
if _ANDROID_PACKAGE_KEY:
forwarder.Forwarder.UnmapAllDevicePorts(ChromeDriverTest._device)
ChromeDriverBaseTestWithWebServer._http_server.Shutdown()
ChromeDriverBaseTestWithWebServer._https_server.Shutdown()
@staticmethod
def GetHttpUrlForFile(file_path):
return ChromeDriverBaseTestWithWebServer._http_server.GetUrl() + file_path
class ChromeDriverTestWithCustomCapability(ChromeDriverBaseTestWithWebServer):
def testEagerMode(self):
send_response = threading.Event()
def waitAndRespond():
send_response.wait(10)
self._sync_server.RespondWithContent('#')
thread = threading.Thread(target=waitAndRespond)
self._http_server.SetDataForPath('/top.html',
"""
<html><body>
<div id='top'>
<img src='%s'>
</div>
</body></html>""" % self._sync_server.GetUrl())
eager_driver = self.CreateDriver(page_load_strategy='eager')
thread.start()
start_eager = monotonic()
eager_driver.Load(self._http_server.GetUrl() + '/top.html')
stop_eager = monotonic()
send_response.set()
eager_time = stop_eager - start_eager
self.assertTrue(eager_time < 9)
thread.join()
def testDoesntWaitWhenPageLoadStrategyIsNone(self):
class HandleRequest(object):
def __init__(self):
self.sent_hello = threading.Event()
def slowPage(self, request):
self.sent_hello.wait(2)
return {}, """
<html>
<body>hello</body>
</html>"""
handler = HandleRequest()
self._http_server.SetCallbackForPath('/slow', handler.slowPage)
driver = self.CreateDriver(page_load_strategy='none')
self.assertEquals('none', driver.capabilities['pageLoadStrategy'])
driver.Load(self._http_server.GetUrl() + '/chromedriver/empty.html')
start = monotonic()
driver.Load(self._http_server.GetUrl() + '/slow')
self.assertTrue(monotonic() - start < 2)
handler.sent_hello.set()
self.WaitForCondition(lambda: 'hello' in driver.GetPageSource())
self.assertTrue('hello' in driver.GetPageSource())
def testUnsupportedPageLoadStrategyRaisesException(self):
self.assertRaises(chromedriver.InvalidArgument,
self.CreateDriver, page_load_strategy="unsupported")
def testGetUrlOnInvalidUrl(self):
# Make sure we don't return 'chrome-error://chromewebdata/' (see
# https://bugs.chromium.org/p/chromedriver/issues/detail?id=1272).
# Block DNS resolution for all hosts so that the navigation results
# in a DNS lookup error.
driver = self.CreateDriver(
chrome_switches=['--host-resolver-rules=MAP * ~NOTFOUND'])
self.assertRaises(chromedriver.ChromeDriverException,
driver.Load, 'http://invalid/')
self.assertEquals('http://invalid/', driver.GetCurrentUrl())
class ChromeDriverWebSocketTest(ChromeDriverBaseTestWithWebServer):
@staticmethod
def composeWebSocketUrl(server_url, session_id):
return server_url.replace('http', 'ws') + '/session/' + session_id
def testDefaultSession(self):
driver = self.CreateDriver()
self.assertFalse('webSocketUrl' in driver.capabilities)
self.assertRaises(Exception, websocket_connection.WebSocketConnection,
_CHROMEDRIVER_SERVER_URL, driver.GetSessionId())
def testWebSocketUrlFalse(self):
driver = self.CreateDriver(web_socket_url=False)
self.assertFalse('webSocketUrl' in driver.capabilities)
self.assertRaises(Exception, websocket_connection.WebSocketConnection,
_CHROMEDRIVER_SERVER_URL, driver.GetSessionId())
def testWebSocketUrlTrue(self):
driver = self.CreateDriver(web_socket_url=True)
self.assertTrue('webSocketUrl' in driver.capabilities)
self.assertNotEqual(None, driver.GetSessionId())
self.assertEquals(driver.capabilities['webSocketUrl'],
self.composeWebSocketUrl(_CHROMEDRIVER_SERVER_URL,
driver.GetSessionId()))
websocket = websocket_connection.WebSocketConnection(
_CHROMEDRIVER_SERVER_URL, driver.GetSessionId())
self.assertNotEqual(None, websocket)
def testWebSocketUrlInvalid(self):
self.assertRaises(chromedriver.InvalidArgument,
self.CreateDriver, web_socket_url='Invalid')
def testWebSocketOneConnectionPerSession(self):
driver = self.CreateDriver(web_socket_url=True)
websocket = websocket_connection.WebSocketConnection(
_CHROMEDRIVER_SERVER_URL, driver.GetSessionId())
self.assertNotEqual(None, websocket)
self.assertRaises(Exception, websocket_connection.WebSocketConnection,
_CHROMEDRIVER_SERVER_URL, driver.GetSessionId())
def testWebSocketInvalidSessionId(self):
driver = self.CreateDriver(web_socket_url=True)
self.assertRaises(Exception, websocket_connection.WebSocketConnection,
_CHROMEDRIVER_SERVER_URL, "random_session_id_123")
def testWebSocketClosedCanReconnect(self):
driver = self.CreateDriver(web_socket_url=True)
websocket = websocket_connection.WebSocketConnection(
_CHROMEDRIVER_SERVER_URL, driver.GetSessionId())
self.assertNotEqual(None, websocket)
websocket.Close()
websocket2 = websocket_connection.WebSocketConnection(
_CHROMEDRIVER_SERVER_URL, driver.GetSessionId())
self.assertNotEqual(None, websocket2)
class ChromeDriverTest(ChromeDriverBaseTestWithWebServer):
"""End to end tests for ChromeDriver."""
def setUp(self):
self._driver = self.CreateDriver()
def testStartStop(self):
pass
def testGetComputedAttributes(self):
self._driver.Load(
self.GetHttpUrlForFile('/chromedriver/accessibility.html'))
firstHeaderElement = self._driver.FindElement(
'css selector', '#first-header')
self.assertEquals(firstHeaderElement.GetComputedLabel(), 'header content')
self.assertEquals(firstHeaderElement.GetComputedRole(), 'heading')
def testGetComputedAttributesForIgnoredNode(self):
self._driver.Load(
self.GetHttpUrlForFile('/chromedriver/accessibility.html'))
ignoredHeaderElement = self._driver.FindElement(
'css selector', '#ignored-header')
# GetComputedLabel for ignored node should return empty string.
self.assertEquals(ignoredHeaderElement.GetComputedLabel(), '')
self.assertEquals(ignoredHeaderElement.GetComputedRole(), 'none')
def testGetComputedAttributesForUnrenderedNode(self):
self._driver.Load(
self.GetHttpUrlForFile('/chromedriver/accessibility.html'))
unrenderedHeaderElement = self._driver.FindElement(
'css selector', '#unrendered-header')
# GetComputedLabel for unrendered node should return empty string.
self.assertEquals(unrenderedHeaderElement.GetComputedLabel(), '')
self.assertEquals(unrenderedHeaderElement.GetComputedRole(), 'none')
def testLoadUrl(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html'))
def testGetCurrentWindowHandle(self):
self._driver.GetCurrentWindowHandle()
# crbug.com/p/chromedriver/issues/detail?id=2995 exposed that some libraries
# introduce circular function references. Functions should not be serialized
# or treated as an object - this test checks that circular function
# definitions are allowed (despite how they are not spec-compliant.
def testExecuteScriptWithSameFunctionReference(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html'))
self._driver.ExecuteScript("""function copyMe() { return 1; }
Function.prototype.foo = copyMe;
const obj = {};
obj['buzz'] = copyMe;
return obj;""")
def _newWindowDoesNotFocus(self, window_type='window'):
current_handles = self._driver.GetWindowHandles()
self._driver.Load(self.GetHttpUrlForFile(
'/chromedriver/focus_blur_test.html'))
new_window = self._driver.NewWindow(window_type=window_type)
text = self._driver.FindElement('css selector', '#result').GetText()
self.assertTrue(new_window['handle'] not in current_handles)
self.assertTrue(new_window['handle'] in self._driver.GetWindowHandles())
self.assertEquals(text, 'PASS')
def testNewWindowDoesNotFocus(self):
self._newWindowDoesNotFocus(window_type='window')
def testNewTabDoesNotFocus(self):
self._newWindowDoesNotFocus(window_type='tab')
def testCloseWindow(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/page_test.html'))
old_handles = self._driver.GetWindowHandles()
self._driver.FindElement('css selector', '#link').Click()
new_window_handle = self.WaitForNewWindow(self._driver, old_handles)
self.assertNotEqual(None, new_window_handle)
self._driver.SwitchToWindow(new_window_handle)
self.assertEquals(new_window_handle, self._driver.GetCurrentWindowHandle())
self.assertRaises(chromedriver.NoSuchElement,
self._driver.FindElement, 'css selector', '#link')
close_returned_handles = self._driver.CloseWindow()
self.assertRaises(chromedriver.NoSuchWindow,
self._driver.GetCurrentWindowHandle)
new_handles = self._driver.GetWindowHandles()
self.assertEquals(close_returned_handles, new_handles)
for old_handle in old_handles:
self.assertTrue(old_handle in new_handles)
for handle in new_handles:
self._driver.SwitchToWindow(handle)
self.assertEquals(handle, self._driver.GetCurrentWindowHandle())
close_handles = self._driver.CloseWindow()
# CloseWindow quits the session if on the last window.
if handle is not new_handles[-1]:
from_get_window_handles = self._driver.GetWindowHandles()
self.assertEquals(close_handles, from_get_window_handles)
def testCloseWindowUsingJavascript(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/page_test.html'))
old_handles = self._driver.GetWindowHandles()
self._driver.FindElement('css selector', '#link').Click()
new_window_handle = self.WaitForNewWindow(self._driver, old_handles)
self.assertNotEqual(None, new_window_handle)
self._driver.SwitchToWindow(new_window_handle)
self.assertEquals(new_window_handle, self._driver.GetCurrentWindowHandle())
self.assertRaises(chromedriver.NoSuchElement,
self._driver.FindElement, 'css selector', '#link')
self._driver.ExecuteScript('window.close()')
with self.assertRaises(chromedriver.NoSuchWindow):
self._driver.GetTitle()
def testGetWindowHandles(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/page_test.html'))
old_handles = self._driver.GetWindowHandles()
self._driver.FindElement('css selector', '#link').Click()
self.assertNotEqual(None, self.WaitForNewWindow(self._driver, old_handles))
def testGetWindowHandlesInPresenceOfSharedWorker(self):
self._driver.Load(
self.GetHttpUrlForFile('/chromedriver/shared_worker.html'))
old_handles = self._driver.GetWindowHandles()
def testSwitchToWindow(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/page_test.html'))
self.assertEquals(
1, self._driver.ExecuteScript('window.name = "oldWindow"; return 1;'))
window1_handle = self._driver.GetCurrentWindowHandle()
old_handles = self._driver.GetWindowHandles()
self._driver.FindElement('css selector', '#link').Click()
new_window_handle = self.WaitForNewWindow(self._driver, old_handles)
self.assertNotEqual(None, new_window_handle)
self._driver.SwitchToWindow(new_window_handle)
self.assertEquals(new_window_handle, self._driver.GetCurrentWindowHandle())
self.assertRaises(chromedriver.NoSuchElement,
self._driver.FindElement, 'css selector', '#link')
self._driver.SwitchToWindow('oldWindow')
self.assertEquals(window1_handle, self._driver.GetCurrentWindowHandle())
def testEvaluateScript(self):
self.assertEquals(1, self._driver.ExecuteScript('return 1'))
self.assertEquals(None, self._driver.ExecuteScript(''))
def testEvaluateScriptWithArgs(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html'))
script = ('document.body.innerHTML = "<div>b</div><div>c</div>";'
'return {stuff: document.querySelectorAll("div")};')
stuff = self._driver.ExecuteScript(script)['stuff']
script = 'return arguments[0].innerHTML + arguments[1].innerHTML'
self.assertEquals(
'bc', self._driver.ExecuteScript(script, stuff[0], stuff[1]))
def testEvaluateInvalidScript(self):
self.assertRaises(chromedriver.ChromeDriverException,
self._driver.ExecuteScript, '{{{')
def testExecuteAsyncScript(self):
self._driver.SetTimeouts({'script': 3000})
self.assertRaises(
chromedriver.ScriptTimeout,
self._driver.ExecuteAsyncScript,
'var callback = arguments[0];'
'setTimeout(function(){callback(1);}, 10000);')
self.assertEquals(
2,
self._driver.ExecuteAsyncScript(
'var callback = arguments[0];'
'setTimeout(function(){callback(2);}, 300);'))
def testExecuteScriptTimeout(self):
self._driver.SetTimeouts({'script': 0})
self.assertRaises(
chromedriver.ScriptTimeout,
self._driver.ExecuteScript,
'return 2')
# Regular script can still run afterwards.
self._driver.SetTimeouts({'script': 1000})
self.assertEquals(
4,
self._driver.ExecuteScript('return 4'))
def testSwitchToFrame(self):
self._driver.ExecuteScript(
'var frame = document.createElement("iframe");'
'frame.id="id";'
'frame.name="name";'
'document.body.appendChild(frame);')
self.assertTrue(self._driver.ExecuteScript('return window.top == window'))
self._driver.SwitchToFrame('id')
self.assertTrue(self._driver.ExecuteScript('return window.top != window'))
self._driver.SwitchToMainFrame()
self.assertTrue(self._driver.ExecuteScript('return window.top == window'))
self._driver.SwitchToFrame('name')
self.assertTrue(self._driver.ExecuteScript('return window.top != window'))
self._driver.SwitchToMainFrame()
self.assertTrue(self._driver.ExecuteScript('return window.top == window'))
self._driver.SwitchToFrameByIndex(0)
self.assertTrue(self._driver.ExecuteScript('return window.top != window'))
self._driver.SwitchToMainFrame()
self.assertTrue(self._driver.ExecuteScript('return window.top == window'))
self._driver.SwitchToFrame(self._driver.FindElement('tag name', 'iframe'))
self.assertTrue(self._driver.ExecuteScript('return window.top != window'))
def testSwitchToParentFrame(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/nested.html'))
self.assertTrue('One' in self._driver.GetPageSource())
self._driver.SwitchToFrameByIndex(0)
self.assertTrue('Two' in self._driver.GetPageSource())
self._driver.SwitchToFrameByIndex(0)
self.assertTrue('Three' in self._driver.GetPageSource())
self._driver.SwitchToParentFrame()
self.assertTrue('Two' in self._driver.GetPageSource())
self._driver.SwitchToParentFrame()
self.assertTrue('One' in self._driver.GetPageSource())
def testSwitchToNestedFrame(self):
self._driver.Load(self.GetHttpUrlForFile(
'/chromedriver/nested_frameset.html'))
self._driver.SwitchToFrameByIndex(0)
self._driver.FindElement("css selector", "#link")
self._driver.SwitchToMainFrame()
self._driver.SwitchToFrame('2Frame')
self._driver.FindElement("css selector", "#l1")
self._driver.SwitchToMainFrame()
self._driver.SwitchToFrame('fourth_frame')
self.assertTrue('One' in self._driver.GetPageSource())
self._driver.SwitchToMainFrame()
self._driver.SwitchToFrameByIndex(4)
self._driver.FindElement("css selector", "#aa1")
def testExecuteInRemovedFrame(self):
self._driver.ExecuteScript(
'var frame = document.createElement("iframe");'
'frame.id="id";'
'frame.name="name";'
'document.body.appendChild(frame);'
'window.addEventListener("message",'
' function(event) { document.body.removeChild(frame); });')
self.assertTrue(self._driver.ExecuteScript('return window.top == window'))
self._driver.SwitchToFrame('id')
self.assertTrue(self._driver.ExecuteScript('return window.top != window'))
self._driver.ExecuteScript('parent.postMessage("remove", "*");')
self._driver.SwitchToMainFrame()
self.assertTrue(self._driver.ExecuteScript('return window.top == window'))
def testSwitchToStaleFrame(self):
self._driver.ExecuteScript(
'var frame = document.createElement("iframe");'
'frame.id="id";'
'frame.name="name";'
'document.body.appendChild(frame);')
element = self._driver.FindElement("css selector", "#id")
self._driver.SwitchToFrame(element)
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html'))
with self.assertRaises(chromedriver.StaleElementReference):
self._driver.SwitchToFrame(element)
def testGetTitle(self):
script = 'document.title = "title"; return 1;'
self.assertEquals(1, self._driver.ExecuteScript(script))
self.assertEquals('title', self._driver.GetTitle())
def testGetPageSource(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/page_test.html'))
self.assertTrue('Link to empty.html' in self._driver.GetPageSource())
def testFindElement(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html'))
self._driver.ExecuteScript(
'document.body.innerHTML = "<div>a</div><div>b</div>";')
self.assertTrue(
isinstance(self._driver.FindElement('tag name', 'div'),
webelement.WebElement))
def testNoSuchElementExceptionMessage(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html'))
self._driver.ExecuteScript(
'document.body.innerHTML = "<div>a</div><div>b</div>";')
self.assertRaisesRegexp(chromedriver.NoSuchElement,
'no such element: Unable '
'to locate element: {"method":"tag name",'
'"selector":"divine"}',
self._driver.FindElement,
'tag name', 'divine')
def testFindElements(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html'))
self._driver.ExecuteScript(
'document.body.innerHTML = "<div>a</div><div>b</div>";')
divs = self._driver.FindElements('tag name', 'div')
self.assertTrue(isinstance(divs, list))
self.assertEquals(2, len(divs))
for div in divs:
self.assertTrue(isinstance(div, webelement.WebElement))
def testFindChildElement(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html'))
self._driver.ExecuteScript(
'document.body.innerHTML = "<div><br><br></div><div><a></a></div>";')
element = self._driver.FindElement('tag name', 'div')
self.assertTrue(
isinstance(element.FindElement('tag name', 'br'),
webelement.WebElement))
def testFindChildElements(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html'))
self._driver.ExecuteScript(
'document.body.innerHTML = "<div><br><br></div><div><br></div>";')
element = self._driver.FindElement('tag name', 'div')
brs = element.FindElements('tag name', 'br')
self.assertTrue(isinstance(brs, list))
self.assertEquals(2, len(brs))
for br in brs:
self.assertTrue(isinstance(br, webelement.WebElement))
def testClickElement(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html'))
div = self._driver.ExecuteScript(
'document.body.innerHTML = "<div>old</div>";'
'var div = document.getElementsByTagName("div")[0];'
'div.addEventListener("click", function() {'
' div.innerHTML="new<br>";'
'});'
'return div;')
div.Click()
self.assertEquals(1, len(self._driver.FindElements('tag name', 'br')))
def testClickElementInSubFrame(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/frame_test.html'))
frame = self._driver.FindElement('tag name', 'iframe')
self._driver.SwitchToFrame(frame)
# Test clicking element in the sub frame.
self.testClickElement()
def testClickElementAfterNavigation(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/link_nav.html'))
link = self._driver.FindElement('css selector', '#l1')
link.Click()
alert_button = self._driver.FindElement('css selector', '#aa1')
alert_button.Click()
self.assertTrue(self._driver.IsAlertOpen())
def testActionsMouseMove(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html'))
self._driver.ExecuteScript(
'document.body.innerHTML = "<div>old</div>";'
'var div = document.getElementsByTagName("div")[0];'
'div.style["width"] = "100px";'
'div.style["height"] = "100px";'
'div.addEventListener("mouseover", function() {'
' var div = document.getElementsByTagName("div")[0];'
' div.innerHTML="new<br>";'
'});'
'return div;')
actions = ({"actions": [{
"actions": [{"duration": 32, "type": "pause"}],
"id": "0",
"type": "none"
}, {
"type":"pointer",
"actions":[{"type": "pointerMove", "x": 10, "y": 10}],
"parameters": {"pointerType": "mouse"},
"id": "pointer1"}]})
self._driver.PerformActions(actions)
self.assertEquals(1, len(self._driver.FindElements('tag name', 'br')))
def testActionsMouseClick(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html'))
self._driver.ExecuteScript(
'document.body.innerHTML = "<div>old</div>";'
'var div = document.getElementsByTagName("div")[0];'
'div.style["width"] = "100px";'
'div.style["height"] = "100px";'
'div.addEventListener("click", function() {'
' var div = document.getElementsByTagName("div")[0];'
' div.innerHTML="new<br>";'
'});'
'return div;')
actions = ({"actions": [{
"type":"pointer",
"actions":[{"type": "pointerMove", "x": 10, "y": 10},
{"type": "pointerDown", "button": 0},
{"type": "pointerUp", "button": 0}],
"parameters": {"pointerType": "mouse"},
"id": "pointer1"}]})
self._driver.PerformActions(actions)
self.assertEquals(1, len(self._driver.FindElements('tag name', 'br')))
def testActionsMouseDoubleClick(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html'))
self._driver.ExecuteScript(
'document.body.innerHTML = "<div>old</div>";'
'var div = document.getElementsByTagName("div")[0];'
'div.style["width"] = "100px";'
'div.style["height"] = "100px";'
'div.addEventListener("dblclick", function() {'
' var div = document.getElementsByTagName("div")[0];'
' div.innerHTML="new<br>";'
'});'
'return div;')
actions = ({"actions": [{
"type":"pointer",
"actions":[{"type": "pointerMove", "x": 10, "y": 10},
{"type": "pointerDown", "button": 0},
{"type": "pointerUp", "button": 0},
{"type": "pointerDown", "button": 0},
{"type": "pointerUp", "button": 0}],
"parameters": {"pointerType": "mouse"},
"id": "pointer1"}]})
self._driver.PerformActions(actions)
self.assertEquals(1, len(self._driver.FindElements('tag name', 'br')))
def testActionsMouseTripleClick(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html'))
self._driver.ExecuteScript(
'document.body.innerHTML = "<div>old</div>";'
'var div = document.getElementsByTagName("div")[0];'
'div.style["width"] = "100px";'
'div.style["height"] = "100px";'
'window.click_counts = [];'
'div.addEventListener("click", event => {'
' window.click_counts.push(event.detail);'
'});'
'return div;')
actions = ({"actions": [{
"type":"pointer",
"actions":[{"type": "pointerMove", "x": 10, "y": 10},
{"type": "pointerDown", "button": 0},
{"type": "pointerUp", "button": 0},
{"type": "pointerDown", "button": 0},
{"type": "pointerUp", "button": 0},
{"type": "pointerDown", "button": 0},
{"type": "pointerUp", "button": 0}],
"parameters": {"pointerType": "mouse"},
"id": "pointer1"}]})
self._driver.PerformActions(actions)
click_counts = self._driver.ExecuteScript('return window.click_counts')
self.assertEquals(3, len(click_counts))
self.assertEquals(1, click_counts[0])
self.assertEquals(2, click_counts[1])
self.assertEquals(3, click_counts[2])
def testActionsMouseResetCountOnOtherButton(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html'))
self._driver.ExecuteScript(
'document.body.innerHTML = "<div>old</div>";'
'var div = document.getElementsByTagName("div")[0];'
'div.style["width"] = "100px";'
'div.style["height"] = "100px";'
'div.addEventListener("dblclick", function() {'
' var div = document.getElementsByTagName("div")[0];'
' div.innerHTML="new<br>";'
'});'
'return div;')
actions = ({"actions": [{
"type":"pointer",
"actions":[{"type": "pointerMove", "x": 10, "y": 10},
{"type": "pointerDown", "button": 0},
{"type": "pointerUp", "button": 0},
{"type": "pointerDown", "button": 1},
{"type": "pointerUp", "button": 1}],
"parameters": {"pointerType": "mouse"},
"id": "pointer1"}]})
self._driver.PerformActions(actions)
self.assertEquals(0, len(self._driver.FindElements('tag name', 'br')))
def testActionsMouseResetCountOnMove(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html'))
self._driver.ExecuteScript(
'document.body.innerHTML = "<div>old</div>";'
'var div = document.getElementsByTagName("div")[0];'
'div.style["width"] = "100px";'
'div.style["height"] = "100px";'
'div.addEventListener("dblclick", function() {'
' var div = document.getElementsByTagName("div")[0];'
' div.innerHTML="new<br>";'
'});'
'return div;')
actions = ({"actions": [{
"type":"pointer",
"actions":[{"type": "pointerMove", "x": 10, "y": 10},
{"type": "pointerDown", "button": 0},
{"type": "pointerUp", "button": 0},
{"type": "pointerMove", "x": 30, "y": 10},
{"type": "pointerDown", "button": 0},
{"type": "pointerUp", "button": 0}],
"parameters": {"pointerType": "mouse"},
"id": "pointer1"}]})
self._driver.PerformActions(actions)
self.assertEquals(0, len(self._driver.FindElements('tag name', 'br')))
def testActionsMouseDrag(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/drag.html'))
target = self._driver.FindElement('css selector', '#target')
# Move to center of target element and drag it to a new location.
actions = ({'actions': [{
"actions": [{"duration": 32, "type": "pause"},
{"duration": 32, "type": "pause"},
{"duration": 32, "type": "pause"}],
"id": "0",
"type": "none"
}, {
'type': 'pointer',
'actions': [
{'type': 'pointerMove', 'x': 100, 'y': 100},
{'type': 'pointerDown', 'button': 0},
{'type': 'pointerMove', 'x': 150, 'y': 175}
],
'parameters': {'pointerType': 'mouse'},
'id': 'pointer1'}]})
time.sleep(1)
self._driver.PerformActions(actions)
time.sleep(1)
rect = target.GetRect()
self.assertAlmostEqual(100, rect['x'], delta=1)
self.assertAlmostEqual(125, rect['y'], delta=1)
# Without releasing mouse button, should continue the drag.
actions = ({'actions': [{
"actions": [{"duration": 32, "type": "pause"}],
"id": "0",
"type": "none"
}, {
'type': 'pointer',
'actions': [
{'type': 'pointerMove', 'x': 15, 'y': 20, 'origin': 'pointer'}
],
'parameters': {'pointerType': 'mouse'},
'id': 'pointer1'}]})
time.sleep(1)
self._driver.PerformActions(actions)
time.sleep(1)
rect = target.GetRect()
self.assertAlmostEqual(115, rect['x'], delta=1)
self.assertAlmostEqual(145, rect['y'], delta=1)
# Releasing mouse button stops the drag.
actions = ({'actions': [{
"actions": [{"duration": 32, "type": "pause"},
{"duration": 32, "type": "pause"}],
"id": "0",
"type": "none"
}, {
'type': 'pointer',
'actions': [
{'type': 'pointerUp', 'button': 0},
{'type': 'pointerMove', 'x': 25, 'y': 25, 'origin': 'pointer'}
],
'parameters': {'pointerType': 'mouse'},
'id': 'pointer1'}]})
time.sleep(1)
self._driver.PerformActions(actions)
time.sleep(1)
rect = target.GetRect()
self.assertAlmostEqual(115, rect['x'], delta=1)
self.assertAlmostEqual(145, rect['y'], delta=1)
def testActionsWheelScroll(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html'))
self._driver.ExecuteScript(
'document.body.innerHTML = "<div>old</div>";'
'var div = document.getElementsByTagName("div")[0];'
'div.style["width"] = "100px";'
'div.style["height"] = "1000px";'
'div.addEventListener("wheel", function() {'
' var div = document.getElementsByTagName("div")[0];'
' div.innerHTML="new<br>";'
'});'
'return div;')
time.sleep(1)
actions = ({"actions": [{
"type":"wheel",
"actions":[{"type": "scroll", "x": 10, "y": 10, "deltaX": 5,
"deltaY": 15}],
"id": "wheel1"}]})
time.sleep(1)
self._driver.PerformActions(actions)
time.sleep(1)
self.assertEquals(1, len(self._driver.FindElements('tag name', 'br')))
def testActionsTouchTap(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html'))
self._driver.ExecuteScript(
'document.body.innerHTML = "<div>old</div>";'
'var div = document.getElementsByTagName("div")[0];'
'div.style["width"] = "100px";'
'div.style["height"] = "100px";'
'div.addEventListener("click", function() {'
' var div = document.getElementsByTagName("div")[0];'
' div.innerHTML="new<br>";'
'});'
'return div;')
actions = ({"actions": [{
"type":"pointer",
"actions":[{"type": "pointerMove", "x": 10, "y": 10},
{"type": "pointerDown"},
{"type": "pointerUp"}],
"parameters": {"pointerType": "touch"},
"id": "pointer1"}]})
self._driver.PerformActions(actions)
self.assertEquals(1, len(self._driver.FindElements('tag name', 'br')))
def testActionsMultiTouchPoint(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html'))
self._driver.ExecuteScript(
'''
document.body.innerHTML
= "<div id='div' autofocus style='width:200px; height:200px'>";
window.events = [];
const div = document.getElementById('div');
div.addEventListener('touchstart', event => {
window.events.push(
{type: event.type,
x: event.touches[event.touches.length - 1].clientX,
y: event.touches[event.touches.length - 1].clientY});
});
div.addEventListener('touchend', event => {
window.events.push(
{type: event.type});
});
''')
time.sleep(1)
actions = ({"actions": [{
"type":"pointer",
"actions":[{"type": "pointerMove", "x": 50, "y": 50},
{"type": "pointerDown"},
{"type": "pointerUp"}],
"parameters": {"pointerType": "touch"},
"id": "pointer1"},
{
"type":"pointer",
"actions":[{"type": "pointerMove", "x": 60, "y": 60},
{"type": "pointerDown"},
{"type": "pointerUp"}],
"parameters": {"pointerType": "touch"},
"id": "pointer2"}]})
self._driver.PerformActions(actions)
time.sleep(1)
events = self._driver.ExecuteScript('return window.events')
self.assertEquals(4, len(events))
self.assertEquals("touchstart", events[0]['type'])
self.assertEquals("touchstart", events[1]['type'])
self.assertEquals("touchend", events[2]['type'])
self.assertEquals("touchend", events[3]['type'])
self.assertAlmostEqual(50, events[0]['x'], delta=1)
self.assertAlmostEqual(50, events[0]['y'], delta=1)
self.assertAlmostEqual(60, events[1]['x'], delta=1)
self.assertAlmostEqual(60, events[1]['y'], delta=1)
self._driver.ReleaseActions()
def testActionsMulti(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html'))
self._driver.ExecuteScript(
'''
document.body.innerHTML
= "<div id='div' autofocus style='width:200px; height:200px'>";
window.events = [];
const div = document.getElementById('div');
div.addEventListener('click', event => {
window.events.push(
{x: event.clientX, y: event.clientY});
});
''')
# Move mouse to (50, 50).
self._driver.PerformActions({'actions': [
{
'type': 'pointer',
'id': 'mouse',
'actions': [ {'type': 'pointerMove', 'x': 50, 'y': 50} ]
}
]})
# Click mouse button. ChromeDriver should remember that mouse is at
# (50, 50).
self._driver.PerformActions({'actions': [
{
'type': 'pointer',
'id': 'mouse',
'actions': [
{'type': 'pointerDown', "button": 0},
{'type': 'pointerUp', "button": 0}
]
}
]})
events = self._driver.ExecuteScript('return window.events')
self.assertEquals(1, len(events))
self.assertAlmostEqual(50, events[0]['x'], delta=1)
self.assertAlmostEqual(50, events[0]['y'], delta=1)
# Clean up action states, move mouse back to (0, 0).
self._driver.ReleaseActions()
# Move mouse relative by (80, 80) pixels, and then click.
self._driver.PerformActions({'actions': [
{
'type': 'pointer',
'id': 'mouse',
'actions': [
{'type': 'pointerMove', 'x': 80, 'y': 80, 'origin': 'pointer'},
{'type': 'pointerDown', "button": 0},
{'type': 'pointerUp', "button": 0}
]
}
]})
events = self._driver.ExecuteScript('return window.events')
self.assertEquals(2, len(events))
self.assertAlmostEqual(80, events[1]['x'], delta=1)
self.assertAlmostEqual(80, events[1]['y'], delta=1)
self._driver.ReleaseActions()
def testActionsPenPointerEventProperties(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html'))
self._driver.ExecuteScript(
'''
document.body.innerHTML = "<div>test</div>";
var div = document.getElementsByTagName("div")[0];
div.style["width"] = "100px";
div.style["height"] = "100px";
window.events = [];
div.addEventListener("pointerdown", event => {
window.events.push(
{type: event.type,
x: event.clientX,
y: event.clientY,
width: event.width,
height: event.height,
pressure: event.pressure,
tiltX: event.tiltX,
tiltY: event.tiltY,
twist: event.twist});
});
''')
time.sleep(1)
actions = ({"actions": [{
"type":"pointer",
"actions":[{"type": "pointerMove", "x": 30, "y": 30},
{"type": "pointerDown", "button": 0, "pressure":0.55,
"tiltX":-36, "tiltY":83, "twist":266},
{"type": "pointerMove", "x": 50, "y": 50},
{"type": "pointerUp", "button": 0}],
"parameters": {"pointerType": "mouse"},
"id": "pointer1"}]})
self._driver.PerformActions(actions)
time.sleep(1)
events = self._driver.ExecuteScript('return window.events')
self.assertEquals(1, len(events))
self.assertEquals("pointerdown", events[0]['type'])
self.assertAlmostEqual(30, events[0]['x'], delta=1)
self.assertAlmostEqual(30, events[0]['y'], delta=1)
self.assertEquals(1.0, round(events[0]['width'], 2))
self.assertEquals(1.0, round(events[0]['height'], 2))
self.assertEquals(0.55, round(events[0]['pressure'], 2))
self.assertEquals(-36, events[0]['tiltX'])
self.assertEquals(83, events[0]['tiltY'])
self.assertEquals(266, events[0]['twist'])
def testActionsPenPointerEventPressure(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html'))
self._driver.ExecuteScript(
'''
document.body.innerHTML = "<div>test</div>";
var div = document.getElementsByTagName("div")[0];
div.style["width"] = "100px";
div.style["height"] = "100px";
window.events = [];
var event_list = ["pointerdown", "pointermove", "pointerup"];
for (var i = 0; i < event_list.length; i++) {
div.addEventListener(event_list[i], event => {
window.events.push(
{type: event.type,
x: event.clientX,
y: event.clientY,
pressure: event.pressure,
twist: event.twist});
});
}
''')
time.sleep(1)
actions = ({"actions": [{
"type":"pointer",
"actions":[{"type": "pointerMove", "x": 30, "y": 30},
{"type": "pointerDown", "button": 0,
"twist":30},
{"type": "pointerMove", "x": 50, "y": 50},
{"type": "pointerUp", "button": 0}],
"parameters": {"pointerType": "pen"},
"id": "pointer1"}]})
self._driver.PerformActions(actions)
time.sleep(1)
events = self._driver.ExecuteScript('return window.events')
self.assertEquals(4, len(events))
self.assertEquals("pointermove", events[0]['type'])
self.assertAlmostEqual(30, events[0]['x'], delta=1)
self.assertAlmostEqual(30, events[0]['y'], delta=1)
self.assertEquals(0.0, round(events[0]['pressure'], 2))
self.assertEquals(0, events[0]['twist'])
self.assertEquals("pointerdown", events[1]['type'])
self.assertAlmostEqual(30, events[1]['x'], delta=1)
self.assertAlmostEqual(30, events[1]['y'], delta=1)
self.assertEquals(0.5, round(events[1]['pressure'], 2))
self.assertEquals(30, events[1]['twist'])
self.assertEquals("pointermove", events[2]['type'])
self.assertAlmostEqual(50, events[2]['x'], delta=1)
self.assertAlmostEqual(50, events[2]['y'], delta=1)
self.assertEquals(0.5, round(events[2]['pressure'], 2))
self.assertEquals(0, events[2]['twist'])
self.assertEquals("pointerup", events[3]['type'])
self.assertAlmostEqual(50, events[3]['x'], delta=1)
self.assertAlmostEqual(50, events[3]['y'], delta=1)
self.assertEquals(0.0, round(events[3]['pressure'], 2))
self.assertEquals(0, events[3]['twist'])
def testActionsPause(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html'))
self._driver.ExecuteScript(
'''
document.body.innerHTML
= "<input type='text' autofocus style='width:100px; height:100px'>";
window.events = [];
const input = document.getElementsByTagName("input")[0];
const listener
= e => window.events.push({type: e.type, time: e.timeStamp});
input.addEventListener("keydown", listener);
input.addEventListener("keyup", listener);
input.addEventListener("mousedown", listener);
''')
# Actions on 3 devices, across 6 ticks, with 200 ms pause at ticks 1 to 4.
# Tick "key" device "pointer" device "none" device
# 0 move
# 1 pause 200 ms pointer down pause 100 ms
# 2 "a" key down pointer up pause 200 ms
# 3 "a" key up pause 200 ms
# 4 "b" key down move 200 ms
# 5 "b" key up
actions = {'actions': [
{
'type': 'key',
'id': 'key',
'actions': [
{'type': 'pause'},
{'type': 'pause', 'duration': 200},
{'type': 'keyDown', 'value': 'a'},
{'type': 'keyUp', 'value': 'a'},
{'type': 'keyDown', 'value': 'b'},
{'type': 'keyUp', 'value': 'b'},
]
},
{
'type': 'pointer',
'id': 'mouse',
'actions': [
{'type': 'pointerMove', 'x': 50, 'y': 50},
{'type': 'pointerDown', 'button': 0},
{'type': 'pointerUp', 'button': 0},
{'type': 'pause', 'duration': 200},
{'type': 'pointerMove', 'duration': 200, 'x': 10, 'y': 10},
]
},
{
'type': 'none',
'id': 'none',
'actions': [
{'type': 'pause'},
{'type': 'pause', 'duration': 100},
{'type': 'pause', 'duration': 200},
]
}
]}
self._driver.PerformActions(actions)
events = self._driver.ExecuteScript('return window.events')
expected_events = ['mousedown', 'keydown', 'keyup', 'keydown', 'keyup']
self.assertEquals(len(expected_events), len(events))
for i in range(len(events)):
self.assertEqual(expected_events[i], events[i]['type'])
if i > 0:
elapsed_time = events[i]['time'] - events[i-1]['time']
self.assertGreaterEqual(elapsed_time, 200)
def testReleaseActions(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html'))
self._driver.ExecuteScript(
'''
document.body.innerHTML
= "<input id='target' type='text' style='width:200px; height:200px'>";
window.events = [];
const recordKeyEvent = event => {
window.events.push(
{type: event.type, code: event.code});
};
const recordMouseEvent = event => {
window.events.push(
{type: event.type, x: event.clientX, y: event.clientY});
};
const target = document.getElementById('target');
target.addEventListener('keydown', recordKeyEvent);
target.addEventListener('keyup', recordKeyEvent);
target.addEventListener('mousedown', recordMouseEvent);
target.addEventListener('mouseup', recordMouseEvent);
''')
# Move mouse to (50, 50), press a mouse button, and press a key.
self._driver.PerformActions({'actions': [
{
'type': 'pointer',
'id': 'mouse',
'actions': [
{'type': 'pointerMove', 'x': 50, 'y': 50},
{'type': 'pointerDown', "button": 0}
]
},
{
'type': 'key',
'id': 'key',
'actions': [
{'type': 'pause'},
{'type': 'pause'},
{'type': 'keyDown', 'value': 'a'}
]
}
]})
events = self._driver.ExecuteScript('return window.events')
self.assertEquals(2, len(events))
self.assertEquals('mousedown', events[0]['type'])
self.assertAlmostEqual(50, events[0]['x'], delta=1)
self.assertAlmostEqual(50, events[0]['y'], delta=1)
self.assertEquals('keydown', events[1]['type'])
self.assertEquals('KeyA', events[1]['code'])
self._driver.ReleaseActions()
events = self._driver.ExecuteScript('return window.events')
self.assertEquals(4, len(events))
self.assertEquals('keyup', events[2]['type'])
self.assertEquals('KeyA', events[2]['code'])
self.assertEquals('mouseup', events[3]['type'])
self.assertAlmostEqual(50, events[3]['x'], delta=1)
self.assertAlmostEqual(50, events[3]['y'], delta=1)
def testActionsCtrlCommandKeys(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html'))
self._driver.ExecuteScript('''
document.write('<input type="text" id="text1" value="Hello World" />');
document.write('<br/>')
document.write('<input type="text" id="text2">');
var text1 = document.getElementById("text1");
text1.addEventListener("click", function() {
var text1 = document.getElementById("text1");
text1.value="new text";
});
''')
time.sleep(1)
elem1 = self._driver.FindElement('css selector', '#text1')
elem2 = self._driver.FindElement('css selector', '#text2')
self.assertEquals("Hello World", elem1.GetProperty('value'))
time.sleep(1)
platform = util.GetPlatformName()
modifier_key = u'\uE009'
if platform == 'mac':
modifier_key = u'\uE03D'
# This is a sequence of actions, first move the mouse to input field
# "elem1", then press ctrl/cmd key and 'a' key to select all the text in
# "elem1", and then press 'x' to cut the text and move the mouse to input
# field "elem2" and press 'v' to paste the text, and at the end, we check
# the texts in both input fields to see if the text are cut and pasted
# correctly from "elem1" to "elem2".
actions = ({'actions': [{
'type': 'key',
'id': 'key',
'actions': [
{'type': 'pause'},
{'type': 'pause'},
{'type': 'pause'},
{'type': 'keyDown', 'value': modifier_key},
{'type': 'keyDown', 'value': 'a'},
{'type': 'keyUp', 'value': 'a'},
{'type': 'keyDown', 'value': 'x'},
{'type': 'keyUp', 'value': 'x'},
{'type': 'keyUp', 'value': modifier_key},
{'type': 'pause'},
{'type': 'pause'},
{'type': 'pause'},
{'type': 'keyDown', 'value': modifier_key},
{'type': 'keyDown', 'value': 'v'},
{'type': 'keyUp', 'value': 'v'},
{'type': 'keyUp', 'value': modifier_key}
]}, {
'type':'pointer',
'actions':[{'type': 'pointerMove', 'x': 0, 'y': 0, 'origin': elem1},
{'type': 'pointerDown', 'button': 0},
{'type': 'pointerUp', 'button': 0},
{'type': 'pause'},
{'type': 'pause'},
{'type': 'pause'},
{'type': 'pause'},
{'type': 'pause'},
{'type': 'pause'},
{'type': 'pointerMove', 'x': 0, 'y': 0, 'origin': elem2},
{'type': 'pointerDown', 'button': 0},
{'type': 'pointerUp', 'button': 0},
{'type': 'pause'},
{'type': 'pause'},
{'type': 'pause'},
{'type': 'pause'}],
'parameters': {'pointerType': 'mouse'},
'id': 'pointer1'}
]})
self._driver.PerformActions(actions)
time.sleep(1)
self.assertEquals("", elem1.GetProperty('value'))
self.assertEquals("new text", elem2.GetProperty('value'))
time.sleep(1)
def testPageLoadStrategyIsNormalByDefault(self):
self.assertEquals('normal',
self._driver.capabilities['pageLoadStrategy'])
def testClearElement(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html'))
text = self._driver.ExecuteScript(
'document.body.innerHTML = \'<input type="text" value="abc">\';'
'return document.getElementsByTagName("input")[0];')
value = self._driver.ExecuteScript('return arguments[0].value;', text)
self.assertEquals('abc', value)
text.Clear()
value = self._driver.ExecuteScript('return arguments[0].value;', text)
self.assertEquals('', value)
def testSendKeysToInputFileElement(self):
file_name = os.path.join(_TEST_DATA_DIR, 'anchor_download_test.png')
self._driver.Load(ChromeDriverTest.GetHttpUrlForFile(
'/chromedriver/file_input.html'))
elem = self._driver.FindElement('css selector', '#id_file')
elem.SendKeys(file_name)
text = self._driver.ExecuteScript(
'var input = document.getElementById("id_file").value;'
'return input;')
self.assertEquals('C:\\fakepath\\anchor_download_test.png', text);
if not _ANDROID_PACKAGE_KEY:
self.assertRaises(chromedriver.InvalidArgument,
elem.SendKeys, "/blah/blah/blah")
def testSendKeysToNonTypeableInputElement(self):
self._driver.Load("about:blank")
self._driver.ExecuteScript(
"document.body.innerHTML = '<input type=\"color\">';")
elem = self._driver.FindElement('tag name', 'input');
input_value = '#7fffd4'
elem.SendKeys(input_value)
value = elem.GetProperty('value')
self.assertEquals(input_value, value)
def testGetElementAttribute(self):
self._driver.Load(self.GetHttpUrlForFile(
'/chromedriver/attribute_colon_test.html'))
elem = self._driver.FindElement("css selector", "*[name='phones']")
self.assertEquals('3', elem.GetAttribute('size'))
def testGetElementProperty(self):
self._driver.Load(self.GetHttpUrlForFile(
'/chromedriver/two_inputs.html'))
elem = self._driver.FindElement("css selector", "#first")
self.assertEquals('text', elem.GetProperty('type'))
self.assertEquals('first', elem.GetProperty('id'))
def testGetElementSpecialCharAttribute(self):
self._driver.Load(self.GetHttpUrlForFile(
'/chromedriver/attribute_colon_test.html'))
elem = self._driver.FindElement("css selector", "*[name='phones']")
self.assertEquals('colonvalue', elem.GetAttribute('ext:qtip'))
def testGetCurrentUrl(self):
url = self.GetHttpUrlForFile('/chromedriver/frame_test.html')
self._driver.Load(url)
self.assertEquals(url, self._driver.GetCurrentUrl())
self._driver.SwitchToFrame(self._driver.FindElement('tag name', 'iframe'))
self.assertEquals(url, self._driver.GetCurrentUrl())
def testGoBackAndGoForward(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html'))
self._driver.GoBack()
self._driver.GoForward()
def testDontGoBackOrGoForward(self):
# We need to run this test in a new tab so that it is isolated from previous
# test runs.
old_windows = self._driver.GetWindowHandles()
self._driver.ExecuteScript('window.open("about:blank")')
new_window = self.WaitForNewWindow(self._driver, old_windows)
self._driver.SwitchToWindow(new_window)
self.assertEquals('about:blank', self._driver.GetCurrentUrl())
self._driver.GoBack()
self.assertEquals('about:blank', self._driver.GetCurrentUrl())
self._driver.GoForward()
self.assertEquals('about:blank', self._driver.GetCurrentUrl())
def testBackNavigationAfterClickElement(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/link_nav.html'))
link = self._driver.FindElement('css selector', '#l1')
link.Click()
self._driver.GoBack()
self.assertNotEqual('data:,', self._driver.GetCurrentUrl())
self.assertEquals(self.GetHttpUrlForFile('/chromedriver/link_nav.html'),
self._driver.GetCurrentUrl())
def testAlertHandlingOnPageUnload(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html'))
self._driver.ExecuteScript('window.onbeforeunload=function(){return true}')
self._driver.FindElement('tag name', 'body').Click()
self._driver.GoBack()
self.assertTrue(self._driver.IsAlertOpen())
self._driver.HandleAlert(True)
self.assertFalse(self._driver.IsAlertOpen())
def testRefresh(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html'))
self._driver.Refresh()
def testAlert(self):
self.assertFalse(self._driver.IsAlertOpen())
self._driver.ExecuteScript('window.confirmed = confirm(\'HI\');')
self.assertTrue(self._driver.IsAlertOpen())
self.assertEquals('HI', self._driver.GetAlertMessage())
self._driver.HandleAlert(False)
self.assertFalse(self._driver.IsAlertOpen())
self.assertEquals(False,
self._driver.ExecuteScript('return window.confirmed'))
def testSendTextToAlert(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html'))
self._driver.ExecuteScript('prompt = window.prompt()')
self.assertTrue(self._driver.IsAlertOpen())
self._driver.HandleAlert(True, 'TextToPrompt')
self.assertEquals('TextToPrompt',
self._driver.ExecuteScript('return prompt'))
self._driver.ExecuteScript('window.confirmed = confirm(\'HI\');')
self.assertRaises(chromedriver.ElementNotInteractable,
self._driver.HandleAlert,
True, 'textToConfirm')
self._driver.HandleAlert(True) #for closing the previous alert.
self._driver.ExecuteScript('window.onbeforeunload=function(){return true}')
self._driver.FindElement('tag name', 'body').Click()
self._driver.Refresh()
self.assertTrue(self._driver.IsAlertOpen())
self.assertRaises(chromedriver.UnsupportedOperation,
self._driver.HandleAlert,
True, 'textToOnBeforeUnload')
def testAlertOnNewWindow(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html'))
old_windows = self._driver.GetWindowHandles()
self._driver.ExecuteScript("window.open('%s')" %
self.GetHttpUrlForFile('/chromedriver/alert_onload.html'))
new_window = self.WaitForNewWindow(self._driver, old_windows)
self.assertNotEqual(None, new_window)
self._driver.SwitchToWindow(new_window)
self.assertTrue(self._driver.IsAlertOpen())
self._driver.HandleAlert(False)
self.assertFalse(self._driver.IsAlertOpen())
def testShouldHandleNewWindowLoadingProperly(self):
"""Tests that ChromeDriver determines loading correctly for new windows."""
self._http_server.SetDataForPath(
'/newwindow',
"""
<html>
<body>
<a href='%s' target='_blank'>new window/tab</a>
</body>
</html>""" % self._sync_server.GetUrl())
self._driver.Load(self._http_server.GetUrl() + '/newwindow')
old_windows = self._driver.GetWindowHandles()
self._driver.FindElement('tag name', 'a').Click()
new_window = self.WaitForNewWindow(self._driver, old_windows)
self.assertNotEqual(None, new_window)
self.assertFalse(self._driver.IsLoading())
self._driver.SwitchToWindow(new_window)
self.assertTrue(self._driver.IsLoading())
self._sync_server.RespondWithContent('<html>new window</html>')
self._driver.ExecuteScript('return 1') # Shouldn't hang.
def testPopups(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html'))
old_handles = self._driver.GetWindowHandles()
self._driver.ExecuteScript('window.open("about:blank")')
new_window_handle = self.WaitForNewWindow(self._driver, old_handles)
self.assertNotEqual(None, new_window_handle)
def testNoSuchFrame(self):
self.assertRaises(chromedriver.NoSuchFrame,
self._driver.SwitchToFrame, 'nosuchframe')
self.assertRaises(chromedriver.NoSuchFrame,
self._driver.SwitchToFrame,
self._driver.FindElement('tag name', 'body'))
def testWindowPosition(self):
rect = self._driver.GetWindowRect()
self._driver.SetWindowRect(None, None, rect[2], rect[3])
self.assertEquals(rect, self._driver.GetWindowRect())
# Resize so the window isn't moved offscreen.
# See https://bugs.chromium.org/p/chromedriver/issues/detail?id=297.
self._driver.SetWindowRect(640, 400, None, None)
self._driver.SetWindowRect(None, None, 100, 200)
self.assertEquals([640, 400, 100, 200], self._driver.GetWindowRect())
def testWindowSize(self):
rect = self._driver.GetWindowRect()
self._driver.SetWindowRect(rect[0], rect[1], None, None)
self.assertEquals(rect, self._driver.GetWindowRect())
self._driver.SetWindowRect(640, 400, None, None)
self.assertEquals([640, 400, rect[2], rect[3]],
self._driver.GetWindowRect())
def testWindowRect(self):
old_window_rect = self._driver.GetWindowRect()
self._driver.SetWindowRect(*old_window_rect)
self.assertEquals(self._driver.GetWindowRect(), old_window_rect)
target_window_rect = [640, 400, 100, 200]
target_window_rect_dict = {'width': 640, 'height': 400, 'x': 100, 'y': 200}
returned_window_rect = self._driver.SetWindowRect(*target_window_rect)
self.assertEquals(self._driver.GetWindowRect(), target_window_rect)
self.assertEquals(returned_window_rect, target_window_rect_dict)
def testWindowMaximize(self):
old_rect_list = [640, 400, 100, 200]
self._driver.SetWindowRect(*old_rect_list)
new_rect = self._driver.MaximizeWindow()
new_rect_list = [
new_rect['width'],
new_rect['height'],
new_rect['x'],
new_rect['y']
]
self.assertNotEqual(old_rect_list, new_rect_list)
self._driver.SetWindowRect(*old_rect_list)
self.assertEquals(old_rect_list, self._driver.GetWindowRect())
def testWindowMinimize(self):
handle_prefix = "CDwindow-"
handle = self._driver.GetCurrentWindowHandle()
target = handle[len(handle_prefix):]
self._driver.SetWindowRect(640, 400, 100, 200)
rect = self._driver.MinimizeWindow()
expected_rect = {u'y': 200, u'width': 640, u'height': 400, u'x': 100}
#check it returned the correct rect
for key in expected_rect.keys():
self.assertEquals(expected_rect[key], rect[key])
# check its minimized
res = self._driver.SendCommandAndGetResult('Browser.getWindowForTarget',
{'targetId': target})
self.assertEquals('minimized', res['bounds']['windowState'])
def testWindowFullScreen(self):
old_rect_list = [640, 400, 100, 200]
self._driver.SetWindowRect(*old_rect_list)
self.assertEquals(self._driver.GetWindowRect(), old_rect_list)
new_rect = self._driver.FullScreenWindow()
new_rect_list = [
new_rect['width'],
new_rect['height'],
new_rect['x'],
new_rect['y']
]
self.assertNotEqual(old_rect_list, new_rect_list)
self._driver.SetWindowRect(*old_rect_list)
for i in range(10):
if old_rect_list == self._driver.GetWindowRect():
break
time.sleep(0.1)
self.assertEquals(old_rect_list, self._driver.GetWindowRect())
def testConsoleLogSources(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/console_log.html'))
logs = self._driver.GetLog('browser')
self.assertEqual('javascript', logs[0]['source'])
self.assertTrue('TypeError' in logs[0]['message'])
self.assertEqual('network', logs[1]['source'])
self.assertTrue('nonexistent.png' in logs[1]['message'])
self.assertTrue('404' in logs[1]['message'])
# Sometimes, we also get an error for a missing favicon.
if len(logs) > 2:
self.assertEqual('network', logs[2]['source'])
self.assertTrue('favicon.ico' in logs[2]['message'])
self.assertTrue('404' in logs[2]['message'])
self.assertEqual(3, len(logs))
else:
self.assertEqual(2, len(logs))
def testPendingConsoleLog(self):
new_logs = [""]
def GetPendingLogs(driver):
response = driver.GetLog('browser')
new_logs[0] = [x for x in response if x['source'] == 'console-api']
return new_logs[0]
self._driver.Load(self.GetHttpUrlForFile(
'/chromedriver/pending_console_log.html'))
logs = self._driver.GetLog('browser')
self.assertEqual('console-api', logs[0]['source'])
self.assertTrue('"InitialError" 2018 "Third"' in logs[0]['message'])
self.WaitForCondition(lambda: len(GetPendingLogs(self._driver)) > 0 , 6)
self.assertEqual('console-api', new_logs[0][0]['source'])
self.assertTrue('"RepeatedError" "Second" "Third"' in
new_logs[0][0]['message'])
def testGetLogOnClosedWindow(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/page_test.html'))
old_handles = self._driver.GetWindowHandles()
self._driver.FindElement('css selector', '#link').Click()
self.WaitForNewWindow(self._driver, old_handles)
self._driver.CloseWindow()
try:
self._driver.GetLog('browser')
except chromedriver.ChromeDriverException as e:
self.fail('exception while calling GetLog on a closed tab: ' + e.message)
def testGetLogOnWindowWithAlert(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html'))
self._driver.ExecuteScript('alert("alert!");')
try:
self._driver.GetLog('browser')
except Exception as e:
self.fail(e.message)
def testDoesntHangOnDebugger(self):
self._driver.Load('about:blank')
self._driver.ExecuteScript('debugger;')
def testChromeDriverSendLargeData(self):
script = 'return "0".repeat(10e6);'
lots_of_data = self._driver.ExecuteScript(script)
self.assertEquals('0'.zfill(int(10e6)), lots_of_data)
def testEmulateNetworkConditions(self):
# Network conditions must be set before it can be retrieved.
self.assertRaises(chromedriver.UnknownError,
self._driver.GetNetworkConditions)
# DSL: 2Mbps throughput, 5ms RTT
latency = 5
throughput = 2048 * 1024
self._driver.SetNetworkConditions(latency, throughput, throughput)
network = self._driver.GetNetworkConditions()
self.assertEquals(latency, network['latency']);
self.assertEquals(throughput, network['download_throughput']);
self.assertEquals(throughput, network['upload_throughput']);
self.assertEquals(False, network['offline']);
# Network Conditions again cannot be retrieved after they've been deleted.
self._driver.DeleteNetworkConditions()
self.assertRaises(chromedriver.UnknownError,
self._driver.GetNetworkConditions)
def testEmulateNetworkConditionsName(self):
# DSL: 2Mbps throughput, 5ms RTT
# latency = 5
# throughput = 2048 * 1024
self._driver.SetNetworkConditionsName('DSL')
network = self._driver.GetNetworkConditions()
self.assertEquals(5, network['latency']);
self.assertEquals(2048*1024, network['download_throughput']);
self.assertEquals(2048*1024, network['upload_throughput']);
self.assertEquals(False, network['offline']);
def testEmulateNetworkConditionsSpeed(self):
# Warm up the browser.
self._http_server.SetDataForPath(
'/', "<html><body>blank</body></html>")
self._driver.Load(self._http_server.GetUrl() + '/')
# DSL: 2Mbps throughput, 5ms RTT
latency = 5
throughput_kbps = 2048
throughput = throughput_kbps * 1024
self._driver.SetNetworkConditions(latency, throughput, throughput)
_32_bytes = " 0 1 2 3 4 5 6 7 8 9 A B C D E F"
_1_megabyte = _32_bytes * 32768
self._http_server.SetDataForPath(
'/1MB',
"<html><body>%s</body></html>" % _1_megabyte)
start = monotonic()
self._driver.Load(self._http_server.GetUrl() + '/1MB')
finish = monotonic()
duration = finish - start
actual_throughput_kbps = 1024 / duration
self.assertLessEqual(actual_throughput_kbps, throughput_kbps * 1.5)
self.assertGreaterEqual(actual_throughput_kbps, throughput_kbps / 1.5)
def testEmulateNetworkConditionsNameSpeed(self):
# Warm up the browser.
self._http_server.SetDataForPath(
'/', "<html><body>blank</body></html>")
self._driver.Load(self._http_server.GetUrl() + '/')
# DSL: 2Mbps throughput, 5ms RTT
throughput_kbps = 2048
throughput = throughput_kbps * 1024
self._driver.SetNetworkConditionsName('DSL')
_32_bytes = " 0 1 2 3 4 5 6 7 8 9 A B C D E F"
_1_megabyte = _32_bytes * 32768
self._http_server.SetDataForPath(
'/1MB',
"<html><body>%s</body></html>" % _1_megabyte)
start = monotonic()
self._driver.Load(self._http_server.GetUrl() + '/1MB')
finish = monotonic()
duration = finish - start
actual_throughput_kbps = 1024 / duration
self.assertLessEqual(actual_throughput_kbps, throughput_kbps * 1.5)
self.assertGreaterEqual(actual_throughput_kbps, throughput_kbps / 1.5)
def testEmulateNetworkConditionsOffline(self):
# A workaround for crbug.com/177511; when setting offline, the throughputs
# must be 0.
self._driver.SetNetworkConditions(0, 0, 0, offline=True)
self.assertRaises(chromedriver.ChromeDriverException,
self._driver.Load,
self.GetHttpUrlForFile('/chromedriver/page_test.html'))
# The "X is not available" title is set after the page load event fires, so
# we have to explicitly wait for this to change. We can't rely on the
# navigation tracker to block the call to Load() above.
self.WaitForCondition(lambda: 'is not available' in self._driver.GetTitle())
def testSendCommandAndGetResult(self):
"""Sends a custom command to the DevTools debugger and gets the result"""
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/page_test.html'))
params = {}
document = self._driver.SendCommandAndGetResult('DOM.getDocument', params)
self.assertTrue('root' in document)
def _FindElementInShadowDom(self, css_selectors):
"""Find an element inside shadow DOM using CSS selectors.
The last item in css_selectors identify the element to find. All preceding
selectors identify the hierarchy of shadow hosts to traverse in order to
reach the target shadow DOM."""
current = None
for selector in css_selectors:
if current is None:
# First CSS selector, start from root DOM.
current = self._driver
else:
# current is a shadow host selected previously.
# Enter the corresponding shadow root.
current = self._driver.ExecuteScript(
'return arguments[0].shadowRoot', current)
current = current.FindElement('css selector', selector)
return current
def testShadowDomFindElement(self):
"""Checks that chromedriver can find elements in a shadow DOM."""
self._driver.Load(self.GetHttpUrlForFile(
'/chromedriver/shadow_dom_test.html'))
self.assertTrue(self._FindElementInShadowDom(
["#innerDiv", "#parentDiv", "#textBox"]))
def testShadowDomFindChildElement(self):
"""Checks that chromedriver can find child elements from a shadow DOM
element."""
self._driver.Load(self.GetHttpUrlForFile(
'/chromedriver/shadow_dom_test.html'))
elem = self._FindElementInShadowDom(
["#innerDiv", "#parentDiv", "#childDiv"])
self.assertTrue(elem.FindElement("css selector", "#textBox"))
def testShadowDomFindElementFailsFromRoot(self):
"""Checks that chromedriver can't find elements in a shadow DOM from
root."""
self._driver.Load(self.GetHttpUrlForFile(
'/chromedriver/shadow_dom_test.html'))
# can't find element from the root without /deep/
with self.assertRaises(chromedriver.NoSuchElement):
self._driver.FindElement("css selector", "#textBox")
def testShadowDomText(self):
"""Checks that chromedriver can find extract the text from a shadow DOM
element."""
self._driver.Load(self.GetHttpUrlForFile(
'/chromedriver/shadow_dom_test.html'))
elem = self._FindElementInShadowDom(
["#innerDiv", "#parentDiv", "#heading"])
self.assertEqual("Child", elem.GetText())
def testShadowDomSendKeys(self):
"""Checks that chromedriver can call SendKeys on a shadow DOM element."""
self._driver.Load(self.GetHttpUrlForFile(
'/chromedriver/shadow_dom_test.html'))
elem = self._FindElementInShadowDom(
["#innerDiv", "#parentDiv", "#textBox"])
elem.SendKeys("bar")
self.assertEqual("foobar", self._driver.ExecuteScript(
'return arguments[0].value;', elem))
def testShadowDomClear(self):
"""Checks that chromedriver can call Clear on a shadow DOM element."""
self._driver.Load(self.GetHttpUrlForFile(
'/chromedriver/shadow_dom_test.html'))
elem = self._FindElementInShadowDom(
["#innerDiv", "#parentDiv", "#textBox"])
elem.Clear()
self.assertEqual("", self._driver.ExecuteScript(
'return arguments[0].value;', elem))
def testShadowDomClick(self):
"""Checks that chromedriver can call Click on an element in a shadow DOM."""
self._driver.Load(self.GetHttpUrlForFile(
'/chromedriver/shadow_dom_test.html'))
# Wait for page to stabilize. See https://crbug.com/954553#c7
time.sleep(1)
elem = self._FindElementInShadowDom(
["#innerDiv", "#parentDiv", "#button"])
elem.Click()
# the button's onClicked handler changes the text box's value
self.assertEqual("Button Was Clicked", self._driver.ExecuteScript(
'return arguments[0].value;',
self._FindElementInShadowDom(["#innerDiv", "#parentDiv", "#textBox"])))
def testShadowDomActionClick(self):
'''Checks that ChromeDriver can use actions API to click on an element in a
shadow DOM.'''
self._driver.Load(self.GetHttpUrlForFile(
'/chromedriver/shadow_dom_test.html'))
# Wait for page to stabilize. See https://crbug.com/954553#c7
time.sleep(1)
elem = self._FindElementInShadowDom(
['#innerDiv', '#parentDiv', '#button'])
actions = ({'actions': [{
'type': 'pointer',
'actions': [{'type': 'pointerMove', 'x': 0, 'y': 0, 'origin': elem},
{'type': 'pointerDown', 'button': 0},
{'type': 'pointerUp', 'button': 0}],
'id': 'pointer1'}]})
self._driver.PerformActions(actions)
# the button's onClicked handler changes the text box's value
self.assertEqual('Button Was Clicked', self._driver.ExecuteScript(
'return arguments[0].value;',
self._FindElementInShadowDom(['#innerDiv', '#parentDiv', '#textBox'])))
def testShadowDomStaleReference(self):
"""Checks that trying to manipulate shadow DOM elements that are detached
from the document raises a StaleElementReference exception"""
self._driver.Load(self.GetHttpUrlForFile(
'/chromedriver/shadow_dom_test.html'))
elem = self._FindElementInShadowDom(
["#innerDiv", "#parentDiv", "#button"])
self._driver.ExecuteScript(
'document.querySelector("#outerDiv").innerHTML="<div/>";')
with self.assertRaises(chromedriver.StaleElementReference):
elem.Click()
def testTouchDownMoveUpElement(self):
self._driver.Load(self.GetHttpUrlForFile(
'/chromedriver/touch_action_tests.html'))
target = self._driver.FindElement('css selector', '#target')
location = target.GetLocation()
self._driver.TouchDown(location['x'], location['y'])
events = self._driver.FindElement('css selector', '#events')
self.assertEquals('events: touchstart', events.GetText())
self._driver.TouchMove(location['x'] + 1, location['y'] + 1)
self.assertEquals('events: touchstart touchmove', events.GetText())
self._driver.TouchUp(location['x'] + 1, location['y'] + 1)
self.assertEquals('events: touchstart touchmove touchend', events.GetText())
def testGetElementRect(self):
self._driver.Load(self.GetHttpUrlForFile(
'/chromedriver/absolute_position_element.html'))
target = self._driver.FindElement('css selector', '#target')
rect = target.GetRect()
self.assertEquals(18, rect['x'])
self.assertEquals(10, rect['y'])
self.assertEquals(200, rect['height'])
self.assertEquals(210, rect['width'])
def testTouchFlickElement(self):
dx = 3
dy = 4
speed = 5
flickTouchEventsPerSecond = 30
moveEvents = int(
math.sqrt(dx * dx + dy * dy) * flickTouchEventsPerSecond / speed)
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html'))
div = self._driver.ExecuteScript(
'document.body.innerHTML = "<div>old</div>";'
'var div = document.getElementsByTagName("div")[0];'
'div.addEventListener("touchstart", function() {'
' div.innerHTML = "preMove0";'
'});'
'div.addEventListener("touchmove", function() {'
' res = div.innerHTML.match(/preMove(\d+)/);'
' if (res != null) {'
' div.innerHTML = "preMove" + (parseInt(res[1], 10) + 1);'
' }'
'});'
'div.addEventListener("touchend", function() {'
' if (div.innerHTML == "preMove' + str(moveEvents) + '") {'
' div.innerHTML = "new<br>";'
' }'
'});'
'return div;')
self._driver.TouchFlick(div, dx, dy, speed)
self.assertEquals(1, len(self._driver.FindElements('tag name', 'br')))
def testSwitchesToTopFrameAfterNavigation(self):
self._driver.Load('about:blank')
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/outer.html'))
frame = self._driver.FindElement('tag name', 'iframe')
self._driver.SwitchToFrame(frame)
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/outer.html'))
p = self._driver.FindElement('tag name', 'p')
self.assertEquals('Two', p.GetText())
def testSwitchesToTopFrameAfterRefresh(self):
self._driver.Load('about:blank')
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/outer.html'))
frame = self._driver.FindElement('tag name', 'iframe')
self._driver.SwitchToFrame(frame)
self._driver.Refresh()
p = self._driver.FindElement('tag name', 'p')
self.assertEquals('Two', p.GetText())
def testSwitchesToTopFrameAfterGoingBack(self):
self._driver.Load('about:blank')
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/outer.html'))
frame = self._driver.FindElement('tag name', 'iframe')
self._driver.SwitchToFrame(frame)
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/inner.html'))
self._driver.GoBack()
p = self._driver.FindElement('tag name', 'p')
self.assertEquals('Two', p.GetText())
def testCanSwitchToPrintPreviewDialog(self):
old_handles = self._driver.GetWindowHandles()
print("Test debug: actual len of old_handles: " + str(len(old_handles)),
file = sys.stdout)
self.assertEquals(1, len(old_handles))
self._driver.ExecuteScript('setTimeout(function(){window.print();}, 0);')
new_window_handle = self.WaitForNewWindow(self._driver, old_handles)
if new_window_handle is None:
print("Test debug: new_window_handle is None", file = sys.stdout)
else:
print("Test debug: new_window_handle is not None", file = sys.stdout)
self.assertNotEqual(None, new_window_handle)
self._driver.SwitchToWindow(new_window_handle)
print("Test debug: actual GetCurrentUrl: " + self._driver.GetCurrentUrl(),
file = sys.stdout)
self.assertEquals('chrome://print/', self._driver.GetCurrentUrl())
def testCanClickInIframes(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/nested.html'))
a = self._driver.FindElement('tag name', 'a')
a.Click()
frame_url = self._driver.ExecuteScript('return window.location.href')
self.assertTrue(frame_url.endswith('#one'))
frame = self._driver.FindElement('tag name', 'iframe')
self._driver.SwitchToFrame(frame)
a = self._driver.FindElement('tag name', 'a')
a.Click()
frame_url = self._driver.ExecuteScript('return window.location.href')
self.assertTrue(frame_url.endswith('#two'))
def testDoesntHangOnFragmentNavigation(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html'))
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html#x'))
def SetCookie(self, request):
return {'Set-Cookie': 'x=y; HttpOnly'}, "<!DOCTYPE html><html></html>"
def testGetHttpOnlyCookie(self):
self._http_server.SetCallbackForPath('/setCookie', self.SetCookie)
self._driver.Load(self.GetHttpUrlForFile('/setCookie'))
self._driver.AddCookie({'name': 'a', 'value': 'b'})
cookies = self._driver.GetCookies()
self.assertEquals(2, len(cookies))
for cookie in cookies:
self.assertIn('name', cookie)
if cookie['name'] == 'a':
self.assertFalse(cookie['httpOnly'])
elif cookie['name'] == 'x':
self.assertTrue(cookie['httpOnly'])
else:
self.fail('unexpected cookie: %s' % json.dumps(cookie))
def testCookiePath(self):
self._driver.Load(self.GetHttpUrlForFile(
'/chromedriver/long_url/empty.html'))
self._driver.AddCookie({'name': 'a', 'value': 'b'})
self._driver.AddCookie({
'name': 'x', 'value': 'y', 'path': '/chromedriver/long_url'})
cookies = self._driver.GetCookies()
self.assertEquals(2, len(cookies))
for cookie in cookies:
self.assertIn('path', cookie)
if cookie['name'] == 'a':
self.assertEquals('/' , cookie['path'])
if cookie['name'] == 'x':
self.assertEquals('/chromedriver/long_url' , cookie['path'])
def testGetNamedCookie(self):
self._driver.Load(self.GetHttpUrlForFile(
'/chromedriver/empty.html'))
self._driver.AddCookie({'name': 'a', 'value': 'b'})
named_cookie = self._driver.GetNamedCookie('a')
self.assertEquals('a' , named_cookie['name'])
self.assertEquals('b' , named_cookie['value'])
self.assertRaisesRegexp(
chromedriver.NoSuchCookie, "no such cookie",
self._driver.GetNamedCookie, 'foo')
def testDeleteCookie(self):
self._driver.Load(self.GetHttpUrlForFile(
'/chromedriver/empty.html'))
self._driver.AddCookie({'name': 'a', 'value': 'b'})
self._driver.AddCookie({'name': 'x', 'value': 'y'})
self._driver.AddCookie({'name': 'p', 'value': 'q'})
cookies = self._driver.GetCookies()
self.assertEquals(3, len(cookies))
self._driver.DeleteCookie('a')
self.assertEquals(2, len(self._driver.GetCookies()))
self._driver.DeleteAllCookies()
self.assertEquals(0, len(self._driver.GetCookies()))
def testCookieForFrame(self):
self._driver.Load(self.GetHttpUrlForFile(
'/chromedriver/cross_domain_iframe.html'))
self._driver.AddCookie({'name': 'outer', 'value': 'main context'})
frame = self._driver.FindElement('tag name', 'iframe')
self._driver.SwitchToFrame(frame)
self.assertTrue(self.WaitForCondition(
lambda: 'outer.html' in
self._driver.ExecuteScript('return window.location.href')))
self._driver.AddCookie({'name': 'inner', 'value': 'frame context'})
cookies = self._driver.GetCookies()
self.assertEquals(1, len(cookies))
self.assertEquals('inner', cookies[0]['name'])
self._driver.SwitchToMainFrame()
cookies = self._driver.GetCookies()
self.assertEquals(1, len(cookies))
self.assertEquals('outer', cookies[0]['name'])
def testCanClickAlertInIframes(self):
# This test requires that the page be loaded from a file:// URI, rather than
# the test HTTP server.
path = os.path.join(chrome_paths.GetTestData(), 'chromedriver',
'page_with_frame.html')
url = 'file://' + six.moves.urllib.request.pathname2url(path)
self._driver.Load(url)
frame = self._driver.FindElement('css selector', '#frm')
self._driver.SwitchToFrame(frame)
a = self._driver.FindElement('css selector', '#btn')
a.Click()
self.WaitForCondition(lambda: self._driver.IsAlertOpen())
self._driver.HandleAlert(True)
def testThrowErrorWithExecuteScript(self):
self.assertRaisesRegexp(
chromedriver.JavaScriptError, "some error",
self._driver.ExecuteScript, 'throw new Error("some error")')
def testDoesntCrashWhenScriptLogsUndefinedValue(self):
# https://bugs.chromium.org/p/chromedriver/issues/detail?id=1547
self._driver.ExecuteScript('var b; console.log(b);')
def testDoesntThrowWhenPageLogsUndefinedValue(self):
# https://bugs.chromium.org/p/chromedriver/issues/detail?id=1547
self._driver.Load(self.GetHttpUrlForFile(
'/chromedriver/log_undefined_value.html'))
def testCanSetCheckboxWithSpaceKey(self):
self._driver.Load('about:blank')
self._driver.ExecuteScript(
"document.body.innerHTML = '<input type=\"checkbox\">';")
checkbox = self._driver.FindElement('tag name', 'input')
self.assertFalse(
self._driver.ExecuteScript('return arguments[0].checked', checkbox))
checkbox.SendKeys(' ')
self.assertTrue(
self._driver.ExecuteScript('return arguments[0].checked', checkbox))
def testElementReference(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/element_ref.html'))
element = self._driver.FindElement('css selector', '#link')
self._driver.FindElements('tag name', 'br')
w3c_id_length = 36
if (self._driver.w3c_compliant):
self.assertEquals(len(element._id), w3c_id_length)
def testFindElementWhenElementIsOverridden(self):
self._driver.Load('about:blank')
self._driver.ExecuteScript(
'document.body.appendChild(document.createElement("a"));')
self._driver.ExecuteScript('window.Element = {}')
self.assertEquals(1, len(self._driver.FindElements('tag name', 'a')))
def testExecuteScriptWhenObjectPrototypeIsModified(self):
# Some JavaScript libraries (e.g. MooTools) do things like this. For context
# see https://bugs.chromium.org/p/chromedriver/issues/detail?id=1521
self._driver.Load('about:blank')
self._driver.ExecuteScript('Object.prototype.$family = undefined;')
self.assertEquals(1, self._driver.ExecuteScript('return 1;'))
def testWebWorkerFrames(self):
"""Verify web worker frames are handled correctly.
Regression test for bug
https://bugs.chromium.org/p/chromedriver/issues/detail?id=2340.
The bug was triggered by opening a page with web worker, and then opening a
page on a different site. We simulate a different site by using 'localhost'
as the host name (default is '127.0.0.1').
"""
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/web_worker.html'))