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

Demo App: Screenshot testing #1158

Closed
wants to merge 15 commits into from
Closed

Conversation

anita-vadverao
Copy link

@anita-vadverao anita-vadverao commented Feb 9, 2022

IMPORTANT: All PRs must be linked to an issue (except for extremely trivial and straightforward changes).

Fixes #[issue number]

Description
Clear and concise code change description.

Alternative(s) considered
Have you considered any alternatives? And if so, why have you chosen the approach in this PR?

Type
Choose one: (Bug fix | Feature | Documentation | Testing | Code health | Builds | Releases | Other)

Screenshots (if applicable)

Checklist

  • I have read and acknowledged the Code of conduct
  • I have read the Contributing page
  • I have signed the Google Individual CLA, or I am covered by my company's Corporate CLA
  • I have discussed my proposed solution with code owners in the linked issue(s) and we have agreed upon the general approach
  • I have run ./gradlew spotlessApply and ./gradlew spotlessCheck to check my code follows the style guide of this project
  • I have run ./gradlew check and ./gradlew connectedCheck to test my changes locally
  • I have built and run the reference app(s) to verify my change fixes the issue and/or does not break the reference app(s)

Copy link
Collaborator

@jingtang10 jingtang10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as discussed please sync and remove reference directory.

also should the html files be checked in?

Copy link
Contributor

@ktarasenko ktarasenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff!
I added my 5 cents, but let's not block this PR. Feel free to add TODOs instead of doing actual changes.

@@ -206,6 +215,7 @@ object Dependencies {
const val mockitoKotlin = "3.2.0"
const val mockitoInline = "4.0.0"
const val robolectric = "4.5.1"
// const val facebookScreenshotPlugin = "0.14.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicates l:209

}

object Espresso {
const val espressoCore = "androidx.test.espresso:espresso-core:${Versions.espresso}"
}

// const val screenshotPlugin =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated above

@RunWith(AndroidJUnit4::class)
class ScreenshotTest {

@get:Rule var activityTestRule = ActivityTestRule(MainActivity::class.java, false, false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ActivityTestRule is deprecated. Please use ActivityScenario instead.
https://developer.android.com/reference/androidx/test/core/app/ActivityScenario

This would change the way we would do snapActivity:

  activityScenario.onActivity { activity ->
            Screenshot.snapActivity(activity).record()
        }

<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
<style
name="AppTheme"
parent="Theme.MaterialComponents.Light.DarkActionBar"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you switch to Light theme from DayNight one on purpose?

val view = activityTestRule.activity.findViewById<TextView>(R.id.search_src_text)
snapActivity(activity).setName("Registered Patient List").record()
snap(view).setName("sample_view_test").record()
Thread.sleep(5000)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I bet most of those timeouts are not necessary.
Espresso tools (IdlingResources) could be used instead.

@jingtang10
Copy link
Collaborator

Can you please remove all the HTML files that are included???

@jingtang10
Copy link
Collaborator

@epicadk FYI this is the PR I mentioned earlier

@epicadk epicadk self-assigned this Feb 25, 2022
import androidx.test.runner.AndroidJUnitRunner
import com.facebook.testing.screenshot.ScreenshotRunner

class ScreenShotTestRunner : AndroidJUnitRunner() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only required when we are using a custom test runner right?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

@vvikramraj
Copy link
Contributor

as discussed please sync and remove reference directory.

also should the html files be checked in?

The html files seem to contain the test output. I reckon we can safely leave them out.

@jingtang10 jingtang10 assigned kevinmost and vvikramraj and unassigned epicadk Mar 17, 2022
@jingtang10
Copy link
Collaborator

@vvikramraj + @kevinmost will you be able to investigate further and see if we can get this PR to be merged in some shape or form?

@epicadk
Copy link
Contributor

epicadk commented Mar 17, 2022

@vvikramraj + @kevinmost will you be able to investigate further and see if we can get this PR to be merged in some shape or form?

as @aditya-07 pointed out, the plugin doesn't support API level 30+, so I'm not sure theres a lot we can do.

@epicadk
Copy link
Contributor

epicadk commented Mar 17, 2022

@jingtang10
Copy link
Collaborator

thanks @epicadk - we'll close this PR for now.

also worth noting that you can also take screenshots in espresso tests. https://github.com/android/testing-samples

@jingtang10 jingtang10 closed this Apr 25, 2022
@jingtang10 jingtang10 deleted the av/demo_screenshot_testing branch July 1, 2022 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

7 participants