Issues starting appium automation on mac

I can’t figure out why I can’t get a simulator to open using appium. Here’s my code:

import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import java.io.File;
import java.net.URL;

public class IOSCreateSessionTest extends BaseTest {
    private RemoteWebDriver driver;
    private String appiumUrl = "http://127.0.0.1:4723/wd/hub";

    @BeforeSuite
    public void setUp() throws Exception {
        File appDir = new File("/Users/kalcala/Library/Developer/Xcode/DerivedData/Debug-dzwubmjzkmhinmbiqendgnbenvbq/Build/Products/Debug-iphonesimulator/");
        File app = new File(appDir.getCanonicalPath(), "Debug.app");

        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("deviceName", "iPhone 12");
        capabilities.setCapability("platformVersion", "14.4");
        capabilities.setCapability("app", app.getAbsolutePath());
        capabilities.setCapability("automationName", "XCUITest");
        capabilities.setCapability("platformName", "iOS");
        capabilities.setCapability("noReset", "true");
        driver = new RemoteWebDriver(new URL(appiumUrl), capabilities);
    }

    @AfterSuite
    public void tearDown() {
        if (driver != null) {
            driver.quit();
        }
    }

    @Test
    public void testFindingAnElement() {
        System.out.println("we did it");

    }
}

The code keeps failing when I try to create the driver. Navigating to http://127.0.0.1:4723/wd/hub gets me this error

{"status":9,"value":{"error":"unknown command","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","stacktrace":""}}

Anyone know what’s going on?

hi.

  1. how you start appium server
  2. pls provide a bit more logs

I have tried starting my appium server in terminal using appium. The specific error I get is

java.lang.NoClassDefFoundError: org/openqa/selenium/logging/LoggingHandler

	at IOSCreateSessionTest.setUp(IOSCreateSessionTest.java:28)
	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 org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
	at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:59)
	at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:458)
	at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:222)
	at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:142)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:401)
	at org.testng.SuiteRunner.run(SuiteRunner.java:364)
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
	at org.testng.TestNG.runSuites(TestNG.java:1049)
	at org.testng.TestNG.run(TestNG.java:1017)
	at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:73)
	at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.logging.LoggingHandler
	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 20 more


Test ignored.

===============================================
Default Suite
Total tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 1
===============================================


Process finished with exit code 0 

Going in with the debugger I’m seeing a IllegalAccessException being thrown.
Appium version: v1.20.2
POM dependencies:

   <dependencies>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-remote-driver</artifactId>
            <version>3.141.59</version>
        </dependency>
        <dependency>
            <groupId>io.appium</groupId>
            <artifactId>java-client</artifactId>
            <version>5.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.7</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.testng/testng -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.14.3</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-api</artifactId>
            <version>3.14.0</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.141.59</version>
        </dependency>
    </dependencies>

I hope you installed appium using NPM command. Correct?
But your error is compile project problem. Something wrong with your code.

Also:

driver = new RemoteWebDriver(new URL(appiumUrl), capabilities);

RemoteWebDriver replace with iOSDriver from appium java-client.

Hi yes, I used npm install -g appium to install. I updated the code to look like this but still showing errors.

public class IOSCreateSessionTest extends BaseTest {
    private IOSDriver driver;
    private String appiumUrl = "http://127.0.0.1:4723/wd/hub";

    @BeforeSuite
    public void setUp() throws Exception {
        File appDir = new File("/Users/kalcala/Library/Developer/Xcode/DerivedData/Debug-dzwubmjzkmhinmbiqendgnbenvbq/Build/Products/Debug-iphonesimulator/");
        File app = new File(appDir.getCanonicalPath(), "Debug.app");

        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("deviceName", "iPhone 12");
        capabilities.setCapability("platformVersion", "14.4");
        capabilities.setCapability("app", app.getAbsolutePath());
        capabilities.setCapability("automationName", "XCUITest");
        capabilities.setCapability("platformName", "iOS");
        capabilities.setCapability("noReset", "true");
        driver = new IOSDriver<>(new URL(appiumUrl), capabilities);
    }

    @AfterSuite
    public void tearDown() {
        if (driver != null) {
            driver.quit();
        }
    }

    @Test
    public void testFindingAnElement() {
        System.out.println("we did it");

    }
}
  1. setUp should be in “@beforeMethod” = before each test
  2. tearDown should be in “@afterMethod” = after each test
  3. replace you java-client to new one and remove logs. e.g. i use 7.3.0. latest 7.4.1:
        <dependency>
            <groupId>io.appium</groupId>
            <artifactId>java-client</artifactId>
            <version>7.3.0</version>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-nop</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-jdk14</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
  1. testNG also can move to newer:
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>7.1.0</version>
            <scope>test</scope>
        </dependency>
  1. try remove from pom:
    • selenium-remote-driver
    • org.apache.commons
    • org.seleniumhq.selenium: both selenium-api + selenium-java
  2. ClassNotFoundException means problem in code

You’re a saint. Thanks so much for your help!

@Aleksei where to include this, as I am facing the same issue and I am running robotframework and android studio to perform mobile automation using appium

Where I should include this block of code, considering I am doing this on windows

And where I should find this pom?

@kalcala here to include this, as I am facing the same issue and I am running robotframework and android studio to perform mobile automation using appium

Where I should include this block of code, considering I am doing this on windows

And where I should find this pom?

I dont know your code. Pom file needed when you write project with maven.

1 Like

My appium server is not running at all, it says; while I check it using url; http://127.0.0.1:4723/wd/hub

{“status”:9,“value”:{“error”:“unknown command”,“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”,“stacktrace”:""}}

I am using robot framework for automation of mobile, in which I am just opening the app.

*** Settings ***

Library AppiumLibrary

*** Test Cases ***

Open_Application

   Open Application    http://localhost:4723/wd/hub    platformName=Android    platformVersion=11    deviceName=emulator-5554       appPackage=chat21.android.demo     appActivity=chat21.android.demo.SplashActivity - Chat21    automationName=Uiautomator2

The appium response gives an error of 500, I have just copied endlines of appium as this site is not allowing me to paste whole response considering new user

ppium\node_modules\appium-uiautomator2-driver\lib\driver.js:229:7)
[debug] [W3C] at AppiumDriver.createSession (C:\Users\Gillani Family\AppData\Roaming\npm\node_modules\appium\lib\appium.js:387:35)
[HTTP] <-- POST /wd/hub/session 500 8769 ms - 3841
[HTTP]
[debug] [Instrumentation] .
[debug] [Instrumentation] Time: 2.055
[debug] [Instrumentation]
[debug] [Instrumentation] OK (1 test)
[debug] [Instrumentation] The process has exited with code 0

I got the solution, the appActivity here should not include - Chat21, which normally comes while we extract it from apk.info app

Open Application http://localhost:4723/wd/hub platformName=Android platformVersion=11 deviceName=emulator-5554 appPackage=chat21.android.demo appActivity=chat21.android.demo.SplashActivity - Chat21 automationName=Uiautomator2