Unable to create Appuim driver session despite having latest chrome driver and slf4j dependencies

huangapple go评论55阅读模式
英文:

Unable to create Appuim driver session despite having latest chrome driver and slf4j dependencies

问题

以下是您提供的内容的中文翻译:

我已经安装了最新的Chrome驱动程序,这解决了其他遇到相同错误的人的问题。我是初次使用Appium。

这是错误信息:

Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: 无法启动新会话。响应代码 404。消息:无法找到请求的资源,或者收到使用不受支持的HTTP方法发送的请求
主机信息:主机:'MallSoft.local',IP:'2601:1c2:0:3680:0:0:0:8406%en0'
构建信息:版本:'4.8.1',修订版本:'8ebccac989'
系统信息:操作系统名称:'Mac OS X',操作系统架构:'x86_64',操作系统版本:'10.16',Java版本:'1.8.0_301'
驱动信息:io.appium.java_client.android.AndroidDriver
命令:[null, newSession {capabilities=[{appium:app=/Users/fieldemployee/IdeaProjects/FirstAppiumProject/src/main/resources/ApiDemos-debug.apk, appium:automationName=uiAutomator2, appium:deviceName=nexus_5, platformName=ANDROID, appium:udid=emulator-5554}], desiredCapabilities=Capabilities {app: /Users/fieldemployee/IdeaPr..., automationName: uiAutomator2, deviceName: nexus_5, platformName: ANDROID, udid: emulator-5554}}]
Capabilities {app: /Users/fieldemployee/IdeaPr..., automationName: uiAutomator2, deviceName: nexus_5, platformName: ANDROID, udid: emulator-5554}
	at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:148)
	...

这是我在IntelliJ中的代码:

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;

public class CreateDriverSession {
    public static void main(String[] args) throws MalformedURLException {
        DesiredCapabilities caps = new DesiredCapabilities();
        caps.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
        caps.setCapability(MobileCapabilityType.DEVICE_NAME, "nexus_5");
        caps.setCapability(MobileCapabilityType.AUTOMATION_NAME, "uiAutomator2");
        caps.setCapability(MobileCapabilityType.UDID, "emulator-5554");
        //for windows users
        String appUrl = "/Users/fieldemployee/IdeaProjects/FirstAppiumProject/src/main/resources/ApiDemos-debug.apk";
        caps.setCapability(MobileCapabilityType.APP, appUrl);

        URL url = new URL("http://0.0.0.0:4723/");

        AppiumDriver driver = new AndroidDriver(url, caps);
    }
}

这是Appium GUI中的结果:

[HTTP] 找不到/wd/hud/session的路由
[HTTP] <-- POST /wd/hud/session 404 8毫秒 - 211
[HTTP]
[HTTP] 请求幂等性密钥:e718b60f-1d53-4e4b-8ebb-ddaf41d23b43
[HTTP] --> POST /session
[HTTP] {"capabilities":{"firstMatch":[{}],"alwaysMatch":{"appium:app":"/Users/fieldemployee/IdeaProjects/FirstAppiumProject/src/main/resources/ApiDemos-debug.apk","appium:automationName":"uiAutomator2","appium:deviceName":"nexus_5","appium:udid":"emulator-5554","platformName":"android"}}}

如您所述,我已经安装了最新的Chrome驱动程序和浏览器(截止到帖子发布日期的最新版本)。我的最初错误与slf4j相关,但添加到POM的依赖项解决了该问题。我尝试过更改URL并删除"/wd/hud/",但没有成功。

英文:

I have the latest chrome driver installed, which fixed the issue for others that have encountered the same error. I am new to using Appium.

here is the error:

