【问题标题】:Unable to open "File" or "Edit" menu in Notepad using WinAppDriver无法使用 WinAppDriver 在记事本中打开“文件”或“编辑”菜单
【发布时间】:2020-09-09 14:17:20
【问题描述】:

我正在尝试学习如何使用 WinAppDriver 来测试我在 VS2019 中开发的桌面应用程序。

我能够使用基本的 Notepad.exe 和键入文本的示例来运行 NUnit 测试。但是,例如,我无法单击记事本中的菜单元素。你是如何做到这一点的?

Inspect.exe 说它的名字是“Edit”。

我正在使用 Appium.WebDriver 4.1.1 nuget 包。

这是我正在尝试做的一个很好的例子,但是代码已经过时了:https://github.com/microsoft/WinAppDriver/blob/master/Samples/C%23/NotepadTest/ScenarioMenuItem.cs

VS2019中的测试代码

using NUnit.Framework;
using OpenQA.Selenium.Appium.Windows;
using System;

namespace Notepad_Tests
{
    public class Tests
    {
        protected static WindowsDriver<WindowsElement> NotepadSession;

        [SetUp]
        public void Setup()
        {
            var appiumOptions = new OpenQA.Selenium.Appium.AppiumOptions();
            appiumOptions.AddAdditionalCapability("platformName", @"Windows");
            appiumOptions.AddAdditionalCapability("deviceName", @"WindowsPC");
            appiumOptions.AddAdditionalCapability("app", @"C:\Windows\notepad.exe");
            appiumOptions.AddAdditionalCapability("app", @"C:\Windows\notepad.exe");
            appiumOptions.AddAdditionalCapability("appArguments", @"MyTestFile.txt");
            appiumOptions.AddAdditionalCapability("appWorkingDir", @"D:\MyTestFolder\");
            NotepadSession = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), appiumOptions);
        }

        [Test]
        public void Test1()
        {
            NotepadSession.FindElementByClassName("Edit").SendKeys("This is some text");
            NotepadSession.FindElementByName("Edit").Click();
        }
        [TearDown]
        public void TestCleanup()
        {
            // NotepadSession.Quit();
        }
    }
}

WinAppDriver.exe 窗口出错

==========================================
POST /session HTTP/1.1
Accept: application/json, image/png
Connection: Keep-Alive
Content-Length: 236
Content-Type: application/json; charset=utf-8
Host: 127.0.0.1:4723
User-Agent: selenium/3.141.0 (.net windows)

{"desiredCapabilities":{"platformName":"Windows","deviceName":"WindowsPC","app":"C:\\Windows\\notepad.exe","appArguments":"MyTestFile.txt","appWorkingDir":"D:\\MyTestFolder\\"},"capabilities":{"firstMatch":[{"platformName":"Windows"}]}}
HTTP/1.1 200 OK
Content-Length: 200
Content-Type: application/json

{"sessionId":"431F0707-71BD-4645-B085-5BD750FC2067","status":0,"value":{"app":"C:\\Windows\\notepad.exe","appArguments":"MyTestFile.txt","appWorkingDir":"D:\\MyTestFolder\\","platformName":"Windows"}}


==========================================
POST /session/431F0707-71BD-4645-B085-5BD750FC2067/element HTTP/1.1
Accept: application/json, image/png
Connection: Keep-Alive
Content-Length: 37
Content-Type: application/json; charset=utf-8
Host: 127.0.0.1:4723
User-Agent: selenium/3.141.0 (.net windows)

{"using":"class name","value":"Edit"}
HTTP/1.1 200 OK
Content-Length: 96
Content-Type: application/json

{"sessionId":"431F0707-71BD-4645-B085-5BD750FC2067","status":0,"value":{"ELEMENT":"42.2099874"}}


==========================================
POST /session/431F0707-71BD-4645-B085-5BD750FC2067/element/42.2099874/value HTTP/1.1
Accept: application/json, image/png
Connection: Keep-Alive
Content-Length: 31
Content-Type: application/json; charset=utf-8
Host: 127.0.0.1:4723
User-Agent: selenium/3.141.0 (.net windows)

{"value":["This is some text"]}
HTTP/1.1 200 OK
Content-Length: 63
Content-Type: application/json

{"sessionId":"431F0707-71BD-4645-B085-5BD750FC2067","status":0}

==========================================
POST /session/431F0707-71BD-4645-B085-5BD750FC2067/element HTTP/1.1
Accept: application/json, image/png
Connection: Keep-Alive
Content-Length: 31
Content-Type: application/json; charset=utf-8
Host: 127.0.0.1:4723
User-Agent: selenium/3.141.0 (.net windows)

{"using":"name","value":"Edit"}

HTTP/1.1 200 OK
Content-Length: 128
Content-Type: application/json

{"sessionId":"431F0707-71BD-4645-B085-5BD750FC2067","status":0,"value":{"ELEMENT":"42.3148312.3.-2147483646.27904.691604525.2"}}


==========================================
POST /session/431F0707-71BD-4645-B085-5BD750FC2067/element/42.3148312.3.-2147483646.27904.691604525.2/click HTTP/1.1
Accept: application/json, image/png
Connection: Keep-Alive
Content-Length: 2
Content-Type: application/json; charset=utf-8
Host: 127.0.0.1:4723
User-Agent: selenium/3.141.0 (.net windows)

{}
HTTP/1.1 400 Bad Request
Content-Length: 175
Content-Type: application/json

{"status":105,"value":{"error":"element not interactable","message":"An element command could not be completed because the element is not pointer- or keyboard interactable."}}

【问题讨论】:

    标签: nunit winappdriver appium-desktop


    【解决方案1】:

    我通过使用 Microsoft.WinAppDriver.Appium.WebDriver Prerlease nugget 包而不是 Appium.WebDriver 4.1.1 nuget 包来使其工作。

    那么,这里的例子完美运行:

    https://github.com/microsoft/WinAppDriver/blob/master/Samples/C%23/NotepadTest/ScenarioMenuItem.cs

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-03
      • 1970-01-01
      • 1970-01-01
      • 2010-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-06
      相关资源
      最近更新 更多