简体   繁体   English

URL '/session' 未映射到有效资源 | 如何使用 winAppDriver / windows 应用程序驱动程序使用 java 运行桌面应用程序测试?

[英]The URL '/session' did not map to a valid resource | How to run desktop application test using winAppDriver / windows application driver using java?

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:我正在尝试使用Windows 应用程序驱动程序 (winAppDriver)appiumjavawindows10上运行 windows 计算器应用程序的自动化测试,如下例所示: https : //github.com/Microsoft/WinAppDriver/tree/master/Samples/Java/CalculatorTest ,但是当我在启动后运行测试时,appium 出现以下提到的错误:

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) Windows 10(已启用开发者模式)
  • appium v1.6.5 appium v​​1.6.5
  • java v1.8 java v1.8
  • winappdriver v0.9-beta winappdriver v0.9-beta
  • IDE - Eclipse IDE - 日食

I will be glad if anyone can help me to fix this issue.如果有人能帮我解决这个问题,我会很高兴。

Thanks in advance.提前致谢。

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 .注意:您应该启动appium serverwinappdriver.exe Don't try to run both appium and winappdriver at once by your self.不要试图自己同时运行 appium 和 winappdriver。

  1. If you are starting appium server , you should give the URI as well as below following by the IP and port;如果你正在启动 appium server ,你应该给出 URI 以及下面的 IP 和端口;

    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;如果你直接运行winappdriver.exe,你应该只提供winappdriver的IP和端口,如下所示;

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

Thanks @Vijendran Selvarajah at first.首先感谢@Vijendran Selvarajah。

for this example: http://appium.io/docs/en/about-appium/getting-started/ need add this line path: "/wd/hub"对于这个例子: http://appium.io/docs/en/about-appium/getting-started/需要添加这一行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.我将分享一个完整的文档和 zip 中关于如何使用 Appium 与所有 deps 测试 Android 应用程序的功能。

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根据我的测试,当您提供必须使用Microsoft.WindowsCalculator_8wekyb3d8bbwe!App的系统路径时,Windows 中的计算器应用程序不会打开

and you don't need to open appium sever has appium has the older version of winappdriver(0.7)并且你不需要打开 appium 服务器 appium 有旧版本的 winappdriver(0.7)

and just saying the winappdriver server should be running in the background只是说 winappdriver 服务器应该在后台运行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在java中切换应用程序winappdriver - how to switch application winappdriver in java 如何在正在运行的桌面应用程序中使用ANT运行Junit测试用例? - How to run Junit test cases using ANT in a running desktop application? Netbeans Java桌面应用程序:资源映射国际化 - Netbeans java desktop application: Resource Map internationalization 如何像其他Windows应用程序一样运行Java桌面应用程序? - How to run java desktop application as other windows application? 如何使用Java创建桌面应用程序并通过浏览器运行? - How to Create Desktop Application Using Java and run through Browser? 如何在不为winappdriver创建新会话的情况下为每个测试用例启动测试应用程序 - How to launch application under test for every test case without creating the new session for winappdriver 如何使用 WinAppDriver Java 在窗口之间切换焦点 - How to switch focus between windows using WinAppDriver Java 如何使用WinRun4J将Java应用程序作为Windows服务运行 - How to run a Java application as Windows service using WinRun4J 如何使用 exec() 方法在 java 代码中运行 windows 控制台应用程序? - How to run windows console application in java code using exec() method? 使用JAVA的Windows桌面应用程序的响应UI设计 - Responsive UI design for windows desktop application using JAVA
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM