OLD | NEW |
---|---|
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 791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
802 | 802 |
803 Verifies that a log message is written into the specified log file. | 803 Verifies that a log message is written into the specified log file. |
804 """ | 804 """ |
805 tmp_log_path = tempfile.NamedTemporaryFile() | 805 tmp_log_path = tempfile.NamedTemporaryFile() |
806 driver = self.CreateDriver(chrome_log_path=tmp_log_path.name) | 806 driver = self.CreateDriver(chrome_log_path=tmp_log_path.name) |
807 driver.ExecuteScript('console.info("%s")' % self.LOG_MESSAGE) | 807 driver.ExecuteScript('console.info("%s")' % self.LOG_MESSAGE) |
808 driver.Quit() | 808 driver.Quit() |
809 self.assertTrue(self.LOG_MESSAGE in open(tmp_log_path.name).read()) | 809 self.assertTrue(self.LOG_MESSAGE in open(tmp_log_path.name).read()) |
810 | 810 |
811 | 811 |
812 class MobileEmulationCapabilityTest(ChromeDriverBaseTest): | |
813 """Tests that ChromeDriver processes chromeOptions.mobileEmulation. | |
814 | |
815 Makes sure the device metrics are overridden in DevTools and user agent is | |
816 overridden in Chrome. | |
817 """ | |
818 | |
819 @staticmethod | |
820 def GlobalSetUp(): | |
821 MobileEmulationCapabilityTest._http_server = webserver.WebServer( | |
822 chrome_paths.GetTestData()) | |
823 MobileEmulationCapabilityTest._http_server.SetCallbackForPath( | |
824 '/userAgent', MobileEmulationCapabilityTest.respondWithUserAgentString) | |
825 | |
826 @staticmethod | |
827 def GlobalTearDown(): | |
828 MobileEmulationCapabilityTest._http_server.Shutdown() | |
829 | |
830 @staticmethod | |
831 def respondWithUserAgentString(request): | |
stgao
2014/05/14 05:10:14
This method could be moved into GlobalSetUp, as it
sam.rawlins
2014/05/16 21:09:38
Done.
| |
832 return request.GetHeader('User-Agent') | |
833 | |
834 def testDeviceMetrics(self): | |
835 driver = self.CreateDriver( | |
836 mobile_emulation = { | |
837 'deviceMetrics': {'width': 360, 'height': 640, 'pixelRatio': 3}}) | |
838 self.assertEqual(360, driver.ExecuteScript('return window.innerWidth')) | |
839 self.assertEqual(640, driver.ExecuteScript('return window.innerHeight')) | |
840 | |
841 def testUserAgent(self): | |
842 driver = self.CreateDriver( | |
843 mobile_emulation = {'userAgent': 'Agent Smith'}) | |
844 driver.Load(self._http_server.GetUrl() + '/userAgent') | |
845 body_tag = driver.FindElement('tag name', 'body') | |
846 self.assertEqual("'Agent Smith'", body_tag.GetText()) | |
847 | |
848 def testDeviceName(self): | |
849 driver = self.CreateDriver( | |
850 mobile_emulation = {'deviceName': 'Google Nexus 5'}) | |
851 driver.Load(self._http_server.GetUrl() + '/userAgent') | |
852 self.assertEqual(360, driver.ExecuteScript('return window.innerWidth')) | |
853 self.assertEqual(640, driver.ExecuteScript('return window.innerHeight')) | |
854 body_tag = driver.FindElement('tag name', 'body') | |
855 self.assertEqual( | |
856 "'Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleW ebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19'", | |
stgao
2014/05/14 05:10:14
over 80 chars.
We use 'str' instead of "str".
It
sam.rawlins
2014/05/16 21:09:38
Done.
| |
857 body_tag.GetText()) | |
858 | |
859 | |
812 class ChromeDriverLogTest(unittest.TestCase): | 860 class ChromeDriverLogTest(unittest.TestCase): |
813 """Tests that chromedriver produces the expected log file.""" | 861 """Tests that chromedriver produces the expected log file.""" |
814 | 862 |
815 UNEXPECTED_CHROMEOPTION_CAP = 'unexpected_chromeoption_capability' | 863 UNEXPECTED_CHROMEOPTION_CAP = 'unexpected_chromeoption_capability' |
816 LOG_MESSAGE = 'unrecognized chrome option: %s' % UNEXPECTED_CHROMEOPTION_CAP | 864 LOG_MESSAGE = 'unrecognized chrome option: %s' % UNEXPECTED_CHROMEOPTION_CAP |
817 | 865 |
818 def testChromeDriverLog(self): | 866 def testChromeDriverLog(self): |
819 _, tmp_log_path = tempfile.mkstemp(prefix='chromedriver_log_') | 867 _, tmp_log_path = tempfile.mkstemp(prefix='chromedriver_log_') |
820 chromedriver_server = server.Server( | 868 chromedriver_server = server.Server( |
821 _CHROMEDRIVER_BINARY, log_path=tmp_log_path) | 869 _CHROMEDRIVER_BINARY, log_path=tmp_log_path) |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
995 if _ANDROID_PACKAGE_KEY: | 1043 if _ANDROID_PACKAGE_KEY: |
996 negative_filter = _ANDROID_NEGATIVE_FILTER[_ANDROID_PACKAGE_KEY] | 1044 negative_filter = _ANDROID_NEGATIVE_FILTER[_ANDROID_PACKAGE_KEY] |
997 else: | 1045 else: |
998 negative_filter = _GetDesktopNegativeFilter(options.chrome_version) | 1046 negative_filter = _GetDesktopNegativeFilter(options.chrome_version) |
999 options.filter = '*-' + ':__main__.'.join([''] + negative_filter) | 1047 options.filter = '*-' + ':__main__.'.join([''] + negative_filter) |
1000 | 1048 |
1001 all_tests_suite = unittest.defaultTestLoader.loadTestsFromModule( | 1049 all_tests_suite = unittest.defaultTestLoader.loadTestsFromModule( |
1002 sys.modules[__name__]) | 1050 sys.modules[__name__]) |
1003 tests = unittest_util.FilterTestSuite(all_tests_suite, options.filter) | 1051 tests = unittest_util.FilterTestSuite(all_tests_suite, options.filter) |
1004 ChromeDriverTest.GlobalSetUp() | 1052 ChromeDriverTest.GlobalSetUp() |
1053 MobileEmulationCapabilityTest.GlobalSetUp() | |
1005 result = unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run(tests) | 1054 result = unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run(tests) |
1006 ChromeDriverTest.GlobalTearDown() | 1055 ChromeDriverTest.GlobalTearDown() |
1056 MobileEmulationCapabilityTest.GlobalTearDown() | |
1007 sys.exit(len(result.failures) + len(result.errors)) | 1057 sys.exit(len(result.failures) + len(result.errors)) |
OLD | NEW |