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

Testing Native App using Node.js #626

Open
SGarno opened this issue Mar 11, 2019 · 11 comments
Open

Testing Native App using Node.js #626

SGarno opened this issue Mar 11, 2019 · 11 comments

Comments

@SGarno
Copy link

SGarno commented Mar 11, 2019

I am trying to automate a native windows application using Node.js. I keep getting that Locator Strategy is not supported for this session. Does that mean the 'appium-windows-driver' node module is not able to work with WAD 1.1? Or is there something wrong with my code.

It seems to start notepad ok, but nothing seems to work and there really aren't any docs regarding using WAD with Node.js. The node module I am using doesn't seem conform to the API docs for Java or C# (i.e. there is no function FindElementByName, etc) either. The only function I could find was findElement.

However, nothing seems to work when I try to use it. I have tried passing in 'id', 'name', etc and tried XPath. I assume I am supposed to be using XPath, but again, I can't find anything out there that helps.

Has anyone been able to make this work from Node?

Here is the code I have currently:

let WindowsDriver = require('appium-windows-driver').WindowsDriver;

let defaultCaps = {
  platformName: 'Windows',
  deviceName: 'WindowsPC',
  app: 'C:\\Windows\\System32\\notepad.exe'
};

async function main() {
  let driver = new WindowsDriver();
  await driver.createSession(defaultCaps);
  let element = await driver.findElement('//*[@ClassName="Edit"]');
//  element.SendKeys("This is some text");
}

main();

Here is the error message:

info WinAppDriver [STDOUT] {"sessionId":"D00A8AF7-F65B-4301-A140-65D1FCA6BAA7","status":0,"value":{"app":"C:\\Windows\\System32\\notepad.exe","platformName":"Windows"}}
dbug WD Proxy Got response with status 200: {"sessionId":"D00A8AF7-F65B-4301-A140-65D1FCA6BAA7","status":0,"value":{"app":"C:\\Windows\\System32\\notepad.exe","platformName":"Windows"}}
dbug BaseDriver Valid locator strategies for this request:
(node:22308) UnhandledPromiseRejectionWarning: InvalidSelectorError: Locator Strategy '//*[@ClassName="Edit"]' is not supported for this session
    at WindowsDriver.validateLocatorStrategy (D:\QA\node_modules\appium-base-driver\lib\basedriver\driver.js:344:13)
    at WindowsDriver.validateLocatorStrategy [as findElOrElsWithProcessing] (D:\QA\node_modules\appium-base-driver\lib\basedriver\commands\find.js:28:8)
    at WindowsDriver.findElOrElsWithProcessing [as findElement] (D:\QA\node_modules\appium-base-driver\lib\basedriver\commands\find.js:50:21)
    at main (D:\QA\startup.js:12:30)
(node:22308) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:22308) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate
the Node.js process with a non-zero exit code.
@naeemakram
Copy link

Have you tried copying the output of Notepad sample as shown on the WAD console while executing a scenario?

@SGarno
Copy link
Author

SGarno commented Mar 12, 2019

I am not sure I follow what you mean by copying the output? The output from the WAD console is what I have provided above. Am I missing something?

@naeemakram
Copy link

Aside from my last comment, I see the following in default capabilities. and deviceName is not in there. Maybe you could remove it. Just as an experiment.

image

@SGarno
Copy link
Author

SGarno commented Mar 12, 2019

I think that is required...

Yep...get this error message:

(node:2116) UnhandledPromiseRejectionWarning: SessionNotCreatedError: A new session could not be created. Details: The desiredCapabilities object was not valid for the following reason(s): 'deviceName' can't be blank

@naeemakram
Copy link

At my home PC I'm doing same in C# and specifying only two capabilities,

        appCapabilities.SetCapability(
            "app", @"C:\Windows\System32\notepad.exe");
        appCapabilities.SetCapability(
            "deviceName", "WindowsPC");

This seems to work.

image

@naeemakram
Copy link

I tried to send keys to the notedpad and it worked.
Some values are showing in the console output of the WinAppDriver, maybe they could help you.
```
calcSession.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(1.5));

        var editBox = calcSession.FindElementByClassName("Edit");
        if(editBox == null)
        {
            Console.WriteLine("Edit not found.");
            return;
        }

        editBox.SendKeys("Hello World!");


![image](https://user-images.githubusercontent.com/6885369/54230102-8a6dbf00-4527-11e9-84b5-0652df102185.png)

@naeemakram
Copy link

image

@SGarno
Copy link
Author

SGarno commented Mar 12, 2019

You are using C#, which seems to have the methods such as FindElementByClassName, whereas the JavaScript library doesn't have that. This is where my problem seems to be.

@naeemakram
Copy link

naeemakram commented Mar 12, 2019 via email

@SGarno
Copy link
Author

SGarno commented Mar 12, 2019

Yeah, I was trying to use the library rather than create my own API. Despite the code being updated in February, it seems that Appium is not keeping up with the changes to WAD. https://github.com/appium/appium-windows-driver

@yodurr
Copy link
Contributor

yodurr commented Mar 18, 2019

Appium installs a specific version of WinAppDriver, and currently they install v1.1
https://github.com/appium/appium-windows-driver/blob/master/lib/installer.js

We haven't submitted a PR yet to use 1.1.1 but can do so after we get more feedback on 1.1.1.

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