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 Screenshot Tests #12701

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
543bc5d
Use views rather than activity
alperozturk96 Mar 18, 2024
1dbf79c
Use views rather than activity
alperozturk96 Mar 18, 2024
4bd89b0
Use ActivityScenarioRule and fix sync problem
alperozturk96 Mar 19, 2024
c3b5939
Use ActivityScenarioRule and fix sync problem
alperozturk96 Mar 19, 2024
e6231c6
Use onIdleSync instead of waitForIdleSync
alperozturk96 Mar 19, 2024
d15753f
Fix kotlin spotless check
alperozturk96 Mar 19, 2024
2539856
Replace deprecated api
alperozturk96 Mar 19, 2024
ebca358
Replace deprecated api
alperozturk96 Mar 19, 2024
4a1758c
Fix sync issues for some broken tests
alperozturk96 Mar 19, 2024
da2ba4e
Fix sync issues for some broken tests
alperozturk96 Mar 20, 2024
66ca3aa
Fix sync issues for some broken tests
alperozturk96 Mar 20, 2024
1fcdbac
Remove deprecated apis
alperozturk96 Mar 20, 2024
02ac4e7
Remove deprecated apis
alperozturk96 Mar 20, 2024
07f1a53
Remove deprecated apis
alperozturk96 Mar 20, 2024
efd32ce
Fix infinite loop
alperozturk96 Mar 25, 2024
fa55911
Fix code analytics
alperozturk96 Mar 25, 2024
c6f13f7
Fix git conflicts
alperozturk96 Mar 27, 2024
305968d
Fix sync issues for some broken tests
alperozturk96 Mar 20, 2024
cb9c852
Fix differentUser()
alperozturk96 Mar 25, 2024
69aa4e6
Use different name for ss tests
alperozturk96 Mar 25, 2024
09eb480
use static strings for screenshots
tobiasKaminsky Mar 26, 2024
31f219a
Use prefix instead full name
alperozturk96 Mar 26, 2024
d31e06b
Use onIdleSync for TrashbinActivityIT
alperozturk96 Mar 26, 2024
c2c21e0
Fix broken tests
alperozturk96 Mar 27, 2024
2f100b5
Fix git conflicts
alperozturk96 Mar 27, 2024
043e116
test commit
alperozturk96 Mar 27, 2024
fdbf290
revert
alperozturk96 Mar 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/inspectionProfiles/ktlint.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
128 changes: 74 additions & 54 deletions app/src/androidTest/java/com/nextcloud/client/ActivitiesActivityIT.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
*/
package com.nextcloud.client

import android.content.Intent
import android.view.View
import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.Espresso
import androidx.test.espresso.contrib.DrawerActions
import androidx.test.espresso.intent.rule.IntentsTestRule
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.ext.junit.rules.ActivityScenarioRule
import com.facebook.testing.screenshot.Screenshot
import com.owncloud.android.AbstractIT
import com.owncloud.android.R
Expand All @@ -22,61 +25,75 @@ import com.owncloud.android.lib.resources.activities.models.PreviewObject
import com.owncloud.android.lib.resources.status.OCCapability
import com.owncloud.android.ui.activities.ActivitiesActivity
import com.owncloud.android.utils.ScreenshotTest
import org.junit.After
import org.junit.Rule
import org.junit.Test
import java.util.GregorianCalendar

