WinAppDriver icon indicating copy to clipboard operation
WinAppDriver copied to clipboard

Unable to connect to running process from Winappdriver JS

Open venkatrao-rgare opened this issue 5 years ago • 3 comments

I am fairly new to JS/Winappdriver.

The application I am trying to test is a "Click Once" application from .Net, so I have to go to a website from IE and click "Install". This will open the application.

Once the application is running, I have no way to connect the application to perform my UI using JavaScript.

Using C#, I was looping through the process to get the process name, get the window handle, convert it to hex, add that as a capability and create the driver. Sample code below,

public Setup_TearDown()
        {
            string TopLevelWindowHandleHex = null;
            IntPtr TopLevelWindowHandle = new IntPtr();
            foreach (Process clsProcess in Process.GetProcesses())
            {
                if (clsProcess.ProcessName.StartsWith($"SomeName-{exec_pob}-{exec_env}"))
                {
                    TopLevelWindowHandle = clsProcess.Handle;
                    TopLevelWindowHandleHex = clsProcess.MainWindowHandle.ToString("x");
                }
            }
            var appOptions = new AppiumOptions();
            appOptions.AddAdditionalCapability("appTopLevelWindow", TopLevelWindowHandleHex);
            appOptions.AddAdditionalCapability("ms:experimental-webdriver", true);
            appOptions.AddAdditionalCapability("ms:waitForAppLaunch", "25");
            AppDriver = new WindowsDriver<WindowsElement>(new Uri(WinAppDriverUrl), appOptions);
            AppDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(60);
        }

How do I do this in Javascript ? I can't seem to find any code examples. Based on an example from this repo, I tried the following in JS to find the process to latch on to but without luck.

import {By2} from "selenium-appium";
// this.appWindow = this.driver.element(By2.nativeAccessibilityId('xxx'));
        // this.appWindow = this.driver.element(By2.nativeXpath("//Window[starts-with(@Name,\"xxxx\")]"));
        // this.appWindow = this.driver.elementByName('WindowsForms10.Window.8.app.0.13965fa_r11_ad1');
        // thisappWindow = this.driver.elementByName('xxxxxxx');

async connectAppDriver(){
        await this.waitForAppWindow();
        var appWindow = await this.appWindow.getAttribute("NativeWindowHandle");
        let hex = (Number(ewarpWindow)).toString(16);
        var currentAppCapabilities =
            {
                "appTopLevelWindow": hex,
                "platformName": "Windows",
                "deviceName": "WindowsPC",
                "newCommandTimeout": "120000"
            }
        let driverBuilder = new DriverBuilder();
        await driverBuilder.stopDriver();
        this.driver = await driverBuilder.createDriver(currentEwarpCapabilities);
        return this.driver;
    }

I keep getting this error

{"status":13,"value":{"error":"unknown error","message":"An unknown error occurred in the remote end while processing the command."}}

I am open to suggestions on how to tackle this issue while using JavaScript.

venkatrao-rgare avatar Mar 18 '20 05:03 venkatrao-rgare

Are you running this through appium? Can you provide the error that appium throws if so?

jsa34 avatar Mar 18 '20 08:03 jsa34

Are you running this through appium? Can you provide the error that appium throws if so?

I am running it through cucumber.js while having the winappdriver open, below is the error I am seeing in WinAppDriver

{"status":13,"value":{"error":"unknown error","message":"An unknown error occurred in the remote end while processing the command."}}

venkatrao-rgare avatar Mar 18 '20 08:03 venkatrao-rgare

I've posted a solution in stackoverflow

element.getDomAttribute('NativeWindowHandle') seems to work.

https://stackoverflow.com/questions/60734348/connecting-to-a-running-process-in-winappdriver-using-javascript/72686928#72686928

rapidroamer avatar Jun 20 '22 12:06 rapidroamer