Automating Xamarin ToolbarItem click The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceDoes anyone have benchmarks (code & results) comparing performance of Android apps written in Xamarin C# and Java?When to use Xamarin.Forms vs Xamarin Native?Binding ToolbarItem Click in Xamarin.FormsXamarin Forms set a ToolBarItem icon to a resource imageToolbarItems button click not working in xamarin formsXamarin Forms ToolbarItem poor animationXamarin ToolBarItem click event not redirecting pageOutputting Xamarin.UITest REPL tree to failed test resultsXamarin ToolBarItems Navigation rulesXamarin Forms Automation Id for toolbaritems
Did war bonds have better investment alternatives during WWII?
My admission is revoked after accepting the admission offer
Why does Java have support for time zone offsets with seconds precision?
What is ls Largest Number Formed by only moving two sticks in 508?
How would it unbalance gameplay to rule that Weapon Master allows for picking a fighting style?
Why did Europeans not widely domesticate foxes?
Israeli soda type drink
What is the purpose of the side handle on a hand ("eggbeater") drill?
Suing a Police Officer Instead of the Police Department
How did Elite on the NES work?
Was Objective-C really a hindrance to Apple software development?
Is there a way to fake a method response using Mock or Stubs?
`FindRoot [ ]`::jsing: Encountered a singular Jacobian at a point...WHY
When does Bran Stark remember Jamie pushing him?
Eigenvalues of the Laplacian of the directed De Bruijn graph
What *exactly* is electrical current, voltage, and resistance?
What happened to Viserion in Season 7?
How to translate "red flag" into Spanish?
"Working on a knee"
RIP Packet Format
How to begin with a paragraph in latex
SQL Server placement of master database files vs resource database files
Coin Game with infinite paradox
Preserving file and folder permissions with rsync
Automating Xamarin ToolbarItem click
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experienceDoes anyone have benchmarks (code & results) comparing performance of Android apps written in Xamarin C# and Java?When to use Xamarin.Forms vs Xamarin Native?Binding ToolbarItem Click in Xamarin.FormsXamarin Forms set a ToolBarItem icon to a resource imageToolbarItems button click not working in xamarin formsXamarin Forms ToolbarItem poor animationXamarin ToolBarItem click event not redirecting pageOutputting Xamarin.UITest REPL tree to failed test resultsXamarin ToolBarItems Navigation rulesXamarin Forms Automation Id for toolbaritems
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I'm using Xamarin.UITest to write some automation.
The target app has this in its markup:
<ContentPage.ToolbarItems>
<ToolbarItem Icon="Settings" AutomationId="SettingsToolbarItem" Order="Primary" Priority="1" Command="Binding ShowSettingsCommand" />
</ContentPage.ToolbarItems>
So far I've had 3 approaches:
Using .Class and Indexing successfully finds the element
systemMenuButton = x => x.Class("android.support.v7.view.menu.ActionMenuItemView").Index(1);
Using .Property fails to find the element
systemMenuButton = e => e.Property("Command", "ShowSettingsCommand");
Similarly, using .Marked also fails to find the element
systemMenuButton = x => x.Marked("SettingsToolbarItem");
Relevant automation code is as follows:
using Query = System.Func<Xamarin.UITest.Queries.AppQuery, Xamarin.UITest.Queries.AppQuery>;
....
protected readonly Query systemMenuButton = x => x.Marked("SettingsToolbarItem");
....
app.Tap(systemMenuButton);
I get a generic "unable to find element" exception:
Unable to find element. Query for Marked("SettingsToolbarItem") gave no results.
I don't get this exception when clicking on other elements outside the ContentPage.ToolbarItems block on the same View/Page
c# xamarin xamarin.forms xamarin.uitest
|
I'm using Xamarin.UITest to write some automation.
The target app has this in its markup:
<ContentPage.ToolbarItems>
<ToolbarItem Icon="Settings" AutomationId="SettingsToolbarItem" Order="Primary" Priority="1" Command="Binding ShowSettingsCommand" />
</ContentPage.ToolbarItems>
So far I've had 3 approaches:
Using .Class and Indexing successfully finds the element
systemMenuButton = x => x.Class("android.support.v7.view.menu.ActionMenuItemView").Index(1);
Using .Property fails to find the element
systemMenuButton = e => e.Property("Command", "ShowSettingsCommand");
Similarly, using .Marked also fails to find the element
systemMenuButton = x => x.Marked("SettingsToolbarItem");
Relevant automation code is as follows:
using Query = System.Func<Xamarin.UITest.Queries.AppQuery, Xamarin.UITest.Queries.AppQuery>;
....
protected readonly Query systemMenuButton = x => x.Marked("SettingsToolbarItem");
....
app.Tap(systemMenuButton);
I get a generic "unable to find element" exception:
Unable to find element. Query for Marked("SettingsToolbarItem") gave no results.
I don't get this exception when clicking on other elements outside the ContentPage.ToolbarItems block on the same View/Page
c# xamarin xamarin.forms xamarin.uitest
|
I'm using Xamarin.UITest to write some automation.
The target app has this in its markup:
<ContentPage.ToolbarItems>
<ToolbarItem Icon="Settings" AutomationId="SettingsToolbarItem" Order="Primary" Priority="1" Command="Binding ShowSettingsCommand" />
</ContentPage.ToolbarItems>
So far I've had 3 approaches:
Using .Class and Indexing successfully finds the element
systemMenuButton = x => x.Class("android.support.v7.view.menu.ActionMenuItemView").Index(1);
Using .Property fails to find the element
systemMenuButton = e => e.Property("Command", "ShowSettingsCommand");
Similarly, using .Marked also fails to find the element
systemMenuButton = x => x.Marked("SettingsToolbarItem");
Relevant automation code is as follows:
using Query = System.Func<Xamarin.UITest.Queries.AppQuery, Xamarin.UITest.Queries.AppQuery>;
....
protected readonly Query systemMenuButton = x => x.Marked("SettingsToolbarItem");
....
app.Tap(systemMenuButton);
I get a generic "unable to find element" exception:
Unable to find element. Query for Marked("SettingsToolbarItem") gave no results.
I don't get this exception when clicking on other elements outside the ContentPage.ToolbarItems block on the same View/Page
c# xamarin xamarin.forms xamarin.uitest
I'm using Xamarin.UITest to write some automation.
The target app has this in its markup:
<ContentPage.ToolbarItems>
<ToolbarItem Icon="Settings" AutomationId="SettingsToolbarItem" Order="Primary" Priority="1" Command="Binding ShowSettingsCommand" />
</ContentPage.ToolbarItems>
So far I've had 3 approaches:
Using .Class and Indexing successfully finds the element
systemMenuButton = x => x.Class("android.support.v7.view.menu.ActionMenuItemView").Index(1);
Using .Property fails to find the element
systemMenuButton = e => e.Property("Command", "ShowSettingsCommand");
Similarly, using .Marked also fails to find the element
systemMenuButton = x => x.Marked("SettingsToolbarItem");
Relevant automation code is as follows:
using Query = System.Func<Xamarin.UITest.Queries.AppQuery, Xamarin.UITest.Queries.AppQuery>;
....
protected readonly Query systemMenuButton = x => x.Marked("SettingsToolbarItem");
....
app.Tap(systemMenuButton);
I get a generic "unable to find element" exception:
Unable to find element. Query for Marked("SettingsToolbarItem") gave no results.
I don't get this exception when clicking on other elements outside the ContentPage.ToolbarItems block on the same View/Page
c# xamarin xamarin.forms xamarin.uitest
c# xamarin xamarin.forms xamarin.uitest
edited Mar 22 at 17:28
Brandon Minnick
6,935123278
6,935123278
asked Mar 18 at 17:31
Doug ClarkDoug Clark
295318
295318
|
|
1 Answer
1
active
oldest
votes
I've hit the same problem - for some reason Android can't detect ToolbarItem.AutomationId
.
A workaround is to assign ToolbarItem.Text
the same value as ToolbarItem.AutomationId
.
Xamarin.Forms.ContentPage
<ContentPage.ToolbarItems>
<ToolbarItem Icon="Settings" Text="SettingsToolbarItem" AutomationId="SettingsToolbarItem" Order="Primary" Priority="1" Command="Binding ShowSettingsCommand" />
</ContentPage.ToolbarItems>
Xamarin.UITest
using Query = System.Func<Xamarin.UITest.Queries.AppQuery, Xamarin.UITest.Queries.AppQuery>;
// ....
protected readonly Query systemMenuButton = x => x.Marked("SettingsToolbarItem");
//....
public void TapSystemMenuButton()
app.Tap(systemMenuButton);
app.Screenshot("Tapped System Menu Button");
Here's is a sample app where I use similar logic to tap a ToolbarItem in a UITest: https://github.com/brminnick/InvestmentDataSampleApp/
Edit
In the comments, you mentioned that you do not have access to the source code of the Xamarin.Forms app.
If you are unable to change the Xamarin.Forms source code, you will have to use x => x.Class("ActionMenuItemView").Index(1)
.
I don't recommend going this route because the int parameter of Index
can vary depending on the device; it is not guaranteed to always be 1
.
public void TapSystemMenuButton()
if (app is iOSApp)
app.Tap(systemMenuButton);
else
app.Tap(x => x.Class("ActionMenuItemView").Index(1));
app.Screenshot("Tapped System Menu Button");
is there a way to differentiate between multiple icons without indexing? i already use class and its not my preferred solution
– Doug Clark
Mar 22 at 18:09
Yup - there's a workaround. I'll update the answer.
– Brandon Minnick
Mar 22 at 18:21
I updated the answer and the corresponding sample app to include this workaround 👍
– Brandon Minnick
Mar 22 at 18:41
Does the text you added to the ToolbarItem display in the toolbar? what if i dont have access or cannot change certain aspects of the sourcecode
– Doug Clark
Mar 22 at 18:47
The text will not appear because you are using an Icon. If you can't change the source code, you will need to useapp.Tap(x => x.Class("ActionMenuItemView").Index(1));
. I recommend working with the development team to add this to the source code because the int parameter of.Index()
is not guaranteed to always be the same, and if/when it changes your tests will fail.
– Brandon Minnick
Mar 22 at 18:50
|
show 1 more comment
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I've hit the same problem - for some reason Android can't detect ToolbarItem.AutomationId
.
A workaround is to assign ToolbarItem.Text
the same value as ToolbarItem.AutomationId
.
Xamarin.Forms.ContentPage
<ContentPage.ToolbarItems>
<ToolbarItem Icon="Settings" Text="SettingsToolbarItem" AutomationId="SettingsToolbarItem" Order="Primary" Priority="1" Command="Binding ShowSettingsCommand" />
</ContentPage.ToolbarItems>
Xamarin.UITest
using Query = System.Func<Xamarin.UITest.Queries.AppQuery, Xamarin.UITest.Queries.AppQuery>;
// ....
protected readonly Query systemMenuButton = x => x.Marked("SettingsToolbarItem");
//....
public void TapSystemMenuButton()
app.Tap(systemMenuButton);
app.Screenshot("Tapped System Menu Button");
Here's is a sample app where I use similar logic to tap a ToolbarItem in a UITest: https://github.com/brminnick/InvestmentDataSampleApp/
Edit
In the comments, you mentioned that you do not have access to the source code of the Xamarin.Forms app.
If you are unable to change the Xamarin.Forms source code, you will have to use x => x.Class("ActionMenuItemView").Index(1)
.
I don't recommend going this route because the int parameter of Index
can vary depending on the device; it is not guaranteed to always be 1
.
public void TapSystemMenuButton()
if (app is iOSApp)
app.Tap(systemMenuButton);
else
app.Tap(x => x.Class("ActionMenuItemView").Index(1));
app.Screenshot("Tapped System Menu Button");
is there a way to differentiate between multiple icons without indexing? i already use class and its not my preferred solution
– Doug Clark
Mar 22 at 18:09
Yup - there's a workaround. I'll update the answer.
– Brandon Minnick
Mar 22 at 18:21
I updated the answer and the corresponding sample app to include this workaround 👍
– Brandon Minnick
Mar 22 at 18:41
Does the text you added to the ToolbarItem display in the toolbar? what if i dont have access or cannot change certain aspects of the sourcecode
– Doug Clark
Mar 22 at 18:47
The text will not appear because you are using an Icon. If you can't change the source code, you will need to useapp.Tap(x => x.Class("ActionMenuItemView").Index(1));
. I recommend working with the development team to add this to the source code because the int parameter of.Index()
is not guaranteed to always be the same, and if/when it changes your tests will fail.
– Brandon Minnick
Mar 22 at 18:50
|
show 1 more comment
I've hit the same problem - for some reason Android can't detect ToolbarItem.AutomationId
.
A workaround is to assign ToolbarItem.Text
the same value as ToolbarItem.AutomationId
.
Xamarin.Forms.ContentPage
<ContentPage.ToolbarItems>
<ToolbarItem Icon="Settings" Text="SettingsToolbarItem" AutomationId="SettingsToolbarItem" Order="Primary" Priority="1" Command="Binding ShowSettingsCommand" />
</ContentPage.ToolbarItems>
Xamarin.UITest
using Query = System.Func<Xamarin.UITest.Queries.AppQuery, Xamarin.UITest.Queries.AppQuery>;
// ....
protected readonly Query systemMenuButton = x => x.Marked("SettingsToolbarItem");
//....
public void TapSystemMenuButton()
app.Tap(systemMenuButton);
app.Screenshot("Tapped System Menu Button");
Here's is a sample app where I use similar logic to tap a ToolbarItem in a UITest: https://github.com/brminnick/InvestmentDataSampleApp/
Edit
In the comments, you mentioned that you do not have access to the source code of the Xamarin.Forms app.
If you are unable to change the Xamarin.Forms source code, you will have to use x => x.Class("ActionMenuItemView").Index(1)
.
I don't recommend going this route because the int parameter of Index
can vary depending on the device; it is not guaranteed to always be 1
.
public void TapSystemMenuButton()
if (app is iOSApp)
app.Tap(systemMenuButton);
else
app.Tap(x => x.Class("ActionMenuItemView").Index(1));
app.Screenshot("Tapped System Menu Button");
is there a way to differentiate between multiple icons without indexing? i already use class and its not my preferred solution
– Doug Clark
Mar 22 at 18:09
Yup - there's a workaround. I'll update the answer.
– Brandon Minnick
Mar 22 at 18:21
I updated the answer and the corresponding sample app to include this workaround 👍
– Brandon Minnick
Mar 22 at 18:41
Does the text you added to the ToolbarItem display in the toolbar? what if i dont have access or cannot change certain aspects of the sourcecode
– Doug Clark
Mar 22 at 18:47
The text will not appear because you are using an Icon. If you can't change the source code, you will need to useapp.Tap(x => x.Class("ActionMenuItemView").Index(1));
. I recommend working with the development team to add this to the source code because the int parameter of.Index()
is not guaranteed to always be the same, and if/when it changes your tests will fail.
– Brandon Minnick
Mar 22 at 18:50
|
show 1 more comment
I've hit the same problem - for some reason Android can't detect ToolbarItem.AutomationId
.
A workaround is to assign ToolbarItem.Text
the same value as ToolbarItem.AutomationId
.
Xamarin.Forms.ContentPage
<ContentPage.ToolbarItems>
<ToolbarItem Icon="Settings" Text="SettingsToolbarItem" AutomationId="SettingsToolbarItem" Order="Primary" Priority="1" Command="Binding ShowSettingsCommand" />
</ContentPage.ToolbarItems>
Xamarin.UITest
using Query = System.Func<Xamarin.UITest.Queries.AppQuery, Xamarin.UITest.Queries.AppQuery>;
// ....
protected readonly Query systemMenuButton = x => x.Marked("SettingsToolbarItem");
//....
public void TapSystemMenuButton()
app.Tap(systemMenuButton);
app.Screenshot("Tapped System Menu Button");
Here's is a sample app where I use similar logic to tap a ToolbarItem in a UITest: https://github.com/brminnick/InvestmentDataSampleApp/
Edit
In the comments, you mentioned that you do not have access to the source code of the Xamarin.Forms app.
If you are unable to change the Xamarin.Forms source code, you will have to use x => x.Class("ActionMenuItemView").Index(1)
.
I don't recommend going this route because the int parameter of Index
can vary depending on the device; it is not guaranteed to always be 1
.
public void TapSystemMenuButton()
if (app is iOSApp)
app.Tap(systemMenuButton);
else
app.Tap(x => x.Class("ActionMenuItemView").Index(1));
app.Screenshot("Tapped System Menu Button");
I've hit the same problem - for some reason Android can't detect ToolbarItem.AutomationId
.
A workaround is to assign ToolbarItem.Text
the same value as ToolbarItem.AutomationId
.
Xamarin.Forms.ContentPage
<ContentPage.ToolbarItems>
<ToolbarItem Icon="Settings" Text="SettingsToolbarItem" AutomationId="SettingsToolbarItem" Order="Primary" Priority="1" Command="Binding ShowSettingsCommand" />
</ContentPage.ToolbarItems>
Xamarin.UITest
using Query = System.Func<Xamarin.UITest.Queries.AppQuery, Xamarin.UITest.Queries.AppQuery>;
// ....
protected readonly Query systemMenuButton = x => x.Marked("SettingsToolbarItem");
//....
public void TapSystemMenuButton()
app.Tap(systemMenuButton);
app.Screenshot("Tapped System Menu Button");
Here's is a sample app where I use similar logic to tap a ToolbarItem in a UITest: https://github.com/brminnick/InvestmentDataSampleApp/
Edit
In the comments, you mentioned that you do not have access to the source code of the Xamarin.Forms app.
If you are unable to change the Xamarin.Forms source code, you will have to use x => x.Class("ActionMenuItemView").Index(1)
.
I don't recommend going this route because the int parameter of Index
can vary depending on the device; it is not guaranteed to always be 1
.
public void TapSystemMenuButton()
if (app is iOSApp)
app.Tap(systemMenuButton);
else
app.Tap(x => x.Class("ActionMenuItemView").Index(1));
app.Screenshot("Tapped System Menu Button");
edited Mar 22 at 18:57
answered Mar 22 at 17:28
Brandon MinnickBrandon Minnick
6,935123278
6,935123278
is there a way to differentiate between multiple icons without indexing? i already use class and its not my preferred solution
– Doug Clark
Mar 22 at 18:09
Yup - there's a workaround. I'll update the answer.
– Brandon Minnick
Mar 22 at 18:21
I updated the answer and the corresponding sample app to include this workaround 👍
– Brandon Minnick
Mar 22 at 18:41
Does the text you added to the ToolbarItem display in the toolbar? what if i dont have access or cannot change certain aspects of the sourcecode
– Doug Clark
Mar 22 at 18:47
The text will not appear because you are using an Icon. If you can't change the source code, you will need to useapp.Tap(x => x.Class("ActionMenuItemView").Index(1));
. I recommend working with the development team to add this to the source code because the int parameter of.Index()
is not guaranteed to always be the same, and if/when it changes your tests will fail.
– Brandon Minnick
Mar 22 at 18:50
|
show 1 more comment
is there a way to differentiate between multiple icons without indexing? i already use class and its not my preferred solution
– Doug Clark
Mar 22 at 18:09
Yup - there's a workaround. I'll update the answer.
– Brandon Minnick
Mar 22 at 18:21
I updated the answer and the corresponding sample app to include this workaround 👍
– Brandon Minnick
Mar 22 at 18:41
Does the text you added to the ToolbarItem display in the toolbar? what if i dont have access or cannot change certain aspects of the sourcecode
– Doug Clark
Mar 22 at 18:47
The text will not appear because you are using an Icon. If you can't change the source code, you will need to useapp.Tap(x => x.Class("ActionMenuItemView").Index(1));
. I recommend working with the development team to add this to the source code because the int parameter of.Index()
is not guaranteed to always be the same, and if/when it changes your tests will fail.
– Brandon Minnick
Mar 22 at 18:50
is there a way to differentiate between multiple icons without indexing? i already use class and its not my preferred solution
– Doug Clark
Mar 22 at 18:09
is there a way to differentiate between multiple icons without indexing? i already use class and its not my preferred solution
– Doug Clark
Mar 22 at 18:09
Yup - there's a workaround. I'll update the answer.
– Brandon Minnick
Mar 22 at 18:21
Yup - there's a workaround. I'll update the answer.
– Brandon Minnick
Mar 22 at 18:21
I updated the answer and the corresponding sample app to include this workaround 👍
– Brandon Minnick
Mar 22 at 18:41
I updated the answer and the corresponding sample app to include this workaround 👍
– Brandon Minnick
Mar 22 at 18:41
Does the text you added to the ToolbarItem display in the toolbar? what if i dont have access or cannot change certain aspects of the sourcecode
– Doug Clark
Mar 22 at 18:47
Does the text you added to the ToolbarItem display in the toolbar? what if i dont have access or cannot change certain aspects of the sourcecode
– Doug Clark
Mar 22 at 18:47
The text will not appear because you are using an Icon. If you can't change the source code, you will need to use
app.Tap(x => x.Class("ActionMenuItemView").Index(1));
. I recommend working with the development team to add this to the source code because the int parameter of .Index()
is not guaranteed to always be the same, and if/when it changes your tests will fail.– Brandon Minnick
Mar 22 at 18:50
The text will not appear because you are using an Icon. If you can't change the source code, you will need to use
app.Tap(x => x.Class("ActionMenuItemView").Index(1));
. I recommend working with the development team to add this to the source code because the int parameter of .Index()
is not guaranteed to always be the same, and if/when it changes your tests will fail.– Brandon Minnick
Mar 22 at 18:50
|
show 1 more comment