class ActivitiesActivityIT : AbstractIT() {
private lateinit var scenario: ActivityScenario<ActivitiesActivity>
val intent = Intent(ApplicationProvider.getApplicationContext(), ActivitiesActivity::class.java)

@get:Rule
var activityRule = IntentsTestRule(ActivitiesActivity::class.java, true, false)
val activityRule = ActivityScenarioRule<ActivitiesActivity>(intent)

@After
fun cleanup() {
scenario.close()
}

@Test
@ScreenshotTest
fun openDrawer() {
val sut = activityRule.launchActivity(null)
shortSleep()
Espresso.onView(withId(R.id.drawer_layout)).perform(DrawerActions.open())
sut.runOnUiThread {
sut.dismissSnackbar()
scenario = activityRule.scenario
scenario.onActivity { sut ->
onIdleSync {
shortSleep()
Espresso.onView(withId(R.id.drawer_layout)).perform(DrawerActions.open())
sut.runOnUiThread {
sut.dismissSnackbar()
}
shortSleep()
screenshot(sut)
}
}
shortSleep()
waitForIdleSync()
screenshot(sut)
}

@Test
@ScreenshotTest
fun loading() {
val sut: ActivitiesActivity = activityRule.launchActivity(null).apply {
runOnUiThread {
dismissSnackbar()
binding.emptyList.root.visibility = View.GONE
binding.swipeContainingList.visibility = View.GONE
binding.loadingContent.visibility = View.VISIBLE
scenario = activityRule.scenario
scenario.onActivity { sut ->
sut.runOnUiThread {
sut.dismissSnackbar()
sut.binding.emptyList.root.visibility = View.GONE
sut.binding.swipeContainingList.visibility = View.GONE
sut.binding.loadingContent.visibility = View.VISIBLE
}
}

shortSleep()
waitForIdleSync()
shortSleep()

Screenshot.snap(sut.binding.loadingContent).record()
onIdleSync {
Screenshot.snap(sut.binding.loadingContent).record()
}
}
}

@Test
@ScreenshotTest
fun empty() {
val sut: ActivitiesActivity = activityRule.launchActivity(null)

sut.runOnUiThread {
sut.showActivities(mutableListOf(), nextcloudClient, -1)
sut.setProgressIndicatorState(false)
sut.dismissSnackbar()
scenario = activityRule.scenario
scenario.onActivity { sut ->
sut.runOnUiThread {
sut.showActivities(mutableListOf(), nextcloudClient, -1)
sut.setProgressIndicatorState(false)
sut.dismissSnackbar()
}
shortSleep()
onIdleSync {
screenshot(sut.binding.emptyList.emptyListView)
}
}

shortSleep()
waitForIdleSync()

screenshot(sut)
}

@Test
Expand All @@ -87,8 +104,6 @@ class ActivitiesActivityIT : AbstractIT() {
capability.versionMayor = 20
fileDataStorageManager.saveCapabilities(capability)

val sut: ActivitiesActivity = activityRule.launchActivity(null)

val date = GregorianCalendar()
date.set(2005, 4, 17, 10, 35, 30) // random date

Expand Down Expand Up @@ -159,35 +174,40 @@ class ActivitiesActivityIT : AbstractIT() {
)
)

sut.runOnUiThread {
sut.showActivities(activities as List<Any>?, nextcloudClient, -1)
sut.setProgressIndicatorState(false)
sut.dismissSnackbar()
}
scenario = activityRule.scenario
scenario.onActivity { sut ->
sut.runOnUiThread {
sut.showActivities(activities as List<Any>?, nextcloudClient, -1)
sut.setProgressIndicatorState(false)
sut.dismissSnackbar()
}

longSleep()
waitForIdleSync()
longSleep()

screenshot(sut)
onIdleSync {
screenshot(sut)
}
}
}

@Test
@ScreenshotTest
fun error() {
val sut: ActivitiesActivity = activityRule.launchActivity(null)

shortSleep()
scenario = activityRule.scenario
scenario.onActivity { sut ->
shortSleep()

sut.runOnUiThread {
sut.showEmptyContent("Error", "Error! Please try again later!")
sut.setProgressIndicatorState(false)
sut.dismissSnackbar()
}

sut.runOnUiThread {
sut.showEmptyContent("Error", "Error! Please try again later!")
sut.setProgressIndicatorState(false)
sut.dismissSnackbar()
shortSleep()
shortSleep()
onIdleSync {
screenshot(sut)
}
}

shortSleep()
shortSleep()
waitForIdleSync()

screenshot(sut)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package com.nextcloud.client;

import android.content.Intent;
import android.widget.TextView;

import com.nextcloud.test.GrantStoragePermissionRule;
Expand All @@ -14,28 +15,43 @@
import com.owncloud.android.authentication.AuthenticatorActivity;
import com.owncloud.android.utils.ScreenshotTest;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;

import androidx.test.espresso.intent.rule.IntentsTestRule;

import androidx.test.core.app.ActivityScenario;
import androidx.test.core.app.ApplicationProvider;

public class AuthenticatorActivityIT extends AbstractIT {
private static final String URL = "cloud.nextcloud.com";
@Rule public IntentsTestRule<AuthenticatorActivity> activityRule = new IntentsTestRule<>(AuthenticatorActivity.class,
true,
false);

private ActivityScenario<AuthenticatorActivity> scenario;

@Before
public void setUp() {
Intent intent = new Intent(ApplicationProvider.getApplicationContext(), AuthenticatorActivity.class);
scenario = ActivityScenario.launch(intent);
}

@After
public void tearDown() {
scenario.close();
}

@Rule
public final TestRule permissionRule = GrantStoragePermissionRule.grant();

@Test
@ScreenshotTest
public void login() {
AuthenticatorActivity sut = activityRule.launchActivity(null);
((TextView) sut.findViewById(R.id.host_url_input)).setText(URL);
sut.runOnUiThread(() -> sut.getAccountSetupBinding().hostUrlInput.clearFocus());
screenshot(sut);
scenario.onActivity(sut -> {
((TextView) sut.findViewById(R.id.host_url_input)).setText(URL);
onIdleSync(() -> {
sut.runOnUiThread(() -> sut.getAccountSetupBinding().hostUrlInput.clearFocus());
screenshot(sut);
});
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,42 @@
*/
package com.nextcloud.client;

import android.app.Activity;
import android.content.Intent;

import com.nextcloud.test.GrantStoragePermissionRule;
import com.owncloud.android.AbstractIT;
import com.owncloud.android.ui.activity.CommunityActivity;
import com.owncloud.android.utils.ScreenshotTest;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;

import androidx.test.espresso.intent.rule.IntentsTestRule;

import androidx.test.core.app.ActivityScenario;
import androidx.test.core.app.ApplicationProvider;

public class CommunityActivityIT extends AbstractIT {
@Rule public IntentsTestRule<CommunityActivity> activityRule = new IntentsTestRule<>(CommunityActivity.class,
true,
false);
private ActivityScenario<CommunityActivity> scenario;

@Before
public void setUp() {
Intent intent = new Intent(ApplicationProvider.getApplicationContext(), CommunityActivity.class);
scenario = ActivityScenario.launch(intent);
}

@After
public void tearDown() {
scenario.close();
}

@Rule
public final TestRule permissionRule = GrantStoragePermissionRule.grant();

@Test
@ScreenshotTest
public void open() {
Activity sut = activityRule.launchActivity(null);

screenshot(sut);
scenario.onActivity(sut -> onIdleSync(() -> screenshot(sut)));
}
}
Loading
Loading