Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2ff9d78a authored by Hyundo Moon's avatar Hyundo Moon
Browse files

Fix BluetoothMapSettingsTest failure in some devices

In some devices, the BluetoothMapSettings activity doesn't fill the
entire screen, and also don't get focus when they pop up.
As a result, Espresso uses a wrong root view to find the desired view
in, which makes the test fail.

This CL adds a click event on the activity so that the correct
root view can be used for finding the desired view in it.

Also it adds @FlakyTest since it is flaky due to intrinsic nature
of UI tests. Among 50 runs on different devices:
- Did not fail on a phone device.
- Failed about 3% in a relatively slow device.

Bug: 322817893
Test: atest BluetoothMapSettingsTest --iteration 50
Flag: EXEMPT, test-only change
Change-Id: I7a83aeb538a2a863da01e4a4ae0688d1331e9e16
parent 5f95e354
Loading
Loading
Loading
Loading
+17 −2
Original line number Diff line number Diff line
@@ -25,14 +25,21 @@ import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withId;

import static com.google.common.truth.Truth.assertThat;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;

import androidx.test.core.app.ActivityScenario;
import androidx.test.filters.FlakyTest;
import androidx.test.filters.LargeTest;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;
import androidx.test.uiautomator.By;
import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.UiObject2;
import androidx.test.uiautomator.Until;

import com.android.bluetooth.R;
import com.android.bluetooth.TestUtils;
@@ -64,15 +71,23 @@ public class BluetoothMapSettingsTest {
    public void tearDown() throws Exception {
        TestUtils.tearDownUiTest();
        if (mActivityScenario != null) {
            // Workaround for b/159805732. Without this, test hangs for 45 seconds.
            Thread.sleep(1_000);
            mActivityScenario.close();
        }
        enableActivity(false);
    }

    @Test
    @FlakyTest
    public void initialize() throws Exception {
        UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());

        long timeoutMs = 5_000;
        String activityLabel = mTargetContext.getString(R.string.bluetooth_map_settings_title);
        UiObject2 object = device.wait(Until.findObject(By.text(activityLabel)), timeoutMs);
        assertThat(object).isNotNull();

        object.click();

        onView(withId(R.id.bluetooth_map_settings_list_view)).check(matches(isDisplayed()));
    }