Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Espresso - Web browser

I have a question

I want to test whether after button click the web browser is beign launched using espresso. And the question is: is it even possible to test such thing? If so any ideas how would I do that?

like image 666
user3274539 Avatar asked Feb 18 '14 13:02

user3274539


People also ask

What is the significance of espresso in Android?

Espresso is an open source android user interface (UI) testing framework developed by Google. The term Espresso is of Italian origin, meaning Coffee. Espresso is a simple, efficient and flexible testing framework.

What is WebView browser tester?

WebView, in Android, is the feature which allows any app to display a webpage as a part of its own activity, instead of opening it on a separate browser. This not only allows the app to retain the users within itself but also increases the user-experience multifold.

What is espresso Kotlin?

Espresso is a user interface-testing framework for testing android application developed in Java / Kotlin language using Android SDK. Therefore, espresso's only requirement is to develop the application using Android SDK in either Java or Kotlin and it is advised to have the latest Android Studio.

What is web browser for Android?

Web Browser for Android is the free web browser. The Web Browser is fast and easy to use, with the latest security and privacy features to help you stay safe on the internet. - Incognito Mode: Private browse the web without saving any browser history.

What is espresso-web and why should I use it?

That being said, Espresso-Web allows you to reuse your custom WebDriver atoms, which gives you a lot of flexibility, especially when writing tests that you plan to run against both standalone web apps and apps that include an Android UI. Similarly to Espresso’s onData () method, a WebView interaction comprises several Atoms.

How do I test espresso-web API?

You can use the Espresso-Web API in conjunction with other Espresso APIs to fully interact with web elements inside WebView objects. If you need to test only the WebView itself, and not the interactions between the WebView and native components in your app, consider writing a general web test using a framework like WebDriver.

How to use espresso framework as a developer?

As a developer, one needs to first understand that it’s purely an Android app UI testing framework. This explains why the Espresso Android framework is built without tight coupling to Android APIs such as getView () and getCurrentActivity (). The first step while starting with Espresso is to assume that you are a user.


1 Answers

Although it's an old question but just posting here to help anyone else. I had the same situation where i wanted to verify whether a particular url was launched in browser or not. I got real help from this link

I got it working using this chunk of code:

    Intents.init();
    Matcher<Intent> expectedIntent = allOf(hasAction(Intent.ACTION_VIEW), hasData(EXPECTED_URL));
    intending(expectedIntent).respondWith(new Instrumentation.ActivityResult(0, null));
    onView(withId(R.id.someid)).perform(click());
    intended(expectedIntent);
    Intents.release();

So, it tests when browser is opened with correct url and intending() does the magic here by enabling intent stubbing. Using this, we can intercept it so the intent is never sent to the system.

like image 190
Wahib Ul Haq Avatar answered Oct 01 '22 22:10

Wahib Ul Haq