In my Android application I have Toolbar and need to perform action for tool bar back button click in Espresso. I have tried the following but it does not work
onView(withId(R.id.pageToolbar)).perform(click());
Need to perform its back button click action.
How to enable back button in action bar? How to enable back button in action bar? This example demonstrates How to get action bar tittle in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.xml.
How to add Back Button (Arrow) to Toolbar 1 Open your Activity class file: Example - MainActivity.java 2 Add the below lines just after super.onCreate (savedInstanceState); in the onCreate () method,#N#package com.example. 3 Now run your App you should see the back arrow button displayed just before the Title. More ...
This example demonstrates How to get action bar tittle in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.xml. In the above code, we have taken text view. Let's try to run your application.
ToolBar Tutorial With Example In Android Studio 1 Define Design Support Library: To use Toolbar you need to add design support library in build.gradle file. 2 Elements of Toolbar In Android: In Android Toolbar has more features than ActionBar and we can easily replace a ActionBar with Toolbar. 3 Basic Toolbar XML code: More items...
The ContentDescription
didn't work for me, so I had to use:
onView(allOf(
instanceOf(AppCompatImageButton::class.java), withParent(withId(R.id.toolbar))
))
.perform(click())
because I have not way to identify it univocally in the hierarchy tree:
+-------->AppCompatImageButton{id=-1, visibility=VISIBLE, width=147, height=147, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, layout-params=androidx.appcompat.widget.Toolbar$LayoutParams@acd01cf, tag=null, root-is-layout-requested=false, has-input-connection=false, x=21.0, y=0.0}
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