OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 """Performance tests for Chrome Endure (long-running perf tests on Chrome). | 6 """Performance tests for Chrome Endure (long-running perf tests on Chrome). |
7 | 7 |
8 This module accepts the following environment variable inputs: | 8 This module accepts the following environment variable inputs: |
9 TEST_LENGTH: The number of seconds in which to run each test. | 9 TEST_LENGTH: The number of seconds in which to run each test. |
10 PERF_STATS_INTERVAL: The number of seconds to wait in-between each sampling | 10 PERF_STATS_INTERVAL: The number of seconds to wait in-between each sampling |
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
595 | 595 |
596 _WEBAPP_NAME = 'Gmail' | 596 _WEBAPP_NAME = 'Gmail' |
597 _TAB_TITLE_SUBSTRING = 'Gmail' | 597 _TAB_TITLE_SUBSTRING = 'Gmail' |
598 _FRAME_XPATH = 'id("canvas_frame")' | 598 _FRAME_XPATH = 'id("canvas_frame")' |
599 | 599 |
600 def setUp(self): | 600 def setUp(self): |
601 ChromeEndureBaseTest.setUp(self) | 601 ChromeEndureBaseTest.setUp(self) |
602 | 602 |
603 # Log into a test Google account and open up Gmail. | 603 # Log into a test Google account and open up Gmail. |
604 self._LoginToGoogleAccount(account_key='test_google_account_gmail') | 604 self._LoginToGoogleAccount(account_key='test_google_account_gmail') |
605 self.NavigateToURL('http://www.gmail.com') | 605 self.NavigateToURL(self._GetConfig().get('gmail_url')) |
606 loaded_tab_title = self.GetActiveTabTitle() | 606 self.assertTrue( |
607 self.assertTrue(self._TAB_TITLE_SUBSTRING in loaded_tab_title, | 607 self.WaitUntil(lambda: self._TAB_TITLE_SUBSTRING in |
608 msg='Loaded tab title does not contain "%s": "%s"' % | 608 self.GetActiveTabTitle(), |
609 (self._TAB_TITLE_SUBSTRING, loaded_tab_title)) | 609 timeout=60, expect_retval=True, retry_sleep=1), |
610 msg='Timed out waiting for Gmail to load. Tab title is: %s' % | |
611 self.GetActiveTabTitle()) | |
610 | 612 |
611 self._driver = self.NewWebDriver() | 613 self._driver = self.NewWebDriver() |
612 # Any call to wait.until() will raise an exception if the timeout is hit. | 614 # Any call to wait.until() will raise an exception if the timeout is hit. |
613 # TODO(dennisjeffrey): Remove the need for webdriver's wait using the new | 615 # TODO(dennisjeffrey): Remove the need for webdriver's wait using the new |
614 # DOM mutation observer mechanism. | 616 # DOM mutation observer mechanism. |
615 self._wait = WebDriverWait(self._driver, timeout=60) | 617 self._wait = WebDriverWait(self._driver, timeout=60) |
616 | 618 |
617 # Wait until Gmail's 'canvas_frame' loads and the 'Inbox' link is present. | 619 # Wait until Gmail's 'canvas_frame' loads and the 'Inbox' link is present. |
618 # TODO(dennisjeffrey): Check with the Gmail team to see if there's a better | 620 # TODO(dennisjeffrey): Check with the Gmail team to see if there's a better |
619 # way to tell when the webpage is ready for user interaction. | 621 # way to tell when the webpage is ready for user interaction. |
620 self._wait.until( | 622 self._wait.until( |
621 self._SwitchToCanvasFrame) # Raises exception if the timeout is hit. | 623 self._SwitchToCanvasFrame) # Raises exception if the timeout is hit. |
622 # Wait for the inbox to appear. | 624 # Wait for the inbox to appear. |
623 self.WaitForDomNode('//a[starts-with(@title, "Inbox")]', | 625 self.WaitForDomNode('//a[starts-with(@title, "Inbox")]', |
624 frame_xpath=self._FRAME_XPATH) | 626 frame_xpath=self._FRAME_XPATH) |
627 # Test whether latency dom element is available. | |
dennis_jeffrey
2012/08/17 17:35:44
nit: add a blank line above this to separate the l
fdeng1
2012/08/17 23:19:37
Done.
| |
628 try: | |
629 self._GetLatencyDomElement(3000) | |
630 self._has_latency = True | |
631 except pyauto_errors.JSONInterfaceError: | |
632 logging.info('Skip recording latency as latency ' + | |
633 'dom element is not available.') | |
634 self._has_latency = False | |
625 | 635 |
626 def _SwitchToCanvasFrame(self, driver): | 636 def _SwitchToCanvasFrame(self, driver): |
627 """Switch the WebDriver to Gmail's 'canvas_frame', if it's available. | 637 """Switch the WebDriver to Gmail's 'canvas_frame', if it's available. |
628 | 638 |
629 Args: | 639 Args: |
630 driver: A selenium.webdriver.remote.webdriver.WebDriver object. | 640 driver: A selenium.webdriver.remote.webdriver.WebDriver object. |
631 | 641 |
632 Returns: | 642 Returns: |
633 True, if the switch to Gmail's 'canvas_frame' is successful, or | 643 True, if the switch to Gmail's 'canvas_frame' is successful, or |
634 False if not. | 644 False if not. |
635 """ | 645 """ |
636 try: | 646 try: |
637 driver.switch_to_frame('canvas_frame') | 647 driver.switch_to_frame('canvas_frame') |
638 return True | 648 return True |
639 except selenium.common.exceptions.NoSuchFrameException: | 649 except selenium.common.exceptions.NoSuchFrameException: |
640 return False | 650 return False |
641 | 651 |
642 def _GetLatencyDomElement(self): | 652 def _GetLatencyDomElement(self, timeout=-1): |
643 """Returns a reference to the latency info element in the Gmail DOM.""" | 653 """Returns a reference to the latency info element in the Gmail DOM. |
654 | |
655 Args: | |
656 timeout: The maximum amount of time (in milliseconds) to wait for | |
657 the latency dom element to appear. | |
dennis_jeffrey
2012/08/17 17:35:44
describe what happens with the default value of -1
fdeng1
2012/08/17 23:19:37
Done.
| |
658 Returns: | |
659 A latency dom element. | |
660 """ | |
644 latency_xpath = ( | 661 latency_xpath = ( |
645 '//span[starts-with(text(), "Why was the last action slow?")]') | 662 '//span[starts-with(text(), "Why was the last action slow?")]') |
646 self.WaitForDomNode(latency_xpath, frame_xpath=self._FRAME_XPATH) | 663 self.WaitForDomNode(latency_xpath, timeout=timeout, |
664 frame_xpath=self._FRAME_XPATH) | |
647 return self._GetElement(self._driver.find_element_by_xpath, latency_xpath) | 665 return self._GetElement(self._driver.find_element_by_xpath, latency_xpath) |
648 | 666 |
649 def _WaitUntilDomElementRemoved(self, dom_element): | 667 def _WaitUntilDomElementRemoved(self, dom_element): |
650 """Waits until the given element is no longer attached to the DOM. | 668 """Waits until the given element is no longer attached to the DOM. |
651 | 669 |
652 Args: | 670 Args: |
653 dom_element: A selenium.webdriver.remote.WebElement object. | 671 dom_element: A selenium.webdriver.remote.WebElement object. |
654 """ | 672 """ |
655 def _IsElementStale(): | 673 def _IsElementStale(): |
656 try: | 674 try: |
(...skipping 12 matching lines...) Expand all Loading... | |
669 minute of test execution are not recorded. | 687 minute of test execution are not recorded. |
670 | 688 |
671 Args: | 689 Args: |
672 element: A selenium.webdriver.remote.WebElement object to click. | 690 element: A selenium.webdriver.remote.WebElement object to click. |
673 test_description: A string description of what the test does, used for | 691 test_description: A string description of what the test does, used for |
674 outputting results to be graphed. Should not contain spaces. For | 692 outputting results to be graphed. Should not contain spaces. For |
675 example, 'ComposeDiscard' for Gmail. | 693 example, 'ComposeDiscard' for Gmail. |
676 action_description: A string description of what action is being | 694 action_description: A string description of what action is being |
677 performed. Should not contain spaces. For example, 'Compose'. | 695 performed. Should not contain spaces. For example, 'Compose'. |
678 """ | 696 """ |
697 if not self._has_latency: | |
698 element.click() | |
699 return | |
679 latency_dom_element = self._GetLatencyDomElement() | 700 latency_dom_element = self._GetLatencyDomElement() |
680 element.click() | 701 element.click() |
681 # Wait for the old latency value to be removed, before getting the new one. | 702 # Wait for the old latency value to be removed, before getting the new one. |
682 self._WaitUntilDomElementRemoved(latency_dom_element) | 703 self._WaitUntilDomElementRemoved(latency_dom_element) |
683 | 704 |
684 latency_dom_element = self._GetLatencyDomElement() | 705 latency_dom_element = self._GetLatencyDomElement() |
685 match = re.search(r'\[(\d+) ms\]', latency_dom_element.text) | 706 match = re.search(r'\[(\d+) ms\]', latency_dom_element.text) |
686 if match: | 707 if match: |
687 latency = int(match.group(1)) | 708 latency = int(match.group(1)) |
688 elapsed_time = int(round(time.time() - self._test_start_time)) | 709 elapsed_time = int(round(time.time() - self._test_start_time)) |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
933 """Long-running performance tests for Chrome using Google Docs.""" | 954 """Long-running performance tests for Chrome using Google Docs.""" |
934 | 955 |
935 _WEBAPP_NAME = 'Docs' | 956 _WEBAPP_NAME = 'Docs' |
936 _TAB_TITLE_SUBSTRING = 'Google Drive' | 957 _TAB_TITLE_SUBSTRING = 'Google Drive' |
937 | 958 |
938 def setUp(self): | 959 def setUp(self): |
939 ChromeEndureBaseTest.setUp(self) | 960 ChromeEndureBaseTest.setUp(self) |
940 | 961 |
941 # Log into a test Google account and open up Google Docs. | 962 # Log into a test Google account and open up Google Docs. |
942 self._LoginToGoogleAccount() | 963 self._LoginToGoogleAccount() |
943 self.NavigateToURL('http://docs.google.com') | 964 self.NavigateToURL(self._GetConfig().get('docs_url')) |
944 self.assertTrue( | 965 self.assertTrue( |
945 self.WaitUntil(lambda: self._TAB_TITLE_SUBSTRING in | 966 self.WaitUntil(lambda: self._TAB_TITLE_SUBSTRING in |
946 self.GetActiveTabTitle(), | 967 self.GetActiveTabTitle(), |
947 timeout=60, expect_retval=True, retry_sleep=1), | 968 timeout=60, expect_retval=True, retry_sleep=1), |
948 msg='Timed out waiting for Docs to load. Tab title is: %s' % | 969 msg='Timed out waiting for Docs to load. Tab title is: %s' % |
949 self.GetActiveTabTitle()) | 970 self.GetActiveTabTitle()) |
950 | 971 |
951 self._driver = self.NewWebDriver() | 972 self._driver = self.NewWebDriver() |
952 | 973 |
953 def testDocsAlternatelyClickLists(self): | 974 def testDocsAlternatelyClickLists(self): |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1005 """Long-running performance tests for Chrome using Google Plus.""" | 1026 """Long-running performance tests for Chrome using Google Plus.""" |
1006 | 1027 |
1007 _WEBAPP_NAME = 'Plus' | 1028 _WEBAPP_NAME = 'Plus' |
1008 _TAB_TITLE_SUBSTRING = 'Google+' | 1029 _TAB_TITLE_SUBSTRING = 'Google+' |
1009 | 1030 |
1010 def setUp(self): | 1031 def setUp(self): |
1011 ChromeEndureBaseTest.setUp(self) | 1032 ChromeEndureBaseTest.setUp(self) |
1012 | 1033 |
1013 # Log into a test Google account and open up Google Plus. | 1034 # Log into a test Google account and open up Google Plus. |
1014 self._LoginToGoogleAccount() | 1035 self._LoginToGoogleAccount() |
1015 self.NavigateToURL('http://plus.google.com') | 1036 self.NavigateToURL(self._GetConfig().get('plus_url')) |
1016 loaded_tab_title = self.GetActiveTabTitle() | 1037 loaded_tab_title = self.GetActiveTabTitle() |
1017 self.assertTrue(self._TAB_TITLE_SUBSTRING in loaded_tab_title, | 1038 self.assertTrue(self._TAB_TITLE_SUBSTRING in loaded_tab_title, |
1018 msg='Loaded tab title does not contain "%s": "%s"' % | 1039 msg='Loaded tab title does not contain "%s": "%s"' % |
1019 (self._TAB_TITLE_SUBSTRING, loaded_tab_title)) | 1040 (self._TAB_TITLE_SUBSTRING, loaded_tab_title)) |
1020 | 1041 |
1021 self._driver = self.NewWebDriver() | 1042 self._driver = self.NewWebDriver() |
1022 | 1043 |
1023 def testPlusAlternatelyClickStreams(self): | 1044 def testPlusAlternatelyClickStreams(self): |
1024 """Alternates between two different streams. | 1045 """Alternates between two different streams. |
1025 | 1046 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1118 self._num_errors += 1 | 1139 self._num_errors += 1 |
1119 | 1140 |
1120 time.sleep(1) | 1141 time.sleep(1) |
1121 | 1142 |
1122 self._RunEndureTest(self._WEBAPP_NAME, self._TAB_TITLE_SUBSTRING, | 1143 self._RunEndureTest(self._WEBAPP_NAME, self._TAB_TITLE_SUBSTRING, |
1123 test_description, scenario) | 1144 test_description, scenario) |
1124 | 1145 |
1125 | 1146 |
1126 if __name__ == '__main__': | 1147 if __name__ == '__main__': |
1127 pyauto_functional.Main() | 1148 pyauto_functional.Main() |
OLD | NEW |