c# - 无法使用 appium 和 c# 在 ionic5 应用程序中检测选择器元素
问题描述
using OpenQA.Selenium;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Remote;
using System;
using System.Threading;
using Xunit;
namespace XUnitTestProject2
{
public class UnitTest1
{
[Fact]
public void Test1()
{
Thread.Sleep(3000);
var driver = InitiliseDriver();
//Login Page
driver.FindElement(By.Id("username")).SendKeys("TestUser");
driver.FindElement(MobileBy.Id("password")).SendKeys("newpassword");
driver.FindElement(MobileBy.Id("91268f5d-d21e-4ef5-9886-c1d19f2799a7")).Click();
}
private RemoteWebDriver InitiliseDriver()
{
//Set the capabilities
DesiredCapabilities cap = new DesiredCapabilities();
cap.SetCapability("platformName", "Android");
cap.SetCapability("platformVersion", "9.0");
cap.SetCapability("app", "C:\\Users\\jamesa\\Downloads\\app-debug.apk");
//cap.SetCapability("automationName", "uiautomator2");
return new RemoteWebDriver(new Uri("http://127.0.0.1:4723/wd/hub"), cap);
}
}
}
我的 nuget 包是 Appium.WebDriver(4.1.1); Microsoft.Net.Test.Sdk(16.0.1); Selenium.Support(3.141.0); Selenium.WebDriver(3.141.0); Xunit(2.4.0); Xunit.runner.visualstudios(2.4.0); MSTest.TestAdapter(2.1.2); MSTest.TestFramework(2.1.2)
我想要的能力是 platformName-Text-Android;平台版本 - 文本 - 9.0;应用程序 - 文本 - \\\
这是我得到的会话详细信息我确实有选择器 ID,但服务器没有选择它
注意: - 我能够成功启动应用程序,但服务器无法选择元素。- 应用程序以 Ionic 方式构建(Ionic 5)
解决方案
您需要将驱动程序上下文设置为 WEBVIEW,ionic 使用 webview(非本机)构建应用程序,您也可能希望在调试模式下构建应用程序。以下是有关使用 appium 测试混合应用程序的更多详细信息。
在您的情况下,您需要在执行测试之前添加类似的内容
driver.context("WEBVIEW");
推荐阅读
- c# - 如何通过桌面/控制台应用程序使用带有不记名令牌的 ASP.NET Web API 2.0
- spring-boot - 未将所有字段从 html 映射到控制器
- html - ":last-child" 和 ":not(:last-child)" 之间的不同行为
- c# - 如何使用 ICommand 在 MVVM 中触发 TextChanged 事件
- android - Android 导航组件活动意图标志
- python - 使用 'or' 运算符处理 dict 中的 KeyError
- python - 基于列值删除行时“列名”的语法无效
- python - nxn 数据帧到矩阵(.as_matrix 将在未来版本中删除)
- reactjs - React 应用程序性能问题
- git - 没有 .gitmodules 文件的 git 子模块?