英文:
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 "main" 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: 'MallSoft.local', ip: '2601:1c2:0:3680:0:0:0:8406%en0'
Build info: version: '4.8.1', revision: '8ebccac989'
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.16', java.version: '1.8.0_301'
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.<init>(RemoteWebDriver.java:157)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:80)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:92)
at io.appium.java_client.android.AndroidDriver.<init>(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, "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";
//System.getProperty("user.dir") + File.separator + "src" + File.separator + "main"
//+ File.separator + "resources" + File.separator + "ApiDemos-debug.apk";
caps.setCapability(MobileCapabilityType.APP, appUrl);
URL url = new URL("http://0.0.0.0:4723/");
AppiumDriver driver = new AndroidDriver(url, caps);
}
}
here is the result in the Appium GUI:
[HTTP] No route found for /wd/hud/session
[HTTP] <-- POST /wd/hud/session 404 8 ms - 211
[HTTP]
[HTTP] Request idempotency key: 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"}}}
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("http://0.0.0.0:4723/");
you need to use:
URL url = new URL("http://localhost:4723/");
or
URL url = new URL("http:///127.0.0.1:4723/");
References
You can find a relevant detailed discussion in:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论