• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Locator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中android.support.test.espresso.web.webdriver.Locator的典型用法代码示例。如果您正苦于以下问题:Java Locator类的具体用法?Java Locator怎么用?Java Locator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Locator类属于android.support.test.espresso.web.webdriver包,在下文中一共展示了Locator类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testShowAlertDialog

import android.support.test.espresso.web.webdriver.Locator; //导入依赖的package包/类
@Test
public void testShowAlertDialog() throws Throwable {
    // create  a signal to let us know when our task is done.
    final CountDownLatch signal = new CountDownLatch(1);

    waitWebViewLoad(MainFragment.DEFAULT_URL);

    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                // Wait second
                signal.await(1, TimeUnit.SECONDS);
                // Find ok button and click
                assertViewWithTextIsVisible(device, rule.getActivity().getString(android.R.string.ok));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }).start();

    // WebView show alert dialog
    onWebView().withElement(findElement(Locator.ID, "showAlertBtn"))
            .perform(webClick());
}
 
开发者ID:taehwandev,项目名称:Android-BlogExample,代码行数:26,代码来源:MainFragmentExtendTest.java


示例2: testWebToAndroidScriptCall

import android.support.test.espresso.web.webdriver.Locator; //导入依赖的package包/类
@Test
public void testWebToAndroidScriptCall() throws Exception {
    String go = MainFragment.DEFAULT_URL;

    onView(withId(R.id.et_url)).perform(clearText());
    onView(withId(R.id.et_url)).perform(typeText(go)).perform(ViewActions.pressImeActionButton());

    waitWebViewLoad();

    onWebView()
            // Find the search keyword element by ID
            .withElement(findElement(Locator.ID, "search_keyword"))
            // Clear previous input
            .perform(clearElement())
            // Enter text into the input element
            .perform(DriverAtoms.webKeys(ANDROID_SCRIPT_CALL))
            // Value check. script getValue 'search_keyword'
            .check(webMatches(script("return document.getElementById('search_keyword').value", castOrDie(String.class)), containsString(ANDROID_SCRIPT_CALL)))
            // Find the submit button
            .withElement(findElement(Locator.ID, "updateKeywordBtn"))
            // Simulate a click via javascript
            .perform(webClick());

    onView(withId(R.id.et_keyword)).check(matches(withText(ANDROID_SCRIPT_CALL)));
}
 
开发者ID:taehwandev,项目名称:Android-BlogExample,代码行数:26,代码来源:MainFragmentTest.java


示例3: testWebViewUpdateElementByDisplayed

import android.support.test.espresso.web.webdriver.Locator; //导入依赖的package包/类
@Test
public void testWebViewUpdateElementByDisplayed() throws Exception {
    String go = MainFragment.DEFAULT_URL;

    onView(withId(R.id.et_url)).perform(clearText());
    onView(withId(R.id.et_url)).perform(typeText(go)).perform(ViewActions.pressImeActionButton());

    waitWebViewLoad();

    onView(withId(R.id.et_keyword)).perform(clearText()).perform(typeText(JAVASCRIPT_CALL));
    onView(withId(R.id.btn_search)).perform(click());

    onWebView()
            // Find the message element by ID
            .withElement(findElement(Locator.ID, "message"))
            // Verify that the text is displayed
            .check(webMatches(getText(), containsString(JAVASCRIPT_CALL)));
}
 
开发者ID:taehwandev,项目名称:Android-BlogExample,代码行数:19,代码来源:MainFragmentTest.java


示例4: testChangeWebViewTest

import android.support.test.espresso.web.webdriver.Locator; //导入依赖的package包/类
@Test
public void testChangeWebViewTest() throws Exception {
    waitWebViewLoad();

    onWebView()
            // Find the search keyword element by ID
            .withElement(findElement(Locator.ID, "url"))
            // Clear previous input
            .perform(clearElement())
            // Enter text into the input element
            .perform(DriverAtoms.webKeys("http://google.com/"))
            // Find the submit button
            .withElement(findElement(Locator.ID, "changeWebView"))
            // Simulate a click via javascript
            .perform(webClick());

    onWebView()
            .withNoTimeout()
            .check(webMatches(getCurrentUrl(), containsString("https://www.google")));
}
 
开发者ID:taehwandev,项目名称:Android-BlogExample,代码行数:21,代码来源:MainFragmentTest.java


示例5: longPressLink

import android.support.test.espresso.web.webdriver.Locator; //导入依赖的package包/类
private void longPressLink(String id, String label, String path) {
    onWebView()
            .withElement(findElement(Locator.ID, id))
            .check(webMatches(getText(), equalTo(label)));


    simulateLinkLongPress(path);
}
 
开发者ID:mozilla-mobile,项目名称:firefox-tv,代码行数:9,代码来源:MultitaskingTest.java


示例6: pullDownToRefreshTest

import android.support.test.espresso.web.webdriver.Locator; //导入依赖的package包/类
@Test
public void pullDownToRefreshTest() throws InterruptedException, UiObjectNotFoundException, IOException {

   onView(withId(R.id.urlView))
            .check(matches(isDisplayed()))
            .check(matches(hasFocus()))
            .perform(click(), replaceText(webServer.url("/").toString()), pressImeActionButton());

    onView(withId(R.id.display_url))
            .check(matches(isDisplayed()))
            .check(matches(withText(containsString(webServer.getHostName()))));

    onWebView()
            .withElement(findElement(Locator.ID, COUNTER))
            .check(webMatches(getText(), containsString(FIRST_TIME)));

    onView(withId(R.id.swipe_refresh))
            .check(matches(isDisplayed()));

    // Swipe down to refresh, spinner is shown (2nd child) and progress bar is shown
    onView(withId(R.id.swipe_refresh))
          .perform(withCustomConstraints(swipeDown(), isDisplayingAtLeast(85)))
          .check(matches(hasChildCount(2)));

    onWebView()
            .withElement(findElement(Locator.ID, COUNTER))
            .check(webMatches(getText(), containsString(SECOND_TIME)));
}
 
开发者ID:mozilla-mobile,项目名称:firefox-tv,代码行数:29,代码来源:PullDownToRefreshTest.java


示例7: takeScreenshotsOfErrorPages

import android.support.test.espresso.web.webdriver.Locator; //导入依赖的package包/类
@Test
public void takeScreenshotsOfErrorPages() throws Exception {
    for (ErrorTypes error: ErrorTypes.values()) {
        onView(withId(R.id.urlView))
                .check(matches(isDisplayed()))
                .check(matches(hasFocus()))
                .perform(click(), replaceText("error:" + error.value), pressImeActionButton());

        assertTrue(TestHelper.webView.waitForExists(waitingTime));
        assertTrue(TestHelper.progressBar.waitUntilGone(waitingTime));

        // Android O has an issue with using Locator.ID
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            UiObject tryAgainBtn = device.findObject(new UiSelector()
                    .descriptionContains(getString(R.string.errorpage_refresh))
                    .clickable(true));
            assertTrue(tryAgainBtn.waitForExists(waitingTime));
        } else {
            onWebView()
                    .withElement(findElement(Locator.ID, "errorTitle"))
                    .perform(webClick());

            onWebView()
                    .withElement(findElement(Locator.ID, "errorTryAgain"))
                    .perform(webScrollIntoView());
        }

        Screengrab.screenshot(error.name());

        onView(withId(R.id.display_url))
                .check(matches(isDisplayed()))
                .perform(click());
    }
}
 
开发者ID:mozilla-mobile,项目名称:firefox-tv,代码行数:35,代码来源:ErrorPagesScreenshots.java


示例8: testCustomTabUI

import android.support.test.espresso.web.webdriver.Locator; //导入依赖的package包/类
@Test
public void testCustomTabUI() throws Exception {
    try {
        startWebServer();

        // Launch activity with custom tabs intent
        activityTestRule.launchActivity(createCustomTabIntent());

        // Wait for website to load
        onWebView()
                .withElement(findElement(Locator.ID, TEST_PAGE_HEADER_ID))
                .check(webMatches(getText(), equalTo(TEST_PAGE_HEADER_TEXT)));

        // Verify action button is visible
        onView(withContentDescription(ACTION_BUTTON_DESCRIPTION))
                .check(matches(isDisplayed()));

        // Open menu
        onView(withId(R.id.menuView))
                .perform(click());

        // Verify share action is visible
        onView(withId(R.id.share))
                .check(matches(isDisplayed()));

        // Verify custom menu item is visible
        onView(withText(MENU_ITEM_LABEL))
                .check(matches(isDisplayed()));

        // Close the menu again
        Espresso.pressBack();

        // Verify close button is visible - Click it to close custom tab.
        onView(withId(R.id.customtab_close))
                .check(matches(isDisplayed()))
                .perform(click());
    } finally {
        stopWebServer();
    }
}
 
开发者ID:mozilla-mobile,项目名称:firefox-tv,代码行数:41,代码来源:CustomTabTest.java


示例9: testCallWebJavascript

import android.support.test.espresso.web.webdriver.Locator; //导入依赖的package包/类
@Test
public void testCallWebJavascript() throws Throwable {
    waitWebViewLoad();

    onWebView()
            // Find the search keyword element by ID
            .withElement(findElement(Locator.ID, "search_keyword"))
            // Clear previous input
            .perform(clearElement())
            // Enter text into the input element
            .perform(DriverAtoms.webKeys(ANDROID_SCRIPT_CALL))
            .perform(script("updateKeyword();"));

    onView(withId(R.id.et_keyword)).check(matches(withText(ANDROID_SCRIPT_CALL)));
}
 
开发者ID:taehwandev,项目名称:Android-BlogExample,代码行数:16,代码来源:MainFragmentTest.java


示例10: contentLicenses_whenClicked_thenWebViewWithContentLicensesIsLaunched

import android.support.test.espresso.web.webdriver.Locator; //导入依赖的package包/类
@Test
public void contentLicenses_whenClicked_thenWebViewWithContentLicensesIsLaunched() {

  // When
  onView(withChildText(R.id.guidedactions_list, R.string.ondemand_settings_about_content))
      .perform(pressKey(KeyEvent.KEYCODE_ENTER));

  // Then
  enableJavaScriptInWebViewToSupportEspresso();
  onWebView().withElement(findElement(Locator.XPATH, "/html/body/h1"))
      .check(webMatches(getText(), is(getString(R.string.ondemand_settings_about_content))));
}
 
开发者ID:mkjensen,项目名称:danish-media-license,代码行数:13,代码来源:AboutActivityAndroidTest.java


示例11: thirdPartyLicenses_whenClicked_thenWebViewWithThirdPartyLicensesIsLaunched

import android.support.test.espresso.web.webdriver.Locator; //导入依赖的package包/类
@Test
public void thirdPartyLicenses_whenClicked_thenWebViewWithThirdPartyLicensesIsLaunched() {

  // When
  onView(withChildText(R.id.guidedactions_list, R.string.ondemand_settings_about_thirdparty))
      .perform(pressKey(KeyEvent.KEYCODE_DPAD_DOWN), pressKey(KeyEvent.KEYCODE_ENTER));

  // Then
  enableJavaScriptInWebViewToSupportEspresso();
  onWebView().withElement(findElement(Locator.XPATH, "/html/body/h1"))
      .check(webMatches(getText(), is(getString(R.string.ondemand_settings_about_thirdparty))));
}
 
开发者ID:mkjensen,项目名称:danish-media-license,代码行数:13,代码来源:AboutActivityAndroidTest.java


示例12: assertName

import android.support.test.espresso.web.webdriver.Locator; //导入依赖的package包/类
/**
 * Enters a full name and then asserts if it's displayed
 *
 * @param firstName the entered first name
 * @param lastName the entered last name
 */
private void assertName(String firstName, String lastName) {
    typeIntoWebField(FIRST_NAME_FORM_ID, firstName);
    typeIntoWebField(LAST_NAME_FORM_ID, lastName);
    onWebView().withElement(findElement(Locator.ID, FULL_NAME_DISPLAY_ID)).
            check(webMatches(getText(), containsString(firstName + " " + lastName)));
}
 
开发者ID:awslabs,项目名称:aws-device-farm-sample-app-for-android,代码行数:13,代码来源:LocalWebViewTest.java


示例13: testVisitingMultipleSites

import android.support.test.espresso.web.webdriver.Locator; //导入依赖的package包/类
@Test
public void testVisitingMultipleSites() {
    {
        // Load website: Erase button visible, Tabs button not

        navigateToMockWebServer(webServer, "tab1.html");

        checkTabIsLoaded("Tab 1");

        onFloatingEraseButton()
                .check(matches(isDisplayed()));

        onFloatingTabsButton()
                .check(matches(not(isDisplayed())));
    }

    {
        // Open link in new tab: Erase button hidden, Tabs button visible

        longPressLink("tab2", "Tab 2", "tab2.html");

        openInNewTab();

        onFloatingEraseButton()
                .check(matches(not(isDisplayed())));

        onFloatingTabsButton()
                .check(matches(isDisplayed()))
                .check(matches(withContentDescription(is("Tabs open: 2"))));
    }

    {
        // Open link in new tab: Tabs button updated, Erase button still hidden

        longPressLink("tab3", "Tab 3", "tab3.html");

        openInNewTab();

        onFloatingEraseButton()
                .check(matches(not(isDisplayed())));

        onFloatingTabsButton()
                .check(matches(isDisplayed()))
                .check(matches(withContentDescription(is("Tabs open: 3"))));
    }

    {
        // Open tabs tray and switch to second tab.

        onFloatingTabsButton()
                .perform(click());

        final String expectedUrl = webServer.getHostName() + "/tab2.html";

        onView(withText(expectedUrl))
                .perform(click());

        onWebView()
                .withElement(findElement(Locator.ID, "content"))
                .check(webMatches(getText(), equalTo("Tab 2")));
    }

    {
        // Remove all tabs via the menu

        onFloatingTabsButton()
                .perform(click());

        onView(withText(R.string.tabs_tray_action_erase))
                .perform(click());

        assertFalse(SessionManager.getInstance().hasSession());
    }


    SystemClock.sleep(5000);
}
 
