简体   繁体   English

遇到错误:java.lang.NoClassDefFoundError:com / google / common / collect / ImmutableList $ Builder

[英]Encountering error: java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableList$Builder

I'm new to Selenium WebDriver using EclipseIDE with TestNG. 我是使用带有TestNG的EclipseIDE的Selenium WebDriver的新手。 I'm currently running this sample code in Eclipse via TestNG: 我目前正在通过TestNG在Eclipse中运行此示例代码:

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import java.util.List;

public class CheesecakeFactory {

    FirefoxDriver driver;

    @BeforeTest
    public void startDriver() {
        driver = new FirefoxDriver();
    }

    @AfterTest
    public void stopDriver() {
        driver.close();
    }

    @Test
    public void listCheesecakes() {
        driver.get("http://www.thecheesecakefactory.com/");
        driver.findElement(By.linkText("Menu")).click();
        driver.findElement(By.linkText("Cheesecake")).click();
        List<WebElement> cheesecakes = driver.findElements(By.xpath("id('leftNav_levelTwo')//li"));

        System.out.println(cheesecakes.size() + " cheesecakes:");
        for (int i=0; i<cheesecakes.size(); i++) {
            System.out.println(i+1 + ". " + cheesecakes.get(i).getText());
        }
    }

}

But Eclipse returns this: 但Eclipse会返回:

[TestNG] Running:
  C:\Users\ryan\AppData\Local\Temp\testng-eclipse--616826937\testng-customsuite.xml

FAILED CONFIGURATION: @BeforeTest startDriver
java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableList$Builder
    at org.openqa.selenium.os.WindowsUtils.getPathsInProgramFiles(WindowsUtils.java:275)
    at org.openqa.selenium.firefox.internal.Executable.locateFirefoxBinaryFromPlatform(Executable.java:148)
    at org.openqa.selenium.firefox.internal.Executable.<clinit>(Executable.java:25)
    at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:60)
    at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:56)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:78)
    at CheesecakeFactory.startDriver(CheesecakeFactory.java:16)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
    at org.testng.TestRunner.beforeRun(TestRunner.java:641)
    at org.testng.TestRunner.run(TestRunner.java:609)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1197)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1122)
    at org.testng.TestNG.run(TestNG.java:1030)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)

I don't understand why I'm getting this error. 我不明白为什么我会收到这个错误。 I've done the following: 我做了以下事情:

  1. Added the guava-12.0.jar file (along with the other jar files in the Selenium-2.25.0 webdriver) as an external jar file in Eclipse. 在Eclipse中添加了guava-12.0.jar文件(以及Selenium-2.25.0 webdriver中的其他jar文件)作为外部jar文件。 (This jar file contains the ImmutableList$Builder class) (这个jar文件包含ImmutableList $ Builder类)

  2. Added the path of this jar file in the CLASSPATH (Environment Variables>System Variables) 在CLASSPATH中添加了此jar文件的路径(环境变量>系统变量)

Am I missing something? 我错过了什么吗? Any help is greatly appreciated. 任何帮助是极大的赞赏。

I guess you are using selenium-java-2.25.0.jar. 我猜你使用的是selenium-java-2.25.0.jar。 You should rather use selenium-server-standalone-2.25.0.jar, it will take care of all the dependencies (ie required jar files). 您应该使用selenium-server-standalone-2.25.0.jar,它将处理所有依赖项(即所需的jar文件)。

Also you dont need to explicitly define the environment variables if the jar files are added in the Eclipse, unless you are running the test outside from eclipse. 如果在Eclipse中添加jar文件,你也不需要显式定义环境变量,除非你在eclipse之外运行测试。

Hope this helps... :) 希望这可以帮助... :)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap 在 Java 中通过 Selenium 使用 GeckoDriver Firefox 时出错 - java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap error using GeckoDriver Firefox through Selenium in Java 线程“main”中的异常 java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap error using Selenium Java - Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap error using Selenium Java "java.lang.NoClassDefFoundError: com\/google\/common\/collect\/ImmutableMap 在 Java Selenium 中使用带有 Maven 依赖关系的 WebDriver" - java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap while using WebDriver with Maven Dependencies in Java Selenium java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap 执行测试文件时 - java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap when executing the test file TestNG java.lang.NoClassDefFoundError:com / google / common / primitives / Ints - TestNG java.lang.NoClassDefFoundError: com/google/common/primitives/Ints java.lang.NoSuchMethodError: 'java.util.stream.Collector com.google.common.collect.ImmutableList.toImmutableList()' using Selenium Java - java.lang.NoSuchMethodError: 'java.util.stream.Collector com.google.common.collect.ImmutableList.toImmutableList()' using Selenium Java java.lang.NoSuchMethodError: 'java.util.stream.Collector com.google.common.collect.ImmutableList.toImmutableList()' 使用 ChromeDriver 和 Selenium - java.lang.NoSuchMethodError: 'java.util.stream.Collector com.google.common.collect.ImmutableList.toImmutableList()' using ChromeDriver and Selenium 配置失败:@BeforeMethod 设置 java.lang.NoClassDefFoundError:com/google/common/base/Function - FAILED CONFIGURATION: @BeforeMethod setUp java.lang.NoClassDefFoundError: com/google/common/base/Function 获取java.lang.NoClassDefFoundError:com / google / gson / Gson - Getting java.lang.NoClassDefFoundError: com/google/gson/Gson 已解决:RSelenium 错误 - com.google.common.collect.Maps$TransformedEntriesMap 与 java.lang.CharSequence 不兼容 - RESOLVED: RSelenium error - com.google.common.collect.Maps$TransformedEntriesMap incompatible with java.lang.CharSequence
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM