1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 from telemetry.core import util
6 from telemetry.page.actions import click_element
7 from telemetry.page.actions import wait
8 from telemetry.unittest import tab_test_case
10 class ClickElementActionTest(tab_test_case.TabTestCase):
11 def testClickWithSelectorWaitForNavigation(self):
12 self._browser.SetHTTPServerDirectories(util.GetUnittestDataDir())
14 self._browser.http_server.UrlOf('page_with_link.html'))
15 self._tab.WaitForDocumentReadyStateToBeComplete()
17 self._tab.EvaluateJavaScript('document.location.pathname;'),
18 '/page_with_link.html')
20 data = {'selector': 'a[id="clickme"]'}
21 i = click_element.ClickElementAction(data)
22 data = {'condition': 'href_change'}
23 j = wait.WaitAction(data)
24 j.RunAction(None, self._tab, i)
27 self._tab.EvaluateJavaScript('document.location.pathname;'),
30 def testClickWithTextWaitForRefChange(self):
31 self._browser.SetHTTPServerDirectories(util.GetUnittestDataDir())
33 self._browser.http_server.UrlOf('page_with_link.html'))
34 self._tab.WaitForDocumentReadyStateToBeComplete()
36 self._tab.EvaluateJavaScript('document.location.pathname;'),
37 '/page_with_link.html')
39 data = {'text': 'Click me'}
40 i = click_element.ClickElementAction(data)
41 data = {'condition': 'href_change'}
42 j = wait.WaitAction(data)
43 j.RunAction(None, self._tab, i)
46 self._tab.EvaluateJavaScript('document.location.pathname;'),
49 def testClickWithXPathWaitForRefChange(self):
50 self._browser.SetHTTPServerDirectories(util.GetUnittestDataDir())
52 self._browser.http_server.UrlOf('page_with_link.html'))
53 self._tab.WaitForDocumentReadyStateToBeComplete()
55 self._tab.EvaluateJavaScript('document.location.pathname;'),
56 '/page_with_link.html')
58 data = {'xpath': '//a[@id="clickme"]'}
59 i = click_element.ClickElementAction(data)
60 data = {'condition': 'href_change'}
61 j = wait.WaitAction(data)
62 j.RunAction(None, self._tab, i)
65 self._tab.EvaluateJavaScript('document.location.pathname;'),