<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                ## Espresso DataMatcher選擇器 通過委托給Espresso的[Data Matcher](https://developer.android.com/reference/android/support/test/espresso/DataInteraction),我們可以定位在視口中不可見的視圖,而無需手動滾動屏幕上的視圖。 ### 適配器視圖 Android應用程序有特殊類型的[AdapterViews](https://developer.android.com/reference/android/widget/AdapterView)視圖(如:`ScrollView`,`ListView`,`GridView`),但其只渲染那些屏幕上可見的子視圖。AdapterView具有“adapter”對象,該對象存儲該視圖子級的所有數據,包括未呈現的視圖。 使用Espresso的數據匹配器時,您可以編寫一個[Hamcrest matcher](http://hamcrest.org/JavaHamcrest/javadoc/1.3/org/hamcrest/Matchers.html)以從適配器中選擇一個項,從而定位屏幕外的視圖。如果該項不在視圖層次結構中,則Espresso會自動將其滾動到視圖中。 ### 示例 這是從Android應用程序的源XML中獲取的ListView: ```xml <android.widget.ListView index="0" package="io.appium.android.apis" class="android.widget.ListView" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" scrollable="true" long-clickable="false" password="false" selected="false" visible="true" bounds="[0,210][1080,1794]" resource-id="android:id/list" adapter-type="HashMap" adapters="{contentDescription=Animation, title=Animation, intent=Intent { cmp=io.appium.android.apis/.ApiDemos (has extras) }},{contentDescription=Auto Complete, title=Auto Complete, intent=Intent { cmp=io.appium.android.apis/.ApiDemos (has extras) }}, ...}"> <android.widget.TextView index="0" package="io.appium.android.apis" class="android.widget.TextView" content-desc="Drag and Drop" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" visible="true" bounds="[0,148][1080,274]" text="Drag and Drop" hint="false" resource-id="android:id/text1" /> <android.widget.TextView index="1" package="io.appium.android.apis" class="android.widget.TextView" content-desc="Expandable Lists" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" visible="true" bounds="[0,277][1080,403]" text="Expandable Lists" hint="false" resource-id="android:id/text1" /> <android.widget.TextView index="2" package="io.appium.android.apis" class="android.widget.TextView" content-desc="Focus" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" visible="true" bounds="[0,406][1080,532]" text="Focus" hint="false" resource-id="android:id/text1" /> <android.widget.TextView index="3" package="io.appium.android.apis" class="android.widget.TextView" content-desc="Gallery" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" visible="true" bounds="[0,535][1080,661]" text="Gallery" hint="false" resource-id="android:id/text1" /> <android.widget.TextView index="4" package="io.appium.android.apis" class="android.widget.TextView" content-desc="Game Controller Input" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" visible="true" bounds="[0,664][1080,790]" text="Game Controller Input" hint="false" resource-id="android:id/text1" /> <android.widget.TextView index="5" package="io.appium.android.apis" class="android.widget.TextView" content-desc="Grid" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" visible="true" bounds="[0,793][1080,919]" text="Grid" hint="false" resource-id="android:id/text1" /> <android.widget.TextView index="6" package="io.appium.android.apis" class="android.widget.TextView" content-desc="Hover Events" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" visible="true" bounds="[0,922][1080,1048]" text="Hover Events" hint="false" resource-id="android:id/text1" /> <android.widget.TextView index="7" package="io.appium.android.apis" class="android.widget.TextView" content-desc="ImageButton" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" visible="true" bounds="[0,1051][1080,1177]" text="ImageButton" hint="false" resource-id="android:id/text1" /> <android.widget.TextView index="8" package="io.appium.android.apis" class="android.widget.TextView" content-desc="ImageSwitcher" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" visible="true" bounds="[0,1180][1080,1306]" text="ImageSwitcher" hint="false" resource-id="android:id/text1" /> <android.widget.TextView index="9" package="io.appium.android.apis" class="android.widget.TextView" content-desc="ImageView" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" visible="true" bounds="[0,1309][1080,1435]" text="ImageView" hint="false" resource-id="android:id/text1" /> <android.widget.TextView index="10" package="io.appium.android.apis" class="android.widget.TextView" content-desc="Layout Animation" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" visible="true" bounds="[0,1438][1080,1564]" text="Layout Animation" hint="false" resource-id="android:id/text1" /> <android.widget.TextView index="11" package="io.appium.android.apis" class="android.widget.TextView" content-desc="Layouts" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" visible="true" bounds="[0,1567][1080,1693]" text="Layouts" hint="false" resource-id="android:id/text1" /> <android.widget.TextView index="12" package="io.appium.android.apis" class="android.widget.TextView" content-desc="Lists" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" visible="true" bounds="[0,1696][1080,1822]" text="Lists" hint="false" resource-id="android:id/text1" /> </android.widget.ListView> ``` 這ListView控件顯示菜單項[ `Drag and Drop`,`Expandable Lists`...直到`Lists`]。此菜單還有其他幾個不在屏幕上的項,無法使用標準定位器定位。例如,有一個名為`TextClock`的菜單項在View層次結構中不可見。 `ListView`上面的XML中的節點具有一個名為的屬性`adapters`,其中包含“備份” ListView的數據: ```js { contentDescription = Animation, title = Animation, intent = Intent { cmp = io.appium.android.apis / .ApiDemos(has extras) } }, { contentDescription = Auto Complete, title = Auto Complete, intent = Intent { cmp = io.appium.android.apis / .ApiDemos(has extras) } }, { contentDescription = Buttons, title = Buttons, intent = Intent { cmp = io.appium.android.apis / .view.Buttons1 } }, ... ``` 這些項可以使用數據匹配器選擇器來定位。以下為顯示如何找到并單擊`TextClock`的代碼段: ```js // Javascript example driver.findElementById("list") .findElement("-android datamatcher", JSON.stringify({ "name": "hasEntry", "args": ["title", "TextClock"] })) .click(); ``` ```ruby # Ruby @driver.find_element(:id, 'list') .find_element(:data_matcher, { name: 'hasEntry', args: ['title', 'TextClock'] }.to_json) .click ``` ```python # Python driver.find_element_by_id('list') .find_element_by_android_data_matcher({ name='hasEntry', args=['title', 'TextClock'] }) .click() ``` 此Appium選擇器等效于在Espresso中編寫此匹配器: ```java // Espresso code (not Appium code) onData(hasEntry("title", "textClock") .inAdapterView(withId("android:id/list)) .perform(click()); ``` 在此示例中,我們使用ID選擇器選擇父對象`AdapterView`,然后通過應用與對象`title="TextClock"`匹配的Hamcrest Matcher找到該視圖的子對象。 `AdapterView`如果“活動”只有一個適配器視圖,則無需定位父對象。在這種情況下,可以將其省略。 ```js driver.findElement("-android datamatcher", JSON.stringify({ "name": "hasEntry", "args": ["title", "TextClock"] })) .click(); ``` ```ruby # Ruby @driver.find_element(:data_matcher, { name: 'hasEntry', args: ['title', 'TextClock'] }.to_json).click ``` ```python # Python driver.find_element_by_android_data_matcher({ name='hasEntry', args=['title', 'TextClock'] }).click() ``` ### 編寫選擇器 數據匹配器選擇器使用Java reflection來調用用于定位適配器對象的[Hamcrest匹配器](http://hamcrest.org/JavaHamcrest/javadoc/1.3/org/hamcrest/Matchers.html)。匹配器為JSON格式,并且具有此格式 ```js { "name": "<METHOD_NAME>", "args": [...], ``` 該名稱是Hamcrest匹配器方法名稱。默認為`org.hamcrest.Matchers`名稱空間,但是也可以使用匹配器方法全稱(例如:`android.support.test.espresso.matcher.CursorMatchers.withRowBlob`)。 args是該方法采用的參數列表(如果不采用args則可以不確定)。這些可以是字符串,數字,布爾值或其他JSON定義的Hamcrest Matcher。 ### JSON匹配器樣本 具有等效Espresso`onData`匹配器的JSON匹配器示例 #### 開頭 ```js // 'startsWith' JSON { "name": "startsWith", "args": "substr" // if it's a single arg, we don't need args to be an array } ``` ```java // Espresso 'startsWith' example onData(startsWith("substr")); ``` #### 多個匹配器 ```js // 'multiple matchers' JSON { "name": "allOf", "args": [ {"name": "instanceOf", "args": "Map.class"}, {"name": "hasEntry", "args": { "name": "equalTo", "args": "STR" }}, {"name": "is", "args": "item: 50"} ] } ``` ```java // Espresso 'multiple matchers' example onData(allOf(is(instanceOf(Map.class)), hasEntry(equalTo("STR"), is("item: 50")))); ``` #### Cursor匹配器 ```js // 'cursor matchers' JSON { "name": "is", "args": { "name": "instanceOf", "args": "Cursor.class" }, "name": "CursorMatchers.withRowString", "args": [ "job_title", {"name": "is", "args": "Barista"} ] } ``` ```java // Espresso 'cursor matchers' example onData( is(instanceOf(Cursor.class)), CursorMatchers.withRowString("job_title", is("Barista")) ); ``` ### 資源 - [Espresso中的視圖與數據說明](https://medium.com/androiddevelopers/adapterviews-and-espresso-f4172aa853cf) - [Espresso清單](https://developer.android.com/training/testing/espresso/lists)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看