Make Xamarin.Uitest Tap Hamburger Icon in drawerlayout toolbar

948 Views Asked by At

I have a xamarin.uitestApp running in Visual Studio, I want to write tests for an App that uses the drawerlayout for navigation.

How do I make Xamarin.Uitest tap the Hamburger Icon in drawerlayout toolbar?

I have tried:

app.WaitForElement(c => c.Marked("toolbar"));
app.Tap(c => c.Marked("toolbar"));

The test succeeds, but the drawer is not opened.

Thanks in advance.

4

There are 4 best solutions below

2
On

This is pretty straight forward. Assign AutomationId to your burger menu view, whether this is in XAML or in code. Then you can tap on it with the same code you used, just replace "toolbar" with whatever Name you gave to AutomationId.

1
On

On iOS, the menu button is drawn by the App and you can therefore assign an automationId to it either in XAML or in your app-code through the AutomationId-property.

In your test, you can then call it using app.Tap("yourAutomationId")

On Android, the button is drawn by the OS and therefore has a fixed automation id which you can't change. AFAIK, the id is always OK and you can therefore tap the button using

app.Tap("OK")
0
On

I ended up using the class to open the drawer

app.Tap(c => c.Class("OverflowMenuButton"));
0
On

Try to run repl check is there any id associated with your navigation drawer. If not you can use below query that I mentioned.

app.Tap(x=>x.Class("NavigationDrawerClassNams"));

Hope it will help you.