Reputation: 17
I am implementing Page object Pattern framework for a sample Xamarin App and when I tried running a simple test to verify button click I am getting the following error: Query for Marked("Click Me!") gave 0 results.
I had tried running a test without setting up the framework and it was running fine but after setting up the framework it gives me the error.
This is my Page Object file
namespace SampleUITests.Pages
{
using Query = System.Func<Xamarin.UITest.Queries.AppQuery, Xamarin.UITest.Queries.AppQuery>;
public class WelcomePage : BasePage
{
readonly Query ClickButton;
readonly Query Label;
protected override PlatformQuery Trait => new PlatformQuery
{
Android = x => x.Marked("Click Me!")
//Can add iOS trait as well
};
public WelcomePage()
{
if (OnAndroid)
{
Label = x => x.Marked("Welcome To Xamarin.Forms!");
ClickButton = x => x.Marked("Click Me!");
}
if (OniOS)
{
//add iOS identifiers here
}
}
public void OnClick()
{
app.Repl();
app.WaitForElement(ClickButton);
app.Tap(ClickButton);
Assert.Equals("You clicked 1 times.", app.Query(ClickButton).First().Text);
}
}
}
This is my code where I am calling the object for Page object and running the test.
namespace SampleUITests
{
[TestFixture(Platform.Android)]
[TestFixture(Platform.iOS)]
public class Tests : BaseTestFixture
{
public Tests(Platform platform) : base(platform)
{
//this.platform = platform;
}
[Test]
public void VerifyButtonClick()
{
WelcomePage welcomepage = new WelcomePage();
welcomepage.OnClick();
}
}
}
I am expecting the test to pass which verifies the button click and the text on the button (You clicked 1 times.) but I am getting the below error:
Android test running Xamarin.UITest version: 3.0.3
Initializing Android app on device emulator-5554 with apk: C:\Users\Sayali.Sheode\AppData\Local\Xamarin\Mono for Android\Archives\2019-08-16\FirstXamarinApp.Android 8-16-19 9.17 AM.apkarchive\com.companyname.firstxamarinapp.apk
Skipping local screenshots. Can be enabled with EnableScreenshots() when configuring app.
Signing apk with Xamarin keystore.
Skipping installation: Already installed.
Waiting for element matching Marked("Click Me!").
Waiting for element matching Marked("Click Me!"). Using element matching Marked("Click Me!"). Tapping coordinates [ 540, 1731 ].
Query for Marked("Click Me!") gave 0 results.
Also this is the stack trace:
Message:
System.InvalidOperationException : Sequence contains no elements
Stack Trace:
at Enumerable.First[TSource](IEnumerable`1 source)
at WelcomePage.OnClick() in WelcomePage.cs line: 43
at Tests.VerifyButtonClick() in Tests.cs line: 36
Upvotes: 0
Views: 1116
Reputation: 17
After further debugging and researching I found out that the
ClickButton = x => x.Marked("Click Me!");
should have been identified via the ID and not the Text on the button because the text on the button changes when clicked.
Changed the identifier to the following and the test passed:
ClickButton = x => x.Id("NoResourceEntry-3");
Upvotes: 1