How to trigger an Android LongClick in Xamarin UI Test - xamarin

I've got a RecyclerView with a ActionMode which can be activated by a long click on a RecyclerView item.
How to trigger a long click in Android with Xamarin UI tests?
AndroidApp contains a method TouchAndHold(Func query) but this one seems not to trigger a long click.
Anyone here have a solution?
My code:
Func<AppQuery, AppQuery> test = c => c.Marked("Test");
app.WaitForElement (test);
app.TouchAndHold (test);

TouchAndHold should trigger a LongClick.
I forgot to build a new release apk where i implemented the OnLongClick functionality. After building a new apk the TouchAndHold worked as expected

Related

Using Xamarin Essentials in Xamarin UI Test project

I am trying to open Browser with a link inside my test method (application is launched prior to that). I installed Xamarin essentials Nuget, and per my current understanding I am not able to use this package outside xamarin project. I found some solutions (see below, using Mock object) but this does not seem to work.
var mockLaunch = new Mock();
IBrowser open = mockLaunch.Object;
open.OpenAsync("https://i389l.app.link/JFsYo6d1Y37", BrowserLaunchMode.SystemPreferred);
Does anyone have solution how to open browser (using real Android device) inside my test method? Thank you.

Xamarin WebView sometimes doesn't show in UWP

I have a WebView that shows the terms and conditions when the user starts the app. That WebView contains a few links. Currently, I have the terms and conditions as a html file that I store in resources.
In the code-behind I fill the WebView via:
public partial class Agb : ContentPage
{
public Agb()
{
InitializeComponent();
BindingContext = new ViewModel.AgbViewModel();
Web.Source = new HtmlWebViewSource
{
Html = Properties.Resources.Agb
};
Web.Navigating += WebViewNavigating;
}
XML:
<WebView
x:Name="Web"
VerticalOptions="FillAndExpand"
Margin="50,0"/>
Most of the time this works well. On UWP this WebView sometimes fails to show. It always shows on my own computer but randomly fails in production.
Is there anything I can do to get the WebView to work reliably?
Option 1:
I've made a pull request to fix this bug in Xamarin.Forms, so simply update Xamarin.Forms to a version, where it will be merged.
However, while the fix is not yet there and while the fix may not be available for earlier versions of Xamarin.Forms before 4.4.0, here's how to fix it in your project:
Option 2
Add the WebViewRenderer_fix.cs file to your project. This file is based on v4.4.0, but if you see build errors, you may need to apply the fix yourself to earlier version of this file.
And don't forget to register it as a custom renderer for your WebView
[assembly: ExportRenderer(typeof(WebView), typeof(WebViewRenderer_fix))]

IconToolbarItem with Iconize not click event

I am currently developing a Xamarin.Forms application. I am using IconizePlugin. The app is tabbedPage based and on toolbar I'm trying to include icons for some actions.
This is whay I'm getting:
Icons are showing well and in Xamarin.iOS gets the click event, while it is not working in Xamarin.Droid.
I included the corresponding nugets and followed every steps told in documentation and can't archive this. Other iconize controls in Droid are working fine except the IconToolbarItem.
Please help!
The workaround I found was to declare de IconToolbarItem in the c# code instead of xaml. Although I don't know why it wasn't working while on xaml.
Declaring the item li
ToolbarItems.Add(new IconToolbarItem
{
Icon = "fa-plus",
IconColor = Color.White,
Command = new Command(this.addBono)
});

Unable To Share Text On Xamarin Form

Hello Everyone I want to share the Text on Xamarin Form using Library plugin.share. I have successfully implemented the library and on android i can able to share the text but in iOS it returns me nothing. i have done the share code on button click event so when i click on button in iOS its doesn't returns me anything.i tried the Below code but doesn't got succeed
CrossShare.Current.Share("Hii alll", "Share");
please help me to get out of this,thanks in advance
You want to take a look at UIActivityViewController, you can find the documentation here https://developer.xamarin.com/api/type/MonoTouch.UIKit.UIActivityViewController/
And Xamarin.Forms specific example http://devcenter.wintellect.com/jwood/implementing-sharing-in-xamarin-forms
This is a bit old, but I was having a similar issue and was able to resolve it.
First of all, you need to add the plugin Plugin.Share to ALL Xamarin.Forms projects (Portable, iOS, Android, UWP).
In the class that references the share code, add...
using Plugin.Share;
using Plugin.Share.Abstractions;
CrossShare.Share() doesn't work with strings, directly. You need to new up a ShareMessage.
var title = "Title For The Share";
var message = "Text to share.";
await CrossShare.Current.Share(new ShareMessage { Text = message, Title = title });
I can't say specifically to iOS, as I don't have a Mac and can't test that project, but Android and Windows 10 is working.

Q: AutomationId not getting set on Android with Forms

I have a suite of UITest for our Xamarin Forms project. All of the AutomationId's are present in the XAML file and work fine on the iOS project. However when running the tests on Android the AutomationId is not there which is causing my tests to fail.
I've doubled checked using REPL and tree to inspect each view for it's Id's
Are you initializing the AutomationId's in the OnCreate of the MainActivity in the Android native project?
After the Xamarin.Forms.Forms.Init (this, bundle); :
Xamarin.Forms.Forms.ViewInitialized += (object sender, Xamarin.Forms.ViewInitializedEventArgs e) => {
if (!string.IsNullOrWhiteSpace (e.View.AutomationId)) {
e.NativeView.ContentDescription = e.View.AutomationId;
}
};
In android app build using Xamarin Forms, the automation id is converted to cont-desc. You can use cont-desc for your test.
There is no automationId itself visible in REPL, but only label or id with the value equal to that set on the automationId, so you should just use Marked passing in the value.

Resources