Exception in thread &quot;main&quot; org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 404. Message: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource 
Host info: host: &#39;MallSoft.local&#39;, ip: &#39;2601:1c2:0:3680:0:0:0:8406%en0&#39;
Build info: version: &#39;4.8.1&#39;, revision: &#39;8ebccac989&#39;
System info: os.name: &#39;Mac OS X&#39;, os.arch: &#39;x86_64&#39;, os.version: &#39;10.16&#39;, java.version: &#39;1.8.0_301&#39;
Driver info: io.appium.java_client.android.AndroidDriver
Command: [null, newSession {capabilities=[{appium:app=/Users/fieldemployee/IdeaProjects/FirstAppiumProject/src/main/resources/ApiDemos-debug.apk, appium:automationName=uiAutomator2, appium:deviceName=nexus_5, platformName=ANDROID, appium:udid=emulator-5554}], desiredCapabilities=Capabilities {app: /Users/fieldemployee/IdeaPr..., automationName: uiAutomator2, deviceName: nexus_5, platformName: ANDROID, udid: emulator-5554}}]
Capabilities {app: /Users/fieldemployee/IdeaPr..., automationName: uiAutomator2, deviceName: nexus_5, platformName: ANDROID, udid: emulator-5554}
	at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:148)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at io.appium.java_client.remote.AppiumProtocolHandshake.createSession(AppiumProtocolHandshake.java:133)
	at io.appium.java_client.remote.AppiumProtocolHandshake.createSession(AppiumProtocolHandshake.java:102)
	at io.appium.java_client.remote.AppiumCommandExecutor.createSession(AppiumCommandExecutor.java:194)
	at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:262)
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543)
	at io.appium.java_client.AppiumDriver.startSession(AppiumDriver.java:229)
	at org.openqa.selenium.remote.RemoteWebDriver.&lt;init&gt;(RemoteWebDriver.java:157)
	at io.appium.java_client.AppiumDriver.&lt;init&gt;(AppiumDriver.java:80)
	at io.appium.java_client.AppiumDriver.&lt;init&gt;(AppiumDriver.java:92)
	at io.appium.java_client.android.AndroidDriver.&lt;init&gt;(AndroidDriver.java:117)
	at CreateDriverSession.main(CreateDriverSession.java:25)

Process finished with exit code 1

here is my code in IntelliJ:

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;

public class CreateDriverSession {
    public static void main(String[] args) throws MalformedURLException {
        DesiredCapabilities caps = new DesiredCapabilities();
        caps.setCapability(MobileCapabilityType.PLATFORM_NAME, &quot;Android&quot;);
        caps.setCapability(MobileCapabilityType.DEVICE_NAME, &quot;nexus_5&quot;);
        caps.setCapability(MobileCapabilityType.AUTOMATION_NAME, &quot;uiAutomator2&quot;);
        caps.setCapability(MobileCapabilityType.UDID, &quot;emulator-5554&quot;);
        //for windows users
        String appUrl = &quot;/Users/fieldemployee/IdeaProjects/FirstAppiumProject/src/main/resources/ApiDemos-debug.apk&quot;;
                //System.getProperty(&quot;user.dir&quot;) + File.separator + &quot;src&quot; + File.separator + &quot;main&quot;
                //+ File.separator + &quot;resources&quot; + File.separator + &quot;ApiDemos-debug.apk&quot;;
        caps.setCapability(MobileCapabilityType.APP, appUrl);

        URL url = new URL(&quot;http://0.0.0.0:4723/&quot;);

        AppiumDriver driver = new AndroidDriver(url, caps);
    }


}

here is the result in the Appium GUI:

[HTTP] No route found for /wd/hud/session
[HTTP] &lt;-- POST /wd/hud/session 404 8 ms - 211
[HTTP] 
[HTTP] Request idempotency key: e718b60f-1d53-4e4b-8ebb-ddaf41d23b43
[HTTP] --&gt; POST /session
[HTTP] {&quot;capabilities&quot;:{&quot;firstMatch&quot;:[{}],&quot;alwaysMatch&quot;:{&quot;appium:app&quot;:&quot;/Users/fieldemployee/IdeaProjects/FirstAppiumProject/src/main/resources/ApiDemos-debug.apk&quot;,&quot;appium:automationName&quot;:&quot;uiAutomator2&quot;,&quot;appium:deviceName&quot;:&quot;nexus_5&quot;,&quot;appium:udid&quot;:&quot;emulator-5554&quot;,&quot;platformName&quot;:&quot;android&quot;}}}

As stated, I have the latest chrome driver and browser installed (latest as of the date on this post). My initial error was related to slf4j but adding the dependencies to pom resolved it. I have tried changing the url and removing the "/wd/hud/" as well.

答案1

得分: 1

可能需要在末尾添加 /wd/hub

解决方案
改成以下方式:

URL url = new URL("http://localhost:4723/");

或者

URL url = new URL("http:///127.0.0.1:4723/");

参考资料
您可以在以下链接中找到相关的详细讨论:

英文:

Possibly you need to add /wd/hub at the end.


Solution

Instead of:

URL url = new URL(&quot;http://0.0.0.0:4723/&quot;);

you need to use:

URL url = new URL(&quot;http://localhost:4723/&quot;);

or

URL url = new URL(&quot;http:///127.0.0.1:4723/&quot;);

References

You can find a relevant detailed discussion in:

huangapple
  • 本文由 发表于 2023年2月18日 03:07:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/75488367.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定