winappdriver - 如何在 Win App 驱动程序中启动单击一次应用程序?
问题描述
我正在使用 Win App Driver 来自动化 WPF 应用程序,我们的 WPF 应用程序是单击一次应用程序。当我启动应用程序时,我注意到驱动程序为空。
private string notepadAppid =
@"https://saqa.xyz.biz/abcnew/testets.Shell.Applications";
protected static OpenQA.Selenium.Appium.Windows.WindowsDriver<WindowsElement> driver;
Uri urls = new Uri("http://127.0.0.1:4723");
AppiumOptions opt = new AppiumOptions();
opt.AddAdditionalCapability("app", notepadAppid);
opt.AddAdditionalCapability("deviceName", "WindowsPC");
driver = new WindowsDriver<WindowsElement> (new Uri("http://127.0.0.1:4723"), opt,
TimeSpan.FromMinutes(1));
我注意到'驱动程序'为空,我收到异常:“无法使用 appId 找到打开的应用程序窗口:https ://saqa.xyz.biz/abcnew/testets.Shell.Applications和 processId:-1。谢谢你进步。
解决方案
如前所述,您需要检查驱动程序是否为空。
//******************************************************************************
//
// Copyright (c) 2017 Microsoft Corporation. All rights reserved.
//
// This code is licensed under the MIT License (MIT).
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
//******************************************************************************
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.Appium.Windows;
using OpenQA.Selenium.Remote;
using System;
namespace CalculatorTest
{
public class CalculatorSession
{
// Note: append /wd/hub to the URL if you're directing the test at Appium
private const string WindowsApplicationDriverUrl = "http://127.0.0.1:4723";
private const string CalculatorAppId = "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App";
protected static WindowsDriver<WindowsElement> session;
public static void Setup(TestContext context)
{
// Launch Calculator application if it is not yet launched
if (session == null)
{
// Create a new session to bring up an instance of the Calculator application
// Note: Multiple calculator windows (instances) share the same process Id
DesiredCapabilities appCapabilities = new DesiredCapabilities();
appCapabilities.SetCapability("app", CalculatorAppId);
appCapabilities.SetCapability("deviceName", "WindowsPC");
session = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities);
Assert.IsNotNull(session);
// Set implicit timeout to 1.5 seconds to make element search to retry every 500 ms for at most three times
session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1.5);
}
}
public static void TearDown()
{
// Close the application and delete the session
if (session != null)
{
session.Quit();
session = null;
}
}
}
}
推荐阅读
- mysql - 计算一列的总和并按具有相同值的列分组
- python - 查找字符串,提取值
- c# - 如何使用 Console.SetCursorPosition c# 绘制对角线?
- javascript - 添加键盘快捷键
- xml - 未封闭的 XML 标记
- php - xml 的 CURL 命令无法通过 php 脚本发送
- amazon-web-services - 从 API Gateway 触发 CodeBuild 时出现 com.amazon.coral.service#UnknownOperationException
- xpath - 如何使用 IMPORTXML 仅导入表中的有限范围,而不是整个表?
- json - 运行 ng serve 时出现以下错误
- html - 如何用图像填充其余的 div 高度?