11

I'm trying to run automate test for windows calculator app on windows10 using Windows application driver (winAppDriver), appium and java as below example: https://github.com/Microsoft/WinAppDriver/tree/master/Samples/Java/CalculatorTest, but when I run the test after started the appium getting below mentioned error:

org.openqa.selenium.UnsupportedCommandException: The URL '/session' did not map to a valid resource
Command duration or timeout: 204 milliseconds
Build info: version: '2.53.0', revision: '35ae25b1534ae328c771e0856c93e187490ca824', time: '2016-03-15 10:43:46'
System info: host: 'LKXXXX', ip: '10.88.68.53', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_131'
Driver info: io.appium.java_client.ios.IOSDriver

My code is as below:

import org.junit.*;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import java.util.concurrent.TimeUnit;
import java.net.URL;
import io.appium.java_client.ios.IOSDriver;

public class CalculatorTest {

    private static IOSDriver CalculatorSession = null;
    private static WebElement CalculatorResult = null;

    @BeforeClass
    public static void setup() {
        try {
            DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.setCapability("app", "C:\\Windows\\System32\\calc.exe");
            CalculatorSession = new IOSDriver(new URL("http://127.0.0.1:4723"), capabilities);
            CalculatorSession.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);

            CalculatorSession.findElementByName("Clear").click();
            CalculatorSession.findElementByName("Seven").click();
            CalculatorResult = CalculatorSession.findElementByName("Display is  7 ");
            Assert.assertNotNull(CalculatorResult);

        }catch(Exception e){
            e.printStackTrace();
        } finally {
        }
    }
}

My Dev Environment

  • Windows 10 (Developer mode enabled)
  • appium v1.6.5
  • java v1.8
  • winappdriver v0.9-beta
  • IDE - Eclipse

I will be glad if anyone can help me to fix this issue.

Thanks in advance.

Vijendran Selvarajah
  • 1,330
  • 1
  • 11
  • 31

4 Answers4

25

After long research, I have found the answer for the above question. We can solve this using two methods.

NOTE: You should start either appium server or winappdriver.exe. Don't try to run both appium and winappdriver at once by your self.

  1. If you are starting appium server, you should give the URI as well as below following by the IP and port;

    CalculatorSession = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

  2. If you are running the winappdriver.exe directly, you should give only the IP and the port of winappdriver as below;

    CalculatorSession = new IOSDriver(new URL("http://127.0.0.1:4723"), capabilities);

Vijendran Selvarajah
  • 1,330
  • 1
  • 11
  • 31
  • Let me add the info here, as I stumbled upon it: To use WinAppDriver you need to run it as Admin and to activate Developer Mode in Windows Settings. – emfi Oct 15 '20 at 10:54
6

Thanks @Vijendran Selvarajah at first.

for this example:http://appium.io/docs/en/about-appium/getting-started/ need add this line path: "/wd/hub"

// javascript

const wdio = require("webdriverio");
const assert = require("assert");

const opts = {
  port: 4723,
  path: "/wd/hub", // fix: The URL '/session' did not map to a valid resource
  capabilities: {
    platformName: "Android",
    platformVersion: "8",
    deviceName: "Android Emulator",
    app: "/path/to/the/downloaded/ApiDemos.apk",
    appPackage: "io.appium.android.apis",
    appActivity: ".view.TextFields",
    automationName: "UiAutomator2"
  }
};

async function main () {
  const client = await wdio.remote(opts);

  const field = await client.$("android.widget.EditText");
  await field.setValue("Hello World!");
  const value = await field.getText();
  assert.equal(value,"Hello World!");

  await client.deleteSession();
}

main();

I will share a completed doc and zip in the feature about how to use Appium to test Android App with all deps.

kangear
  • 2,493
  • 2
  • 31
  • 44
2

to my testing, the calculator app in windows doesn't open when you giving the system path you have to use Microsoft.WindowsCalculator_8wekyb3d8bbwe!App

and you don't need to open appium sever has appium has the older version of winappdriver(0.7)

and just saying the winappdriver server should be running in the background

teja
  • 127
  • 2
  • 11
0

for appium 2.0 it can be fixed by removing "/" after port. eg : appium_url = "http://0.0.0.0:4723"

Sudip Neupane
  • 33
  • 1
  • 9