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?
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.
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.
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.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With