简体   繁体   中英

Exception in thread “main” java.lang.NoClassDefFoundError once I run my Appium script

I'm a new Appium user and I'm following with an Appium tutorial and when I try to run my script I'm gitting the following error :

Exception in thread “main” java.lang.NoClassDefFoundError: org/openqa/selenium/remote/AcceptedW3CCapabilityKeys
at io.appium.java_client.remote.NewAppiumSessionPayload.(NewAppiumSessionPayload.java:98)
at io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:175)
at io.appium.java_client.remote.AppiumCommandExecutor.createSession(AppiumCommandExecutor.java:217)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:239)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:219)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:142)
at io.appium.java_client.DefaultGenericMobileDriver.(DefaultGenericMobileDriver.java:38)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:84)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:94)
at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:95)
at base.main(base.java:20)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.remote.AcceptedW3CCapabilityKeys
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
… 15 more

I've tried to remove the selenium jars and relaunch eclipse and the emulator with no benefits.

here's my script:

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.remote.MobileCapabilityType;

public class base {

public static void main(String[] args) throws MalformedURLException {

    File f = new File("src");
    File fs = new File(f,"ApiDemos-debug.apk");
    URL ServerURL = new URL("http://127.0.0.1:4723/wd/hub");

    DesiredCapabilities cap = new DesiredCapabilities();
    cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Demo");
    cap.setCapability(MobileCapabilityType.APP, fs.getAbsolutePath());
    AndroidDriver<AndroidElement> driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"),cap);

} 
}

@Malek, hi. Have You created maven-based project?

Could You pleas ensure that You do have correct and up-to-date dependencies? Obviously You're missing some dependency or maven didnt pull the dependency from the repo. After You've ensured, please note:

if You have selenium and java-client dependencies eg:

<dependency>
  <groupId>io.appium</groupId>
  <artifactId>java-client</artifactId>
  <version>7.0.0</version>
</dependency>

and

<dependency>
  <groupId>org.seleniumhq.selenium</groupId>
  <artifactId>selenium-java</artifactId>
  <version>3.12.0</version>
</dependency>

they might be conflicting each other. Please remove selenium dependency and leave java-client dependency.

After that - please call mvn clean install command . You can learn about maven lifecycle here .

Second option to try: please ensure that You create and initialize capabilities in the correct way. The difference between JSONWP and W3C Spec capabilities You may get here, in this answer .

And last one advice- here, in Comparing and combining web and mobile test automation drivers article You may get an example of working code that You may adjust up to Your needs.

Hope this helps for You. Regards, Eugene

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM