mavenselenium-webdriverselenium-chromedriverappiumappium-android

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


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.


Solution

  • 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: