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 15 matching lines...) Expand all Loading... | |
26 import time | 26 import time |
27 | 27 |
28 import perf | 28 import perf |
29 import pyauto_functional # Must be imported before pyauto. | 29 import pyauto_functional # Must be imported before pyauto. |
30 import pyauto | 30 import pyauto |
31 import pyauto_errors | 31 import pyauto_errors |
32 import pyauto_utils | 32 import pyauto_utils |
33 import remote_inspector_client | 33 import remote_inspector_client |
34 import selenium.common.exceptions | 34 import selenium.common.exceptions |
35 from selenium.webdriver.support.ui import WebDriverWait | 35 from selenium.webdriver.support.ui import WebDriverWait |
36 | 36 import test_utils |
37 | 37 |
38 class NotSupportedEnvironmentError(RuntimeError): | 38 class NotSupportedEnvironmentError(RuntimeError): |
39 """Represent an error raised since the environment (OS) is not supported.""" | 39 """Represent an error raised since the environment (OS) is not supported.""" |
40 pass | 40 pass |
41 | 41 |
42 class ChromeEndureBaseTest(perf.BasePerfTest): | 42 class ChromeEndureBaseTest(perf.BasePerfTest): |
43 """Implements common functionality for all Chrome Endure tests. | 43 """Implements common functionality for all Chrome Endure tests. |
44 | 44 |
45 All Chrome Endure test classes should inherit from this class. | 45 All Chrome Endure test classes should inherit from this class. |
46 """ | 46 """ |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
533 try: | 533 try: |
534 element = self._GetElement(driver.find_element_by_xpath, xpath) | 534 element = self._GetElement(driver.find_element_by_xpath, xpath) |
535 element.click() | 535 element.click() |
536 except (selenium.common.exceptions.StaleElementReferenceException, | 536 except (selenium.common.exceptions.StaleElementReferenceException, |
537 selenium.common.exceptions.TimeoutException) as e: | 537 selenium.common.exceptions.TimeoutException) as e: |
538 logging.exception('WebDriver exception: %s' % e) | 538 logging.exception('WebDriver exception: %s' % e) |
539 return False | 539 return False |
540 | 540 |
541 return True | 541 return True |
542 | 542 |
543 def _GetConfig(self): | |
544 """Load endure configuration file.""" | |
545 config_file = os.path.join(os.path.dirname(__file__), 'endure_config.txt') | |
546 if not os.path.exists(config_file): | |
547 return {} | |
dennis_jeffrey
2012/08/09 17:29:04
if the file doesn't exist, let's return a dictiona
fdeng1
2012/08/11 00:11:27
Done.
| |
548 else: | |
549 return pyauto.PyUITest.EvalDataFrom(config_file) | |
550 | |
551 def _LoginToGoogleAccount(self, account_key='test_google_account'): | |
552 """Login to Google account. | |
553 | |
554 Try to use the url and credential specified in endure_config.txt. | |
555 If it fails to load valid information, try to login via public | |
556 google account url with credential in | |
557 src/data/pyauto_private/private_tests_info.txt. | |
558 | |
559 Args: | |
560 account_key: The string key in private_tests_info.txt which is associated | |
561 with the test account login credentials to use. It will only | |
562 be used when fail to load credential from endure_config.txt | |
563 | |
564 Raises: | |
565 RuntimeError: if could not get credential information. | |
566 """ | |
dennis_jeffrey
2012/08/09 17:29:04
if this function successfully finds credentials to
fdeng1
2012/08/11 00:11:27
Added a log message for each case.
On 2012/08/09 1
| |
567 config = self._GetConfig() | |
568 google_account_url = (config['google_account_url'] | |
569 if 'google_account_url' in config | |
570 else None) | |
571 username = (config['username'] if 'username' in config else None) | |
572 password = (config['password'] if 'password' in config else None) | |
573 if not username or not password: | |
574 private_file = os.path.join(pyauto.PyUITest.DataDir(), 'pyauto_private', | |
dennis_jeffrey
2012/08/09 17:29:04
can we just use the superclass's _LoginToGoogleAcc
fdeng1
2012/08/11 00:11:27
I tried to make config file also effective for per
| |
575 'private_tests_info.txt') | |
576 if os.path.exists(private_file): | |
577 google_account_url = None | |
578 creds = self.GetPrivateInfo()[account_key] | |
579 username = creds['username'] | |
580 password = creds['password'] | |
581 else: | |
582 message = \ | |
583 'Please sepecify credential information in %s.\n' \ | |
584 'Format:\n\t{\n' \ | |
585 '\t "username": "my_username",\n' \ | |
586 '\t "password": "my_password",\n' \ | |
587 '\t "google_account_url": "https://my-google-account-server/",\n' \ | |
588 '\t "gmail_url: "https://my-gmail-server",\n' \ | |
589 '\t "plus_url": "https://my-plus-server",\n' \ | |
590 '\t "docs_url": "https://my-docs-server",\n\t}\n' \ | |
591 % os.path.join(os.path.dirname(__file__), 'endure_config.txt') | |
592 raise RuntimeError('Could not get credential information.\n' + message) | |
593 test_utils.GoogleAccountsLogin( | |
594 self, username, password, url=google_account_url) | |
595 self.NavigateToURL('about:blank') | |
596 | |
543 | 597 |
544 class ChromeEndureControlTest(ChromeEndureBaseTest): | 598 class ChromeEndureControlTest(ChromeEndureBaseTest): |
545 """Control tests for Chrome Endure.""" | 599 """Control tests for Chrome Endure.""" |
546 | 600 |
547 _WEBAPP_NAME = 'Control' | 601 _WEBAPP_NAME = 'Control' |
548 _TAB_TITLE_SUBSTRING = 'Chrome Endure Control Test' | 602 _TAB_TITLE_SUBSTRING = 'Chrome Endure Control Test' |
549 | 603 |
550 def testControlAttachDetachDOMTree(self): | 604 def testControlAttachDetachDOMTree(self): |
551 """Continually attach and detach a DOM tree from a basic document.""" | 605 """Continually attach and detach a DOM tree from a basic document.""" |
552 test_description = 'AttachDetachDOMTree' | 606 test_description = 'AttachDetachDOMTree' |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
595 | 649 |
596 _WEBAPP_NAME = 'Gmail' | 650 _WEBAPP_NAME = 'Gmail' |
597 _TAB_TITLE_SUBSTRING = 'Gmail' | 651 _TAB_TITLE_SUBSTRING = 'Gmail' |
598 _FRAME_XPATH = 'id("canvas_frame")' | 652 _FRAME_XPATH = 'id("canvas_frame")' |
599 | 653 |
600 def setUp(self): | 654 def setUp(self): |
601 ChromeEndureBaseTest.setUp(self) | 655 ChromeEndureBaseTest.setUp(self) |
602 | 656 |
603 # Log into a test Google account and open up Gmail. | 657 # Log into a test Google account and open up Gmail. |
604 self._LoginToGoogleAccount(account_key='test_google_account_gmail') | 658 self._LoginToGoogleAccount(account_key='test_google_account_gmail') |
605 self.NavigateToURL('http://www.gmail.com') | 659 gmail_url = (self._GetConfig()['gmail_url'] |
660 if 'gmail_url' in self._GetConfig() | |
661 else 'http://www.gmail.com') | |
662 self.NavigateToURL(gmail_url) | |
606 loaded_tab_title = self.GetActiveTabTitle() | 663 loaded_tab_title = self.GetActiveTabTitle() |
607 self.assertTrue(self._TAB_TITLE_SUBSTRING in loaded_tab_title, | 664 self.assertTrue(self._TAB_TITLE_SUBSTRING in loaded_tab_title, |
608 msg='Loaded tab title does not contain "%s": "%s"' % | 665 msg='Loaded tab title does not contain "%s": "%s"' % |
609 (self._TAB_TITLE_SUBSTRING, loaded_tab_title)) | 666 (self._TAB_TITLE_SUBSTRING, loaded_tab_title)) |
610 | 667 |
611 self._driver = self.NewWebDriver() | 668 self._driver = self.NewWebDriver() |
612 # Any call to wait.until() will raise an exception if the timeout is hit. | 669 # 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 | 670 # TODO(dennisjeffrey): Remove the need for webdriver's wait using the new |
614 # DOM mutation observer mechanism. | 671 # DOM mutation observer mechanism. |
615 self._wait = WebDriverWait(self._driver, timeout=60) | 672 self._wait = WebDriverWait(self._driver, timeout=60) |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
668 To account for scenario warm-up time, latency values during the first | 725 To account for scenario warm-up time, latency values during the first |
669 minute of test execution are not recorded. | 726 minute of test execution are not recorded. |
670 | 727 |
671 Args: | 728 Args: |
672 element: A selenium.webdriver.remote.WebElement object to click. | 729 element: A selenium.webdriver.remote.WebElement object to click. |
673 test_description: A string description of what the test does, used for | 730 test_description: A string description of what the test does, used for |
674 outputting results to be graphed. Should not contain spaces. For | 731 outputting results to be graphed. Should not contain spaces. For |
675 example, 'ComposeDiscard' for Gmail. | 732 example, 'ComposeDiscard' for Gmail. |
676 action_description: A string description of what action is being | 733 action_description: A string description of what action is being |
677 performed. Should not contain spaces. For example, 'Compose'. | 734 performed. Should not contain spaces. For example, 'Compose'. |
678 """ | 735 """ |
fdeng1
2012/08/09 04:01:58
Since we allow user to use their own google accoun
dennis_jeffrey
2012/08/09 17:29:04
Good point. It would be good to have the code her
fdeng1
2012/08/11 00:11:27
How would a test know the latency is available or
| |
679 latency_dom_element = self._GetLatencyDomElement() | 736 latency_dom_element = self._GetLatencyDomElement() |
680 element.click() | 737 element.click() |
681 # Wait for the old latency value to be removed, before getting the new one. | 738 # Wait for the old latency value to be removed, before getting the new one. |
682 self._WaitUntilDomElementRemoved(latency_dom_element) | 739 self._WaitUntilDomElementRemoved(latency_dom_element) |
683 | 740 |
684 latency_dom_element = self._GetLatencyDomElement() | 741 latency_dom_element = self._GetLatencyDomElement() |
685 match = re.search(r'\[(\d+) ms\]', latency_dom_element.text) | 742 match = re.search(r'\[(\d+) ms\]', latency_dom_element.text) |
686 if match: | 743 if match: |
687 latency = int(match.group(1)) | 744 latency = int(match.group(1)) |
688 elapsed_time = int(round(time.time() - self._test_start_time)) | 745 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.""" | 990 """Long-running performance tests for Chrome using Google Docs.""" |
934 | 991 |
935 _WEBAPP_NAME = 'Docs' | 992 _WEBAPP_NAME = 'Docs' |
936 _TAB_TITLE_SUBSTRING = 'Google Drive' | 993 _TAB_TITLE_SUBSTRING = 'Google Drive' |
937 | 994 |
938 def setUp(self): | 995 def setUp(self): |
939 ChromeEndureBaseTest.setUp(self) | 996 ChromeEndureBaseTest.setUp(self) |
940 | 997 |
941 # Log into a test Google account and open up Google Docs. | 998 # Log into a test Google account and open up Google Docs. |
942 self._LoginToGoogleAccount() | 999 self._LoginToGoogleAccount() |
943 self.NavigateToURL('http://docs.google.com') | 1000 docs_url = (self._GetConfig()['docs_url'] |
1001 if 'docs_url' in self._GetConfig() | |
1002 else 'http://docs.google.com') | |
1003 self.NavigateToURL(docs_url) | |
944 self.assertTrue( | 1004 self.assertTrue( |
945 self.WaitUntil(lambda: self._TAB_TITLE_SUBSTRING in | 1005 self.WaitUntil(lambda: self._TAB_TITLE_SUBSTRING in |
946 self.GetActiveTabTitle(), | 1006 self.GetActiveTabTitle(), |
947 timeout=60, expect_retval=True, retry_sleep=1), | 1007 timeout=60, expect_retval=True, retry_sleep=1), |
948 msg='Timed out waiting for Docs to load. Tab title is: %s' % | 1008 msg='Timed out waiting for Docs to load. Tab title is: %s' % |
949 self.GetActiveTabTitle()) | 1009 self.GetActiveTabTitle()) |
950 | 1010 |
951 self._driver = self.NewWebDriver() | 1011 self._driver = self.NewWebDriver() |
952 | 1012 |
953 def testDocsAlternatelyClickLists(self): | 1013 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.""" | 1065 """Long-running performance tests for Chrome using Google Plus.""" |
1006 | 1066 |
1007 _WEBAPP_NAME = 'Plus' | 1067 _WEBAPP_NAME = 'Plus' |
1008 _TAB_TITLE_SUBSTRING = 'Google+' | 1068 _TAB_TITLE_SUBSTRING = 'Google+' |
1009 | 1069 |
1010 def setUp(self): | 1070 def setUp(self): |
1011 ChromeEndureBaseTest.setUp(self) | 1071 ChromeEndureBaseTest.setUp(self) |
1012 | 1072 |
1013 # Log into a test Google account and open up Google Plus. | 1073 # Log into a test Google account and open up Google Plus. |
1014 self._LoginToGoogleAccount() | 1074 self._LoginToGoogleAccount() |
1015 self.NavigateToURL('http://plus.google.com') | 1075 plus_url = (self._GetConfig()['plus_url'] |
1076 if 'plus_url' in self._GetConfig() | |
1077 else 'http://plus.google.com') | |
1078 self.NavigateToURL(plus_url) | |
1016 loaded_tab_title = self.GetActiveTabTitle() | 1079 loaded_tab_title = self.GetActiveTabTitle() |
1017 self.assertTrue(self._TAB_TITLE_SUBSTRING in loaded_tab_title, | 1080 self.assertTrue(self._TAB_TITLE_SUBSTRING in loaded_tab_title, |
1018 msg='Loaded tab title does not contain "%s": "%s"' % | 1081 msg='Loaded tab title does not contain "%s": "%s"' % |
1019 (self._TAB_TITLE_SUBSTRING, loaded_tab_title)) | 1082 (self._TAB_TITLE_SUBSTRING, loaded_tab_title)) |
1020 | 1083 |
1021 self._driver = self.NewWebDriver() | 1084 self._driver = self.NewWebDriver() |
1022 | 1085 |
1023 def testPlusAlternatelyClickStreams(self): | 1086 def testPlusAlternatelyClickStreams(self): |
1024 """Alternates between two different streams. | 1087 """Alternates between two different streams. |
1025 | 1088 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1118 self._num_errors += 1 | 1181 self._num_errors += 1 |
1119 | 1182 |
1120 time.sleep(1) | 1183 time.sleep(1) |
1121 | 1184 |
1122 self._RunEndureTest(self._WEBAPP_NAME, self._TAB_TITLE_SUBSTRING, | 1185 self._RunEndureTest(self._WEBAPP_NAME, self._TAB_TITLE_SUBSTRING, |
1123 test_description, scenario) | 1186 test_description, scenario) |
1124 | 1187 |
1125 | 1188 |
1126 if __name__ == '__main__': | 1189 if __name__ == '__main__': |
1127 pyauto_functional.Main() | 1190 pyauto_functional.Main() |
OLD | NEW |