Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: chrome/test/chromedriver/test/run_py_tests.py

Issue 288193004: [Chromedriver] Add Device Metrics override support to ChromeDriver via Capabilities (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2013 The Chromium Authors. All rights reserved. 2 # Copyright 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """End to end tests for ChromeDriver.""" 6 """End to end tests for ChromeDriver."""
7 7
8 import base64 8 import base64
9 import json 9 import json
10 import math 10 import math
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 return filter 93 return filter
94 94
95 _ANDROID_NEGATIVE_FILTER = {} 95 _ANDROID_NEGATIVE_FILTER = {}
96 _ANDROID_NEGATIVE_FILTER['chrome'] = ( 96 _ANDROID_NEGATIVE_FILTER['chrome'] = (
97 _NEGATIVE_FILTER + [ 97 _NEGATIVE_FILTER + [
98 # TODO(chrisgao): fix hang of tab crash test on android. 98 # TODO(chrisgao): fix hang of tab crash test on android.
99 'ChromeDriverTest.testTabCrash', 99 'ChromeDriverTest.testTabCrash',
100 # Android doesn't support switches and extensions. 100 # Android doesn't support switches and extensions.
101 'ChromeSwitchesCapabilityTest.*', 101 'ChromeSwitchesCapabilityTest.*',
102 'ChromeExtensionsCapabilityTest.*', 102 'ChromeExtensionsCapabilityTest.*',
103 'MobileEmulationCapabilityTest.*',
103 # https://crbug.com/274650 104 # https://crbug.com/274650
104 'ChromeDriverTest.testCloseWindow', 105 'ChromeDriverTest.testCloseWindow',
105 # https://code.google.com/p/chromedriver/issues/detail?id=270 106 # https://code.google.com/p/chromedriver/issues/detail?id=270
106 'ChromeDriverTest.testPopups', 107 'ChromeDriverTest.testPopups',
107 # https://code.google.com/p/chromedriver/issues/detail?id=298 108 # https://code.google.com/p/chromedriver/issues/detail?id=298
108 'ChromeDriverTest.testWindowPosition', 109 'ChromeDriverTest.testWindowPosition',
109 'ChromeDriverTest.testWindowSize', 110 'ChromeDriverTest.testWindowSize',
110 'ChromeDriverTest.testWindowMaximize', 111 'ChromeDriverTest.testWindowMaximize',
111 'ChromeLogPathCapabilityTest.testChromeLogPath', 112 'ChromeLogPathCapabilityTest.testChromeLogPath',
112 'ExistingBrowserTest.*', 113 'ExistingBrowserTest.*',
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 # When 31 is released, will reload the tab instead. 702 # When 31 is released, will reload the tab instead.
702 # https://code.google.com/p/chromedriver/issues/detail?id=547 703 # https://code.google.com/p/chromedriver/issues/detail?id=547
703 self.assertRaises(chromedriver.UnknownError, 704 self.assertRaises(chromedriver.UnknownError,
704 self._driver.Load, 'chrome://crash') 705 self._driver.Load, 'chrome://crash')
705 self.assertRaises(chromedriver.NoSuchSession, 706 self.assertRaises(chromedriver.NoSuchSession,
706 self._driver.GetCurrentUrl) 707 self._driver.GetCurrentUrl)
707 708
708 def testDoesntHangOnDebugger(self): 709 def testDoesntHangOnDebugger(self):
709 self._driver.ExecuteScript('debugger;') 710 self._driver.ExecuteScript('debugger;')
710 711
712 def testMobileEmulationDisabledByDefault(self):
713 self.assertFalse(self._driver.capabilities['mobileEmulationEnabled'])
714
711 715
712 class ChromeDriverAndroidTest(ChromeDriverBaseTest): 716 class ChromeDriverAndroidTest(ChromeDriverBaseTest):
713 """End to end tests for Android-specific tests.""" 717 """End to end tests for Android-specific tests."""
714 718
715 def testLatestAndroidAppInstalled(self): 719 def testLatestAndroidAppInstalled(self):
716 if ('stable' not in _ANDROID_PACKAGE_KEY and 720 if ('stable' not in _ANDROID_PACKAGE_KEY and
717 'beta' not in _ANDROID_PACKAGE_KEY): 721 'beta' not in _ANDROID_PACKAGE_KEY):
718 return 722 return
719 723
720 self._driver = self.CreateDriver() 724 self._driver = self.CreateDriver()
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 806
803 Verifies that a log message is written into the specified log file. 807 Verifies that a log message is written into the specified log file.
804 """ 808 """
805 tmp_log_path = tempfile.NamedTemporaryFile() 809 tmp_log_path = tempfile.NamedTemporaryFile()
806 driver = self.CreateDriver(chrome_log_path=tmp_log_path.name) 810 driver = self.CreateDriver(chrome_log_path=tmp_log_path.name)
807 driver.ExecuteScript('console.info("%s")' % self.LOG_MESSAGE) 811 driver.ExecuteScript('console.info("%s")' % self.LOG_MESSAGE)
808 driver.Quit() 812 driver.Quit()
809 self.assertTrue(self.LOG_MESSAGE in open(tmp_log_path.name).read()) 813 self.assertTrue(self.LOG_MESSAGE in open(tmp_log_path.name).read())
810 814
811 815
816 class MobileEmulationCapabilityTest(ChromeDriverBaseTest):
817 """Tests that ChromeDriver processes chromeOptions.mobileEmulation.
818
819 Makes sure the device metrics are overridden in DevTools and user agent is
820 overridden in Chrome.
821 """
822
823 @staticmethod
824 def GlobalSetUp():
825 def respondWithUserAgentString(request):
826 return request.GetHeader('User-Agent')
827
828 MobileEmulationCapabilityTest._http_server = webserver.WebServer(
829 chrome_paths.GetTestData())
830 MobileEmulationCapabilityTest._http_server.SetCallbackForPath(
831 '/userAgent', respondWithUserAgentString)
832
833 @staticmethod
834 def GlobalTearDown():
835 MobileEmulationCapabilityTest._http_server.Shutdown()
836
837 def testDeviceMetrics(self):
838 driver = self.CreateDriver(
839 mobile_emulation = {
840 'deviceMetrics': {'width': 360, 'height': 640, 'pixelRatio': 3}})
841 self.assertTrue(driver.capabilities['mobileEmulationEnabled'])
842 self.assertEqual(360, driver.ExecuteScript('return window.innerWidth'))
843 self.assertEqual(640, driver.ExecuteScript('return window.innerHeight'))
844
845 def testUserAgent(self):
846 driver = self.CreateDriver(
847 mobile_emulation = {'userAgent': 'Agent Smith'})
848 driver.Load(self._http_server.GetUrl() + '/userAgent')
849 body_tag = driver.FindElement('tag name', 'body')
850 self.assertEqual("Agent Smith", body_tag.GetText())
851
852 def testDeviceName(self):
stgao 2014/05/22 05:02:22 It seems this testcase keeps failing on Chrome 33,
853 driver = self.CreateDriver(
854 mobile_emulation = {'deviceName': 'Google Nexus 5'})
855 driver.Load(self._http_server.GetUrl() + '/userAgent')
856 self.assertEqual(360, driver.ExecuteScript('return window.innerWidth'))
857 self.assertEqual(640, driver.ExecuteScript('return window.innerHeight'))
858 body_tag = driver.FindElement('tag name', 'body')
859 self.assertEqual(
860 'Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleW'
861 'ebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/53'
862 '5.19',
863 body_tag.GetText())
864
865
812 class ChromeDriverLogTest(unittest.TestCase): 866 class ChromeDriverLogTest(unittest.TestCase):
813 """Tests that chromedriver produces the expected log file.""" 867 """Tests that chromedriver produces the expected log file."""
814 868
815 UNEXPECTED_CHROMEOPTION_CAP = 'unexpected_chromeoption_capability' 869 UNEXPECTED_CHROMEOPTION_CAP = 'unexpected_chromeoption_capability'
816 LOG_MESSAGE = 'unrecognized chrome option: %s' % UNEXPECTED_CHROMEOPTION_CAP 870 LOG_MESSAGE = 'unrecognized chrome option: %s' % UNEXPECTED_CHROMEOPTION_CAP
817 871
818 def testChromeDriverLog(self): 872 def testChromeDriverLog(self):
819 _, tmp_log_path = tempfile.mkstemp(prefix='chromedriver_log_') 873 _, tmp_log_path = tempfile.mkstemp(prefix='chromedriver_log_')
820 chromedriver_server = server.Server( 874 chromedriver_server = server.Server(
821 _CHROMEDRIVER_BINARY, log_path=tmp_log_path) 875 _CHROMEDRIVER_BINARY, log_path=tmp_log_path)
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 if _ANDROID_PACKAGE_KEY: 1049 if _ANDROID_PACKAGE_KEY:
996 negative_filter = _ANDROID_NEGATIVE_FILTER[_ANDROID_PACKAGE_KEY] 1050 negative_filter = _ANDROID_NEGATIVE_FILTER[_ANDROID_PACKAGE_KEY]
997 else: 1051 else:
998 negative_filter = _GetDesktopNegativeFilter(options.chrome_version) 1052 negative_filter = _GetDesktopNegativeFilter(options.chrome_version)
999 options.filter = '*-' + ':__main__.'.join([''] + negative_filter) 1053 options.filter = '*-' + ':__main__.'.join([''] + negative_filter)
1000 1054
1001 all_tests_suite = unittest.defaultTestLoader.loadTestsFromModule( 1055 all_tests_suite = unittest.defaultTestLoader.loadTestsFromModule(
1002 sys.modules[__name__]) 1056 sys.modules[__name__])
1003 tests = unittest_util.FilterTestSuite(all_tests_suite, options.filter) 1057 tests = unittest_util.FilterTestSuite(all_tests_suite, options.filter)
1004 ChromeDriverTest.GlobalSetUp() 1058 ChromeDriverTest.GlobalSetUp()
1059 MobileEmulationCapabilityTest.GlobalSetUp()
1005 result = unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run(tests) 1060 result = unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run(tests)
1006 ChromeDriverTest.GlobalTearDown() 1061 ChromeDriverTest.GlobalTearDown()
1062 MobileEmulationCapabilityTest.GlobalTearDown()
1007 sys.exit(len(result.failures) + len(result.errors)) 1063 sys.exit(len(result.failures) + len(result.errors))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698