OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 from telemetry import test | 5 from telemetry import test |
6 from telemetry.core import exceptions | 6 from telemetry.core import exceptions |
7 from telemetry.core import util | 7 from telemetry.core import util |
8 from telemetry.core.backends.chrome import tracing_backend | 8 from telemetry.core.backends.chrome import tracing_backend |
9 from telemetry.core.timeline import model | 9 from telemetry.core.timeline import model |
10 from telemetry.page.actions import action_runner as action_runner_module | 10 from telemetry.page.actions import action_runner as action_runner_module |
(...skipping 124 matching lines...) Loading... |
135 def WaitForElement(): | 135 def WaitForElement(): |
136 action_runner.WaitForElement(text='oo', timeout=1) | 136 action_runner.WaitForElement(text='oo', timeout=1) |
137 self.assertRaises(util.TimeoutException, WaitForElement) | 137 self.assertRaises(util.TimeoutException, WaitForElement) |
138 | 138 |
139 def testClickElement(self): | 139 def testClickElement(self): |
140 self.Navigate('page_with_clickables.html') | 140 self.Navigate('page_with_clickables.html') |
141 action_runner = action_runner_module.ActionRunner(self._tab) | 141 action_runner = action_runner_module.ActionRunner(self._tab) |
142 | 142 |
143 action_runner.ExecuteJavaScript('valueSettableByTest = 1;') | 143 action_runner.ExecuteJavaScript('valueSettableByTest = 1;') |
144 action_runner.ClickElement('#test') | 144 action_runner.ClickElement('#test') |
145 self.assertEquals(1, action_runner.EvaluateJavaScript('valueToTest')) | 145 self.assertEqual(1, action_runner.EvaluateJavaScript('valueToTest')) |
146 | 146 |
147 action_runner.ExecuteJavaScript('valueSettableByTest = 2;') | 147 action_runner.ExecuteJavaScript('valueSettableByTest = 2;') |
148 action_runner.ClickElement(text='Click/tap me') | 148 action_runner.ClickElement(text='Click/tap me') |
149 self.assertEquals(2, action_runner.EvaluateJavaScript('valueToTest')) | 149 self.assertEqual(2, action_runner.EvaluateJavaScript('valueToTest')) |
150 | 150 |
151 action_runner.ExecuteJavaScript('valueSettableByTest = 3;') | 151 action_runner.ExecuteJavaScript('valueSettableByTest = 3;') |
152 action_runner.ClickElement( | 152 action_runner.ClickElement( |
153 element_function='document.body.firstElementChild;') | 153 element_function='document.body.firstElementChild;') |
154 self.assertEquals(3, action_runner.EvaluateJavaScript('valueToTest')) | 154 self.assertEqual(3, action_runner.EvaluateJavaScript('valueToTest')) |
155 | 155 |
156 def WillFail(): | 156 def WillFail(): |
157 action_runner.ClickElement('#notfound') | 157 action_runner.ClickElement('#notfound') |
158 self.assertRaises(exceptions.EvaluateException, WillFail) | 158 self.assertRaises(exceptions.EvaluateException, WillFail) |
159 | 159 |
160 @test.Disabled('debug') | 160 @test.Disabled('debug') |
161 def testTapElement(self): | 161 def testTapElement(self): |
162 self.Navigate('page_with_clickables.html') | 162 self.Navigate('page_with_clickables.html') |
163 action_runner = action_runner_module.ActionRunner(self._tab) | 163 action_runner = action_runner_module.ActionRunner(self._tab) |
164 | 164 |
165 action_runner.ExecuteJavaScript('valueSettableByTest = 1;') | 165 action_runner.ExecuteJavaScript('valueSettableByTest = 1;') |
166 action_runner.TapElement('#test') | 166 action_runner.TapElement('#test') |
167 self.assertEquals(1, action_runner.EvaluateJavaScript('valueToTest')) | 167 self.assertEqual(1, action_runner.EvaluateJavaScript('valueToTest')) |
168 | 168 |
169 action_runner.ExecuteJavaScript('valueSettableByTest = 2;') | 169 action_runner.ExecuteJavaScript('valueSettableByTest = 2;') |
170 action_runner.TapElement(text='Click/tap me') | 170 action_runner.TapElement(text='Click/tap me') |
171 self.assertEquals(2, action_runner.EvaluateJavaScript('valueToTest')) | 171 self.assertEqual(2, action_runner.EvaluateJavaScript('valueToTest')) |
172 | 172 |
173 action_runner.ExecuteJavaScript('valueSettableByTest = 3;') | 173 action_runner.ExecuteJavaScript('valueSettableByTest = 3;') |
174 action_runner.TapElement( | 174 action_runner.TapElement( |
175 element_function='document.body.firstElementChild') | 175 element_function='document.body.firstElementChild') |
176 self.assertEquals(3, action_runner.EvaluateJavaScript('valueToTest')) | 176 self.assertEqual(3, action_runner.EvaluateJavaScript('valueToTest')) |
177 | 177 |
178 def WillFail(): | 178 def WillFail(): |
179 action_runner.TapElement('#notfound') | 179 action_runner.TapElement('#notfound') |
180 self.assertRaises(exceptions.EvaluateException, WillFail) | 180 self.assertRaises(exceptions.EvaluateException, WillFail) |
| 181 |
| 182 def testSwipe(self): |
| 183 self.Navigate('page_with_swipeables.html') |
| 184 action_runner = action_runner_module.ActionRunner(self._tab) |
| 185 |
| 186 action_runner.SwipeElement( |
| 187 selector='#left-right', direction='left', left_start_ratio=0.9) |
| 188 self.assertTrue(action_runner.EvaluateJavaScript( |
| 189 'document.querySelector("#left-right").scrollLeft') > 75) |
| 190 action_runner.SwipeElement( |
| 191 selector='#top-bottom', direction='up', top_start_ratio=0.9) |
| 192 self.assertTrue(action_runner.EvaluateJavaScript( |
| 193 'document.querySelector("#top-bottom").scrollTop') > 75) |
| 194 |
| 195 action_runner.SwipePage(direction='left', left_start_ratio=0.9) |
| 196 self.assertTrue(action_runner.EvaluateJavaScript( |
| 197 'document.body.scrollLeft') > 75) |
| 198 action_runner.SwipePage(direction='up', top_start_ratio=0.9) |
| 199 self.assertTrue(action_runner.EvaluateJavaScript( |
| 200 'document.body.scrollTop') > 75) |
OLD | NEW |