Xamarin UI test giving the error: Query for Marked("Click Me!") gave 0 results
Xamarin UI test giving the error: Query for Marked("Click Me!") gave 0 results
我正在为示例 Xamarin 应用程序实现页面对象模式框架,当我尝试 运行 一个简单的测试来验证按钮点击时,我收到以下错误:查询标记("Click Me!")给出了 0 个结果。
我在没有设置框架的情况下尝试了 运行 测试,结果 运行 很好,但是在设置框架之后它给了我错误。
这是我的页面对象文件
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);
}
}
}
这是我的代码,我在其中调用 Page 对象的对象和 运行 测试。
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();
}
}
}
我希望通过验证按钮点击和按钮上的文本(您点击了 1 次。)的测试,但我收到以下错误:
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\Archives19-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.
这也是堆栈跟踪:
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
经过进一步的调试和研究,我发现
ClickButton = x => x.Marked("Click Me!");
应该通过 ID 而不是按钮上的文本来识别,因为单击时按钮上的文本会发生变化。
将标识符更改为以下内容并通过测试:
ClickButton = x => x.Id("NoResourceEntry-3");
我正在为示例 Xamarin 应用程序实现页面对象模式框架,当我尝试 运行 一个简单的测试来验证按钮点击时,我收到以下错误:查询标记("Click Me!")给出了 0 个结果。
我在没有设置框架的情况下尝试了 运行 测试,结果 运行 很好,但是在设置框架之后它给了我错误。
这是我的页面对象文件
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);
}
}
}
这是我的代码,我在其中调用 Page 对象的对象和 运行 测试。
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();
}
}
}
我希望通过验证按钮点击和按钮上的文本(您点击了 1 次。)的测试,但我收到以下错误:
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\Archives19-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.
这也是堆栈跟踪:
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
经过进一步的调试和研究,我发现
ClickButton = x => x.Marked("Click Me!");
应该通过 ID 而不是按钮上的文本来识别,因为单击时按钮上的文本会发生变化。
将标识符更改为以下内容并通过测试:
ClickButton = x => x.Id("NoResourceEntry-3");