Skip to content

Commit

Permalink
Merge pull request #16944 from wordpress-mobile/refactor/ui-testing-s…
Browse files Browse the repository at this point in the history
…wipe-to-avoid-viewpager-gray-overlay

Refactor swipeToAvoidGrayOverlay to ignore failures and become reusable
  • Loading branch information
AjeshRPai authored Jul 25, 2022
2 parents fdd9b34 + 33a2805 commit 6ea4960
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.wordpress.android.support.BaseTest;
import org.wordpress.android.support.DemoModeEnabler;
import org.wordpress.android.ui.WPLaunchActivity;
import org.wordpress.android.util.UiTestingUtils;
import org.wordpress.android.util.image.ImageType;

import java.util.Locale;
Expand Down Expand Up @@ -46,8 +47,6 @@
import static org.wordpress.android.support.WPSupportUtils.isTextDisplayed;
import static org.wordpress.android.support.WPSupportUtils.pressBackUntilElementIsDisplayed;
import static org.wordpress.android.support.WPSupportUtils.setNightMode;
import static org.wordpress.android.support.WPSupportUtils.swipeLeftOnViewPager;
import static org.wordpress.android.support.WPSupportUtils.swipeRightOnViewPager;
import static org.wordpress.android.support.WPSupportUtils.waitForAtLeastOneElementWithIdToBeDisplayed;
import static org.wordpress.android.support.WPSupportUtils.waitForElementToBeDisplayed;
import static org.wordpress.android.support.WPSupportUtils.waitForElementToBeDisplayedWithoutFailure;
Expand Down Expand Up @@ -221,7 +220,7 @@ private void generateStats() {
clickOn(R.id.nav_sites);
(new MySitesPage()).goToStats().dismissUpdateAlertDialogFragmentIfDisplayed();

swipeToAvoidGrayOverlay(R.id.statsPager);
UiTestingUtils.swipeToAvoidGrayOverlayIgnoringFailures(R.id.statsPager);

if (isElementDisplayed(R.id.button_negative)) {
clickOn(R.id.button_negative);
Expand Down Expand Up @@ -428,17 +427,6 @@ private void screenshotPostWithName(String name,
pressBackUntilElementIsDisplayed(R.id.tabLayout);
}

// In some cases there's a gray overlay on view pager screens when taking screenshots
// this function swipes left and then right as a workaround to clear it
// resourceID should be the ID of the viewPager
private void swipeToAvoidGrayOverlay(int resourceID) {
// Workaround to avoid gray overlay
swipeLeftOnViewPager(resourceID);
idleFor(1000);
swipeRightOnViewPager(resourceID);
idleFor(1000);
}

private void setNightModeAndWait(boolean isNightMode) {
setNightMode(isNightMode);
idleFor(5000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.wordpress.android.support.DemoModeEnabler;
import org.wordpress.android.ui.WPLaunchActivity;
import org.wordpress.android.ui.posts.EditPostActivity;
import org.wordpress.android.util.UiTestingUtils;
import org.wordpress.android.util.image.ImageType;

import static org.wordpress.android.support.WPSupportUtils.clickOn;
Expand All @@ -29,8 +30,6 @@
import static org.wordpress.android.support.WPSupportUtils.pressBackUntilElementIsDisplayed;
import static org.wordpress.android.support.WPSupportUtils.setNightMode;
import static org.wordpress.android.support.WPSupportUtils.swipeDownOnView;
import static org.wordpress.android.support.WPSupportUtils.swipeLeftOnViewPager;
import static org.wordpress.android.support.WPSupportUtils.swipeRightOnViewPager;
import static org.wordpress.android.support.WPSupportUtils.swipeUpOnView;
import static org.wordpress.android.support.WPSupportUtils.waitForAtLeastOneElementWithIdToBeDisplayed;
import static org.wordpress.android.support.WPSupportUtils.waitForElementToBeDisplayed;
Expand Down Expand Up @@ -152,8 +151,7 @@ private void navigateDiscover() {

// Workaround to avoid gray overlay
try {
swipeToAvoidGrayOverlay(R.id.view_pager);

UiTestingUtils.swipeToAvoidGrayOverlayIgnoringFailures(R.id.view_pager);
if (isTabletScreen()) {
swipeDownOnView(R.id.view_pager, (float) 0.5);
idleFor(1000);
Expand All @@ -178,7 +176,7 @@ private void navigateStats() {
clickOn(R.id.nav_sites);
(new MySitesPage()).goToStats();

swipeToAvoidGrayOverlay(R.id.statsPager);
UiTestingUtils.swipeToAvoidGrayOverlayIgnoringFailures(R.id.statsPager);

if (isElementDisplayed(R.id.button_negative)) {
clickOn(R.id.button_negative);
Expand Down Expand Up @@ -261,18 +259,6 @@ private boolean runningInTestLab() {
return "true".equals(testLabSetting);
}


// In some cases there's a gray overlay on view pager screens when taking screenshots
// this function swipes left and then right as a workaround to clear it
// resourceID should be the ID of the viewPager
private void swipeToAvoidGrayOverlay(int resourceID) {
// Workaround to avoid gray overlay
swipeLeftOnViewPager(resourceID);
idleFor(1000);
swipeRightOnViewPager(resourceID);
idleFor(1000);
}

private boolean editPostActivityIsNoLongerLoadingImages() {
EditPostActivity editPostActivity = (EditPostActivity) getCurrentActivity();
return editPostActivity.getAztecImageLoader().getNumberOfImagesBeingDownloaded() == 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.wordpress.android.util

import org.wordpress.android.support.WPSupportUtils

object UiTestingUtils {
/**
* Workaround to avoid gray overlay.
* In some cases there's a gray overlay on view pager screens when taking screenshots.
* This function swipes left and then right as a workaround to clear it.
* @param resourceID: Int the ID of the viewPager
*/
@JvmStatic
fun swipeToAvoidGrayOverlayIgnoringFailures(resourceID: Int) {
try {
WPSupportUtils.swipeLeftOnViewPager(resourceID)
WPSupportUtils.idleFor(1000)
WPSupportUtils.swipeRightOnViewPager(resourceID)
WPSupportUtils.idleFor(1000)
} catch (e: Throwable) {
// Fail softly
@Suppress("PrintStackTrace")
e.printStackTrace()
}
}
}

0 comments on commit 6ea4960

Please sign in to comment.