【问题标题】:How to launch click-once application in Win App driver?如何在 Win App 驱动程序中启动单击一次应用程序?
【发布时间】:2021-01-22 13:08:56
【问题描述】:

我正在使用 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 定位打开的应用程序窗口。提前致谢。

【问题讨论】:

    标签: winappdriver


    【解决方案1】:

    如here所说,需要检查驱动是否为空。

    //******************************************************************************
    //
    // 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;
                }
            }
        }
    }
    

    【讨论】:

    • 感谢您的回复@Akif .....在我的情况下,我收到错误:driver = new WindowsDriver (new Uri("127.0.0.1:4723"), opt, TimeSpan.FromMinutes (1)); 驱动程序为空。
    • 收到异常后,应用程序正在打开。注意到驱动程序为空。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-28
    • 1970-01-01
    • 2014-05-24
    • 2011-07-14
    • 2018-01-22
    • 1970-01-01
    相关资源
    最近更新 更多