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 1818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1829 | 1829 |
1830 Verifies that a log message is written into the specified log file. | 1830 Verifies that a log message is written into the specified log file. |
1831 """ | 1831 """ |
1832 tmp_log_path = tempfile.NamedTemporaryFile() | 1832 tmp_log_path = tempfile.NamedTemporaryFile() |
1833 driver = self.CreateDriver(chrome_log_path=tmp_log_path.name) | 1833 driver = self.CreateDriver(chrome_log_path=tmp_log_path.name) |
1834 driver.ExecuteScript('console.info("%s")' % self.LOG_MESSAGE) | 1834 driver.ExecuteScript('console.info("%s")' % self.LOG_MESSAGE) |
1835 driver.Quit() | 1835 driver.Quit() |
1836 self.assertTrue(self.LOG_MESSAGE in open(tmp_log_path.name).read()) | 1836 self.assertTrue(self.LOG_MESSAGE in open(tmp_log_path.name).read()) |
1837 | 1837 |
1838 | 1838 |
1839 class MobileEmulationCapabilityTest(ChromeDriverBaseTest): | 1839 class MobileEmulationCapabilityTest(ChromeDriverBaseTestWithWebServer): |
1840 """Tests that ChromeDriver processes chromeOptions.mobileEmulation. | 1840 """Tests that ChromeDriver processes chromeOptions.mobileEmulation. |
1841 | 1841 |
1842 Makes sure the device metrics are overridden in DevTools and user agent is | 1842 Makes sure the device metrics are overridden in DevTools and user agent is |
1843 overridden in Chrome. | 1843 overridden in Chrome. |
1844 """ | 1844 """ |
1845 | 1845 |
1846 @staticmethod | 1846 @staticmethod |
1847 def GlobalSetUp(): | 1847 def GlobalSetUp(): |
1848 def respondWithUserAgentString(request): | 1848 def respondWithUserAgentString(request): |
1849 return {}, """ | 1849 return {}, """ |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1898 self.assertEqual(360, driver.ExecuteScript('return window.screen.width')) | 1898 self.assertEqual(360, driver.ExecuteScript('return window.screen.width')) |
1899 self.assertEqual(640, driver.ExecuteScript('return window.screen.height')) | 1899 self.assertEqual(640, driver.ExecuteScript('return window.screen.height')) |
1900 | 1900 |
1901 def testUserAgent(self): | 1901 def testUserAgent(self): |
1902 driver = self.CreateDriver( | 1902 driver = self.CreateDriver( |
1903 mobile_emulation = {'userAgent': 'Agent Smith'}) | 1903 mobile_emulation = {'userAgent': 'Agent Smith'}) |
1904 driver.Load(self._http_server.GetUrl() + '/userAgent') | 1904 driver.Load(self._http_server.GetUrl() + '/userAgent') |
1905 body_tag = driver.FindElement('tag name', 'body') | 1905 body_tag = driver.FindElement('tag name', 'body') |
1906 self.assertEqual("Agent Smith", body_tag.GetText()) | 1906 self.assertEqual("Agent Smith", body_tag.GetText()) |
1907 | 1907 |
1908 def testUserAgentNewTab(self): | |
1909 driver = self.CreateDriver( | |
1910 mobile_emulation = {'userAgent': 'Agent Smith'}) | |
1911 driver.Load(self.GetHttpUrlForFile('/chromedriver/newtab.html')) | |
1912 old_windows = driver.GetWindowHandles() | |
1913 link = driver.FindElements('tag name', 'a')[0] | |
1914 driver.MouseMoveTo(link) | |
1915 driver.MouseClick() | |
stgao
2017/04/05 04:17:08
What's the user-agent if the new tab itself direct
irisu
2017/04/05 06:44:33
Sorry for that misunderstanding. Modified the test
Sami
2017/04/05 13:52:04
Right, looks like we need to support a default use
| |
1916 new_window = self.WaitForNewWindow(driver, old_windows) | |
1917 driver.SwitchToWindow(new_window) | |
1918 driver.Load(self._http_server.GetUrl() + '/userAgent') | |
stgao
2017/04/05 04:17:08
Before this load, we already instruct the new tab
| |
1919 body_tag = driver.FindElement('tag name', 'body') | |
1920 self.assertEqual("Agent Smith", body_tag.GetText()) | |
1921 | |
1908 def testDeviceName(self): | 1922 def testDeviceName(self): |
1909 driver = self.CreateDriver( | 1923 driver = self.CreateDriver( |
1910 mobile_emulation = {'deviceName': 'Google Nexus 5'}) | 1924 mobile_emulation = {'deviceName': 'Google Nexus 5'}) |
1911 driver.Load(self._http_server.GetUrl() + '/userAgentUseDeviceWidth') | 1925 driver.Load(self._http_server.GetUrl() + '/userAgentUseDeviceWidth') |
1912 self.assertEqual(360, driver.ExecuteScript('return window.screen.width')) | 1926 self.assertEqual(360, driver.ExecuteScript('return window.screen.width')) |
1913 self.assertEqual(640, driver.ExecuteScript('return window.screen.height')) | 1927 self.assertEqual(640, driver.ExecuteScript('return window.screen.height')) |
1914 body_tag = driver.FindElement('tag name', 'body') | 1928 body_tag = driver.FindElement('tag name', 'body') |
1915 self.assertEqual( | 1929 self.assertEqual( |
1916 'Mozilla/5.0 (Linux; Android 4.4.4; Nexus 5 Build/KTU84P) ' | 1930 'Mozilla/5.0 (Linux; Android 4.4.4; Nexus 5 Build/KTU84P) ' |
1917 'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.114 Mobile ' | 1931 'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.114 Mobile ' |
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2418 | 2432 |
2419 all_tests_suite = unittest.defaultTestLoader.loadTestsFromModule( | 2433 all_tests_suite = unittest.defaultTestLoader.loadTestsFromModule( |
2420 sys.modules[__name__]) | 2434 sys.modules[__name__]) |
2421 tests = unittest_util.FilterTestSuite(all_tests_suite, options.filter) | 2435 tests = unittest_util.FilterTestSuite(all_tests_suite, options.filter) |
2422 ChromeDriverTest.GlobalSetUp() | 2436 ChromeDriverTest.GlobalSetUp() |
2423 MobileEmulationCapabilityTest.GlobalSetUp() | 2437 MobileEmulationCapabilityTest.GlobalSetUp() |
2424 result = unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run(tests) | 2438 result = unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run(tests) |
2425 ChromeDriverTest.GlobalTearDown() | 2439 ChromeDriverTest.GlobalTearDown() |
2426 MobileEmulationCapabilityTest.GlobalTearDown() | 2440 MobileEmulationCapabilityTest.GlobalTearDown() |
2427 sys.exit(len(result.failures) + len(result.errors)) | 2441 sys.exit(len(result.failures) + len(result.errors)) |
OLD | NEW |