开发者ID:mozilla-mobile,项目名称:firefox-tv,代码行数:78,代码来源:MultitaskingTest.java


示例14: checkTabIsLoaded

import android.support.test.espresso.web.webdriver.Locator; //导入依赖的package包/类
private void checkTabIsLoaded(String title) {
    onWebView()
            .withElement(findElement(Locator.ID, "content"))
            .check(webMatches(getText(), equalTo(title)));
}
 
开发者ID:mozilla-mobile,项目名称:firefox-tv,代码行数:6,代码来源:MultitaskingTest.java


示例15: MismatchTest

import android.support.test.espresso.web.webdriver.Locator; //导入依赖的package包/类
@Test
public void MismatchTest() throws InterruptedException, UiObjectNotFoundException {
    // Type "mozilla" into the URL bar.
    onView(withId(R.id.urlView))
            .check(matches(isDisplayed()))
            .check(matches(hasFocus()))
            .perform(click(), replaceText("mozilla"));

    // Verify that the search hint is displayed and click it.
    onView(withId(R.id.searchView))
            .check(matches(isDisplayed()))
            .check(matches(withText("Search for mozilla")))
            .check(matches(isClickable()))
            .perform(click());

    // A WebView is displayed
    onView(withId(R.id.webview))
            .check(matches(isDisplayed()));

    // The displayed URL contains mozilla. Click on it to edit it again.
    onView(withId(R.id.display_url))
            .check(matches(isDisplayed()))
            .check(matches(withText(containsString("mozilla"))))
            .perform(click());

    // Type "moz" - Verify that it auto-completes to "mozilla.org" and then load the website
    onView(withId(R.id.urlView))
            .perform(click(), replaceText("mozilla"))
            .check(matches(withText("mozilla.org")))
            .perform(pressImeActionButton());

    // Check we loaded the mozilla.org website
    onWebView()
            .withElement(findElement(Locator.CSS_SELECTOR, MOZILLA_WEBSITE_SLOGAN_SELECTOR))
            .check(webMatches(getText(), containsString(MOZILLA_WEBSITE_SLOGAN_TEXT)));

    // The displayed URL contains www.mozilla.org
    onView(withId(R.id.display_url))
            .check(matches(isDisplayed()))
            .check(matches(withText(containsString("www.mozilla.org"))));
}
 
开发者ID:mozilla-mobile,项目名称:firefox-tv,代码行数:42,代码来源:URLMismatchTest.java


示例16: AzureADSignIn

import android.support.test.espresso.web.webdriver.Locator; //导入依赖的package包/类
public static void AzureADSignIn(String username, String password, ActivityTestRule<SignInActivity> signInActivityTestRule) throws InterruptedException {
    SignInActivity signInActivity = signInActivityTestRule.launchActivity(null);

    onView(withId(R.id.o365_signin)).perform(click());

    try {
        onWebView()
                .withElement(findElement(Locator.ID, USER_ID_TEXT_ELEMENT))
                .perform(clearElement())
                // Enter text into the input element
                .perform(DriverAtoms.webKeys(username))
                // Set focus on the username input text
                // The form validates the username when this field loses focus
                .perform(webClick())
                .withElement(findElement(Locator.ID, PASSWORD_TEXT_ELEMENT))
                // Now we force focus on this element to make
                // the username element to lose focus and validate
                .perform(webClick())
                .perform(clearElement())
                // Enter text into the input element
                .perform(DriverAtoms.webKeys(password));

        Thread.sleep(2000, 0);

        onWebView()
                .withElement(findElement(Locator.ID, SIGN_IN_BUTTON_ELEMENT))
                .perform(webClick());
    } catch (NoMatchingViewException ex) {
        // If user is already logged in, the flow will go directly to SnippetListActivity
    } finally {
        Thread.sleep(2000, 0);
    }

    // Finally, verify that SnippetListActivity is on top
    intended(allOf(
            hasComponent(hasShortClassName(".SnippetListActivity")),
            toPackage("com.microsoft.graph.snippets")
    ));

    signInActivity.finish();
}
 
开发者ID:microsoftgraph,项目名称:android-java-snippets-sample,代码行数:42,代码来源:SignInActivityTests.java


示例17: typeIntoWebField

import android.support.test.espresso.web.webdriver.Locator; //导入依赖的package包/类
/**
 * Types a given string into a id
 *
 * @param id the element id
 * @param text the text input
 */
private void typeIntoWebField(String id, String text){
    onWebView().withElement(findElement(Locator.ID, id)).perform(clearElement()).perform(webKeys(text));
}
 
开发者ID:awslabs,项目名称:aws-device-farm-sample-app-for-android,代码行数:10,代码来源:LocalWebViewTest.java



注:本文中的android.support.test.espresso.web.webdriver.Locator类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java OptimizationException类代码示例发布时间:2022-05-22
下一篇:
Java GuardedAction类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap