Reputation: 191
I am working on Xamarin forms application where I'm using Toast.Forms.Plugin
to show the popups when ever there is invalid login. I'm not able to understand how to write the UI test case to test negative login scenario to check the text on that toast as there is no XAML element. Please find the screenshot.
I want to test that Some success text is available or not.
Upvotes: 0
Views: 1161
Reputation: 32320
In Xamarin Android you can show as usual like
Toast.MakeText(this,"toast message", ToastLength.Long).Show();
In Xamarin iOS you have to use custom designed UIView with animation to achieve the same effect
public void ShowToast(String message, UIView view)
{
UIView residualView = view.ViewWithTag(1989);
if (residualView != null)
residualView.RemoveFromSuperview();
var viewBack = new UIView(new CoreGraphics.CGRect(83, 0, 300, 100));
viewBack.BackgroundColor = UIColor.Black;
viewBack.Tag = 1989;
UILabel lblMsg = new UILabel(new CoreGraphics.CGRect(0, 20, 300, 60));
lblMsg.Lines = 2;
lblMsg.Text = message;
lblMsg.TextColor = UIColor.White;
lblMsg.TextAlignment = UITextAlignment.Center;
viewBack.Center = view.Center;
viewBack.AddSubview(lblMsg);
view.AddSubview(viewBack);
roundtheCorner(viewBack);
UIView.BeginAnimations("Toast");
UIView.SetAnimationDuration(3.0f);
viewBack.Alpha = 0.0f;
UIView.CommitAnimations();
}
Upvotes: 2