如何使用C#为WinAppDriver创建测试项目

发布于 2025-01-31 19:03:34 字数 83 浏览 4 评论 0原文

我需要了解如何在Visual Studio中设置WinAppdriver Windows App测试项目,并检查中等大小的Windows应用程序的元素。

I need to learn about how to set-up a winappdriver windows app test project in visual studio and inspecting the elements for a medium size windows application.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

云胡 2025-02-07 19:03:34
  • 导航到WinAppdriver GitHub网页并下载最新
    版本。我在安装后下载了1.2版本
  • ,您将在C:\ Program Files上找到潜水员
    (x86)\ Windows应用程序驱动程序位置。
  • 首先,我们需要在Windows 10上启用开发人员模式,开发人员
    未启用模式。通过设置启用它并重新启动Windows
    应用程序驱动程序
  • 如果您安装了Microsoft Visual Studio,您很可能会
    元素检查器,则已经在计算机上安装了元素检查器
  • 如果您没有安装 ,请导航到Windows 10 SDK
    网站,下载并安装它
    工作正常

**。

  1. 创建一个新的Nunit测试项目
    2-从Nuget下载Appium依赖性
    3-更新现有的UnitTest1.cs类,如下:**

    使用nunit.framework;
    使用OpenQA.Selenium.Appium;
    使用OpenQA.Selenium.Appium.Windows;
    使用系统


 [SetUp]
            public void Setup()
            {
                AppiumOptions Options = new AppiumOptions();
                Options.AddAdditionalCapability("app", "C:\\Windows\\System32\\notepad.exe");

                Options.AddAdditionalCapability("deviceName", "WindowsPC");

                DesktopSession = new WindowsDriver<WindowsElement>(new Uri(DriverUrl), Options);

                Assert.IsNotNull(DesktopSession);
            }

  [TearDown]
            public void Close()
            {
                DesktopSession.CloseApp();
            }
        }

4 =运行测试
注意:如果缺少某些引用或软件包,请右键单击它,并将其包含在解决方案中。

5-创建Windows元素并执行操作
打开测试的应用程序(AUT),在我们的情况下是Notepad.exe,并检查exe工具以获取定位器。

单击记事​​本文本区域,然后在nevess.exe工具的右侧找到AutomationId属性。

WindowsElement Notepadtextarea = desktopsession.findelementByAccostibilityId(“ 15”);
notepadtextarea.sendkeys(“ Hello World”);

尝试!尝试! ,运行测试!运行测试!运行测试!

  • Navigate to the WinAppDriver GitHub web page and download the latest
    version. I downloaded the 1.2 version
  • After installation, you will find the diver at C:\Program Files
    (x86)\Windows Application Driver location.
  • First, we need to enable Developer Mode on our Windows 10, Developer
    mode is not enabled. Enable it through Settings and restart Windows
    Application Driver
  • If you have Microsoft Visual Studio installed, you will most likely
    have Element Inspector already installed on your machine
  • In case you do not have it installed, navigate to the Windows 10 SDK
    site, download and install it.Run the inspect.exe and make sure it is
    working fine

**.

  1. Create a new NUnit test project
    2- download appium dependency from NuGet
    3- Update an existing UnitTest1.cs class as follows:**

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


 [SetUp]
            public void Setup()
            {
                AppiumOptions Options = new AppiumOptions();
                Options.AddAdditionalCapability("app", "C:\\Windows\\System32\\notepad.exe");

                Options.AddAdditionalCapability("deviceName", "WindowsPC");

                DesktopSession = new WindowsDriver<WindowsElement>(new Uri(DriverUrl), Options);

                Assert.IsNotNull(DesktopSession);
            }

  [TearDown]
            public void Close()
            {
                DesktopSession.CloseApp();
            }
        }

4= Run the test
Note: If some references or packages are missing, right-click on it and include it in the solution.

5- Create Windows Elements and perform actions
Open up application under test (AUT), in our case it is Notepad.exe, and Inspect.exe tool to fetch locators.

Click on the Notepad text area and find the AutomationId attribute on the right-hand side of the Inspect.exe tool.

WindowsElement NotepadTextArea = DesktopSession.FindElementByAccessibilityId(“15”);
NotepadTextArea.SendKeys(“Hello World”);

Try! try! ,Run the test! Run the test! Run the test!

你不是我要的菜∠ 2025-02-07 19:03:34

@pawansinghncr的答案是正确的,但我还建议尝试使用UI录音机(检查部分),它在Winappdriver的GitHub的发行页中。

@pawansinghncr's answer is correct, but I would also suggest trying out the UI Recorder (for the inspecting part), it's in the Releases page of the WinAppDriver's Github.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文