2016-07-12 2 views
2

私はUIAutomatorをGoogleマップでMarkerOptionsをクリックしようとしています。 This solution does not work ..UIAutomatorを使用してMarkerOptionsをクリックする

build.gradle(アプリケーションレベル)

dependencies { 
    androidTestCompile 'com.android.support.test:runner:0.3' 
    androidTestCompile 'com.android.support.test:rules:0.3' 
    androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1' 
} 

TestClassを

@RunWith(AndroidJUnit4.class) 
public class ApplicationTest { 

     UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); 
     UiObject marker = device.findObject(new UiSelector().descriptionContains("title_of_marker. snippet_of_marker.")); 
     try { 
      marker.click(); 
     } catch (UiObjectNotFoundException e) { 
      e.printStackTrace(); 
     } 
} 

MapsFragment.java

private GoogleMap mMapView; 

private void loadMapLocations() { 

      mMapView.addMarker(new MarkerOptions() 
        .position(new LatLng(52.0988198,5.074657)) 
        .title("title_of_marker") 
        .snippet("snippet_of_marker")); 
} 

enter image description here

出力:

W/System.err: android.support.test.uiautomator.UiObjectNotFoundException: UiSelector[CONTAINS_DESCRIPTION=title_of_marker. snippet_of_marker.] 
W/System.err:  at android.support.test.uiautomator.UiObject.click(UiObject.java:412) 

私はすべてを試みたが、今続行する方法がわかりません。

答えて

0

私はサンプルマップを作成し、あなたのようなマーカーを追加しました。 CulebraTesterを開始しました。テスト録音を開始しました。マーカーをクリックします。

enter image description here

その後、私はこのテストを得るために、(すぐに自動生成される)waitを追加しました。

@Test 
public void culebraGeneratedTest() throws Exception { 
    final BySelector bySelector = By.clazz(Pattern.compile(".*")).desc("title_of_marker. snippet_of_marker.").pkg("com.example.diego.mymapapplication"); 
    mDevice.wait(Until.hasObject(bySelector), DEFAULT_TIMEOUT); 
    mDevice.findObject(bySelector).clickAndWait(Until.newWindow(), DEFAULT_TIMEOUT); 
} 

プロジェクトにテストクラスを追加しました。 テストを実行します。 それは動作します!

テストする良い機会のようです。CulebraTesterコード生成。

+0

のthnx私はCulebraTesterのためにオプトイン。 –

+0

このチュートリアルは、このソリューションを試しました:https://www.linkedin.com/pulse/android-ui-testing-androidviewclientculebra-ahmed-kasemしかし、これはどちらもうまくいきません。 –

+0

上記のチュートリアルは、Pythonのためのものです。答えに含まれるコードは、UiAutomator/Javaです。私はコードをテストし、私のために働いた、何があなたのために働いていないのですか? '' com.example.diego.mymapapplication "'をあなたのパッケージ名に変更しましたか? –

1

私はサンディエゴのサンプルコード@使用し、私のApplicationTest.javaにこれを貼り付け、これは動作しますが、私はクレブラを使用する必要はありませんしました:

@Test 
public void loginAndClickMarker() { 

    UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); 
    final BySelector bySelector = By.clazz(Pattern.compile(".*")).desc("title_of_marker. snippet_of_marker.").pkg("www.brandmkrs.com.damageapp"); 
    device.wait(Until.hasObject(bySelector), DEFAULT_TIMEOUT); 
    device.findObject(bySelector).clickAndWait(Until.newWindow(), DEFAULT_TIMEOUT); 
    SystemClock.sleep(1000); 
} 
+0

私は、CulebraTesterはコードをどこでどのように生成したかを示すためにのみ言及されていることは明らかでした。 CulebraTesterは、この種のコードを生成するための強力なツールです –

関連する問題