Gajanand Swamy
Gajanand Swamy

Reputation: 2108

Test if a webpage was opened succesfully via intent using Robolectric

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?

Upvotes: 3

Views: 338

Answers (1)

Gajanand Swamy
Gajanand Swamy

Reputation: 2108

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)

Upvotes: 3

Related Questions