Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to connect to running process from Winappdriver JS #1106

Open
venkatrao-rgare opened this issue Mar 18, 2020 · 3 comments
Open

Unable to connect to running process from Winappdriver JS #1106

venkatrao-rgare opened this issue Mar 18, 2020 · 3 comments

Comments

@venkatrao-rgare
Copy link

venkatrao-rgare commented Mar 18, 2020

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.

@jsa34
Copy link

jsa34 commented Mar 18, 2020

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

@venkatrao-rgare
Copy link
Author

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."}}

@rapidroamer
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants