diff --git a/app/build.gradle b/app/build.gradle index 8ef4fa8f4..1b187d219 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -91,6 +91,7 @@ dependencies { androidTestImplementation "androidx.test:core:1.4.0" androidTestImplementation "androidx.test.ext:junit:1.1.3" androidTestImplementation "androidx.test:rules:1.4.0" + androidTestImplementation "androidx.test.espresso:espresso-core:3.4.0" // ViewModel implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version" diff --git a/app/src/androidTest/java/in/testpress/testpress/fragment/WebViewFragmentTest.kt b/app/src/androidTest/java/in/testpress/testpress/fragment/WebViewFragmentTest.kt new file mode 100644 index 000000000..26b05173b --- /dev/null +++ b/app/src/androidTest/java/in/testpress/testpress/fragment/WebViewFragmentTest.kt @@ -0,0 +1,38 @@ +package `in`.testpress.testpress.fragment + +import android.os.Bundle +import androidx.fragment.app.testing.FragmentScenario +import androidx.test.espresso.Espresso +import androidx.test.espresso.assertion.ViewAssertions +import androidx.test.espresso.matcher.ViewMatchers +import androidx.test.ext.junit.runners.AndroidJUnit4 +import `in`.testpress.testpress.R +import `in`.testpress.testpress.ui.fragments.WebViewFragment +import androidx.fragment.app.testing.launchFragmentInContainer +import org.junit.Test +import org.junit.runner.RunWith + +@RunWith(AndroidJUnit4::class) +class WebViewFragmentTest { + + @Test + fun testWebViewFragment() { + val url = "https://www.google.com" + val bundle = WebViewFragment.createArguments(url) + + // Launch the fragment + val scenario: FragmentScenario = launchFragmentInContainer( + bundle, R.style.AppTheme + ) + + // Check that the web view is displayed + Espresso.onView(ViewMatchers.withId(R.id.web_view)) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + } + + private fun WebViewFragment.Companion.createArguments(url: String): Bundle { + return Bundle().apply { + putString(URL_TO_OPEN, url) + } + } +} \ No newline at end of file