Chromium Code Reviews| Index: android_webview/tools/automated_ui_tests/javatests/src/org/chromium/webview_ui_test/test/util/DropDownListUtils.java |
| diff --git a/android_webview/tools/automated_ui_tests/javatests/src/org/chromium/webview_ui_test/test/util/DropDownListUtils.java b/android_webview/tools/automated_ui_tests/javatests/src/org/chromium/webview_ui_test/test/util/DropDownListUtils.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d7b393f95f19567f3ec7a79affe275250fd9cae2 |
| --- /dev/null |
| +++ b/android_webview/tools/automated_ui_tests/javatests/src/org/chromium/webview_ui_test/test/util/DropDownListUtils.java |
| @@ -0,0 +1,48 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
|
the real yoland
2016/11/15 01:45:44
DropDownSelectAtoms.java
aluo
2016/11/18 00:22:30
changed to Atoms.java
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| +package org.chromium.webview_ui_test.test; |
| + |
| +import static android.support.test.espresso.Espresso.onView; |
| +import static android.support.test.espresso.matcher.RootMatchers.withDecorView; |
| +import static android.support.test.espresso.matcher.ViewMatchers.isEnabled; |
| +import static android.support.test.espresso.matcher.ViewMatchers.withText; |
| +import static android.support.test.espresso.web.model.Atoms.castOrDie; |
| + |
| +import android.support.test.espresso.ViewInteraction; |
| +import android.support.test.espresso.web.model.Atom; |
| +import android.support.test.espresso.web.model.Evaluation; |
| +import android.support.test.espresso.web.model.SimpleAtom; |
| +import android.support.test.espresso.web.model.TransformingAtom; |
| + |
| +/** |
| + * Class to help automation of html select element in Espresso tests |
| + */ |
| +class DropDownListUtils { |
| + /** |
| + * Click on a select element |
| + */ |
| + public static SimpleAtom selectAction() { |
| + return new SimpleAtom("function(webElement) {" |
| + + "var e = document.createEvent('MouseEvents');" |
| + + "e.initMouseEvent('mousedown', true, true, window, 0, 0, 0, 0, 0," |
| + + "false, false, false, false, 0, null);" |
| + + "webElement.dispatchEvent(e);}"); |
| + } |
| + |
| + /** |
| + * Returns a ViewInteration for an item in the select dropdown that matches itemText |
| + */ |
| + public static ViewInteraction getSelectItem(String itemText) { |
|
the real yoland
2016/11/15 01:45:44
this shouldn't be abstracted.
aluo
2016/11/18 00:22:30
Done.
|
| + return onView(withText(itemText)).inRoot(withDecorView(isEnabled())); |
| + } |
| + |
| + /** |
| + * Returns an Atom that represents the text in the select elements currently selected item |
| + */ |
| + public static Atom<String> getCurrentSelection() { |
| + return new TransformingAtom<Evaluation, String>( |
| + new SimpleAtom("function(e) {return e.options[e.selectedIndex].text;}"), |
| + castOrDie(String.class)); |
| + } |
| +} |