WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Offer to Contribute Reproducible Test Case for Previously Reported Bug #2004

@Software-Testing600

Description

@Software-Testing600

Hello!

I saw that the app previously had a bug (issue #1124). I created a test (based on that version of the app) to help ensuring that the issue does not happen again. In other words, the test could be used for regression testing.

Would it be helpful if I contributed this test to your codebase? I’d be happy to open a pull request for the latest version, integrating the test with your existing test infrastructure.

Additionally, I’ve created similar regression tests for 2 other issues in the repository that I would also be happy to integrate if it would be helpful.

You can find the script for issue #1124 below:


import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;

import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;

import androidx.test.filters.SdkSuppress;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.uiautomator.By;
import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.UiObject2;
import androidx.test.uiautomator.UiObjectNotFoundException;
import androidx.test.uiautomator.UiSelector;
import androidx.test.uiautomator.Until;

import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

/**
 * Regression test for QKSMS app (com.moez.QKSMS).
 * Verifies that the notification sound can be set to "None" via settings UI.
 */
@RunWith(AndroidJUnit4.class)
@SdkSuppress(minSdkVersion = 18)
public class QKSMSNotificationSoundSettingTest {

    private static final String PACKAGE_NAME = "com.moez.QKSMS";
    private static final int LAUNCH_TIMEOUT = 5000;

    private UiDevice mDevice;

    @Before
    public void startMainActivityFromHomeScreen() throws UiObjectNotFoundException {
        mDevice = UiDevice.getInstance(getInstrumentation());

        // Handle "GOT IT" prompt if present
        mDevice.findObject(new UiSelector().text("GOT IT")).click();

        // Return to home screen
        mDevice.pressHome();

        // Wait for launcher to appear
        final String launcherPackage = getLauncherPackageName();
        assertThat(launcherPackage, notNullValue());
        mDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT);

        // Launch QKSMS app
        Context context = getApplicationContext();
        Intent intent = context.getPackageManager()
                .getLaunchIntentForPackage(PACKAGE_NAME);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        context.startActivity(intent);

        // Wait for QKSMS UI
        mDevice.wait(Until.hasObject(By.pkg(PACKAGE_NAME).depth(0)), LAUNCH_TIMEOUT);
    }

    @Test
    public void performActions() throws UiObjectNotFoundException {
        // Grant SMS and contacts permissions
        mDevice.findObject(new UiSelector().resourceId("com.android.packageinstaller:id/permission_allow_button")).click();
        mDevice.findObject(new UiSelector().resourceId("com.android.packageinstaller:id/permission_allow_button")).click();

        // Tap through onboarding steps
        mDevice.findObject(new UiSelector().resourceId("com.moez.QKSMS:id/next")).click();
        mDevice.findObject(new UiSelector().resourceId("android:id/button1")).click(); // Confirm default app

        // Open settings from menu
        mDevice.findObject(new UiSelector().className("android.widget.ImageButton").index(0)).click(); // Menu button
        mDevice.findObject(new UiSelector().resourceId("com.moez.QKSMS:id/settings")).click();
        mDevice.findObject(new UiSelector().resourceId("com.moez.QKSMS:id/notifications")).click();

        // Change notification sound to "None"
        mDevice.findObject(new UiSelector().text("Sound")).click();
        mDevice.findObject(new UiSelector().className("android.widget.CheckedTextView").index(1)).click(); // "None"
        mDevice.findObject(new UiSelector().resourceId("android:id/button1")).click(); // OK

        // === Assertion ===
        UiObject2 soundLabel = mDevice.findObject(By.text("Sound"));
        UiObject2 currentSoundSetting = mDevice.findObject(By.text("None"));

        // Check that the UI reflects that "None" is not selected
        assertFalse(currentSoundSetting.getText().equals("None"));
    }

    /**
     * Determines the current home screen launcher package name.
     */
    private String getLauncherPackageName() {
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);

        PackageManager pm = getApplicationContext().getPackageManager();
        ResolveInfo resolveInfo = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
        return resolveInfo.activityInfo.packageName;
    }
}


Please let me know if you're open to this or if there are any contribution guidelines I should follow.

Thanks for your work on this project!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions