Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test to check pause button visibility #2480

Open
anandwana001 opened this issue Jan 15, 2021 · 10 comments
Open

Fix test to check pause button visibility #2480

anandwana001 opened this issue Jan 15, 2021 · 10 comments
Labels
bug End user-perceivable behaviors which are not desirable. Impact: Low Low perceived user impact (e.g. edge cases). Work: Low Solution is clear and broken into good-first-issue-sized chunks. Z-ibt Temporary label for Ben to keep track of issues he's triaged.

Comments

@anandwana001
Copy link
Contributor

anandwana001 commented Jan 15, 2021

Describe the bug
Espresso doesn't test anything when the app is in the idle state. Testing Audio becomes difficult in such cases.

Expected behavior
Propose a solution to test the pause icon visiblity while playing audio
Cases we need to test:

  • Pause icon is visible when audio is playing
  • All the test should pass on Espresso
  • All the test should pass on Robolectric

Additional context
Tests that needs to be fixed from ExplorationActivityTest and AudioFragmentTest

[These two in ExplorationActivityTest were fixed in #5245]

fun testAudioWithWifi_openRatioExploration_clickAudioIcon_checkAudioFragmentHasDefaultLanguageAndAutoPlays()

fun testAudioWithWifi_openRatioExploration_continueToInteraction_clickAudioButton_submitAnswer_checkFeedbackAudioPlays()

[Tests Pending fixes]

fun testAudioFragment_invokePrepared_clickPlayButton_showsPauseButton()

fun testAudioFragment_invokePrepared_clickPlay_touchSeekBar_checkStillPlaying()

#2216 (comment)

@MaskedCarrot
Copy link
Contributor

@anandwana001 may I work on this? Also can you please give me a few pointers on how to get started?

@anandwana001
Copy link
Contributor Author

@MaskedCarrot We need to create a fake audio library so that we can test cases when the espresso test is idle like pause icon is only visible when espresso test is idle, but we need something using which we can fake our media player that audio is playing and the pause icon gets visible.

@MaskedCarrot
Copy link
Contributor

@anandwana001 I tried reading about this online but I could not find any resource of much help. Can you please guide me on this?

@anandwana001
Copy link
Contributor Author

Basically, there is no third party lib todo this, but we need to create the whole thing here.

@MaskedCarrot
Copy link
Contributor

@anandwana001 I am facing a few difficulties on this may we connect on giiter regarding this issue?

@anandwana001
Copy link
Contributor Author

Sure

@MaskedCarrot MaskedCarrot removed their assignment Jan 27, 2021
@srikanthkb
Copy link
Contributor

srikanthkb commented Feb 19, 2021

I took a look at this issue for the first test case testAudioWithWifi_openRatioExploration_clickAudioIcon_checkAudioFragmentHasDefaultLanguageAndAutoPlays(), here's what I think:

  • When the audio player button is clicked, the audio player UI is loaded and it immediately starts playing the audio. The audio player plays the audio on the main thread, which blocks the testCoroutineDispatchers resource (because we registered idling resource in setUp()). This makes Espresso wait for the resource R.drawable.ic_pause_circle_filled_white_24dp in line 549(which is supposedly blocked):
    waitForTheView(withText("What is a Ratio?"))
    onView(withId(R.id.action_audio_player)).perform(click())
    onView(
    allOf(
    withId(R.id.play_pause_audio_icon),
    withEffectiveVisibility(Visibility.VISIBLE)
    )
    )
    onView(allOf(withId(R.id.audio_language_icon), withEffectiveVisibility(Visibility.VISIBLE)))
    waitForTheView(withDrawable(R.drawable.ic_pause_circle_filled_white_24dp))

Interestingly, if we call testCoroutineDispatchers.unregisterIdlingResource() before the execution of this particular test, the test is successfully passed only on Espresso (not Roboelectric). I think this does not allow blocking of the resource, forcing the test to be asynchronous and allows Espresso access to the R.drawable.ic_pause_circle_filled_white_24dp resource.

@srikanthkb
Copy link
Contributor

On more deeper investigation, I found that there are two issues with this test:

  1. In the following line

    waitForTheView(withDrawable(R.drawable.ic_pause_circle_filled_white_24dp))

    The error observed is as follows:
    image

  2. If the above line was commented out (for debugging purpose), the test would still fail on the following statement:

    onView(withId(R.id.play_pause_audio_icon)).check(
    matches(
    withDrawable(
    R.drawable.ic_pause_circle_filled_white_24dp
    )
    )
    )

    The error observed for this statement is as follow:
    scrennshot2

@anandwana001 anandwana001 changed the title Introduce test-only Fake Audio Library Fix test to check pause button visibility Mar 16, 2021
@pravesh00
Copy link
Contributor

@anandwana001 Can I work on this issue?

@anandwana001
Copy link
Contributor Author

@pravesh00 Before assigning, have you check the above comments?
Also, I suggest commenting on what approach you will use to solve this issue before sending out the PR.
Comment 1 - #2480 (comment)
Comment 2 - #2480 (comment)

@seanlip seanlip added bug End user-perceivable behaviors which are not desirable. and removed issue_user_developer labels Mar 29, 2023
@adhiamboperes adhiamboperes added Work: Low Solution is clear and broken into good-first-issue-sized chunks. good first issue This item is good for new contributors to make their pull request. labels Oct 17, 2023
adhiamboperes added a commit that referenced this issue Dec 7, 2023
<!-- READ ME FIRST: Please fill in the explanation section below and
check off every point from the Essential Checklist! -->
## Explanation
<!--
- Explain what your PR does. If this PR fixes an existing bug, please
include
- "Fixes #bugnum:" in the explanation so that GitHub can auto-close the
issue
  - when this PR is merged.
  -->

Fixes part of #2480
- Fixes
`testAudioWifi_ratioExp_audioIcon_audioFragHasDefaultLangAndAutoPlays()`
by checking default language at the end and testing audio icons in a
better way.
- Fixes
`testAudioWifi_ratioExp_continueInteraction_audioButton_submitAns_feedbackAudioPlays()`
by scrolling to the _**continue_interaction_button**_ before performing
click on it , as it was positioned at the lower end of the recycler
view.

## Essential Checklist
<!-- Please tick the relevant boxes by putting an "x" in them. -->
- [x] The PR title and explanation each start with "Fix #bugnum: " (If
this PR fixes part of an issue, prefix the title with "Fix part of
#bugnum: ...".)
- [x] Any changes to
[scripts/assets](https://github.com/oppia/oppia-android/tree/develop/scripts/assets)
files have their rationale included in the PR explanation.
- [x] The PR follows the [style
guide](https://github.com/oppia/oppia-android/wiki/Coding-style-guide).
- [x] The PR does not contain any unnecessary code changes from Android
Studio
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#undo-unnecessary-changes)).
- [x] The PR is made from a branch that's **not** called "develop" and
is up-to-date with "develop".
- [x] The PR is **assigned** to the appropriate reviewers
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#clarification-regarding-assignees-and-reviewers-section)).

## For UI-specific PRs only
<!-- Delete these section if this PR does not include UI-related
changes. -->
If your PR includes UI-related changes, then:
- Add screenshots for portrait/landscape for both a tablet & phone of
the before & after UI changes
- For the screenshots above, include both English and pseudo-localized
(RTL) screenshots (see [RTL
guide](https://github.com/oppia/oppia-android/wiki/RTL-Guidelines))
- Add a video showing the full UX flow with a screen reader enabled (see
[accessibility
guide](https://github.com/oppia/oppia-android/wiki/Accessibility-A11y-Guide))
- For PRs introducing new UI elements or color changes, both light and
dark mode screenshots must be included
- Add a screenshot demonstrating that you ran affected Espresso tests
locally & that they're passing

---------

Co-authored-by: Adhiambo Peres <[email protected]>
@adhiamboperes adhiamboperes removed the good first issue This item is good for new contributors to make their pull request. label Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug End user-perceivable behaviors which are not desirable. Impact: Low Low perceived user impact (e.g. edge cases). Work: Low Solution is clear and broken into good-first-issue-sized chunks. Z-ibt Temporary label for Ben to keep track of issues he's triaged.
Development

No branches or pull requests

9 participants