Test if a webpage was opened succesfully via intent using Robolectric

Viewed 105

I am having simple function as Below

fun openWebPage(url: String) {
    val openURL = Intent(Intent.ACTION_VIEW)
    openURL.data = Uri.parse(url)
    startActivity(openURL)
}

How to test and verify that webpage is opened successfully using Robolectric?

1 Answers

This code snippet helped to capture that scenario

    val shadow = Shadows.shadowOf(activity)
    val exp_url = "www.google.com"
    val intent =  shadow.nextStartedActivity
    val url = intent.data.toString()
    assertEquals(exp_url,url)
Related