簡體   English   中英

Selenium java 錯誤 com/google/common/collect/ImmutableMap 在 ubuntu

[英]Selenium java error com/google/common/collect/ImmutableMap in ubuntu

嘿,我正在我的 64 位 ubuntu 16.04 系統中用 java 編寫一個基本的 selenium 程序。

package test;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class App {
    public static void main(String[] args) {
        System.setProperty("webdriver.chrome.driver", "/home/bopsi/webdriver/chromedriver/2.40/chromedriver");
        WebDriver driver = new ChromeDriver();

        String baseUrl = "http://demo.guru99.com/test/newtours/";
        String expectedTitle = "Welcome: Mercury Tours";
        String actualTitle = "";

        driver.get(baseUrl);

        actualTitle = driver.getTitle();

        if (actualTitle.contentEquals(expectedTitle)) {
            System.out.println("Test Passed!");
        } else {
            System.out.println("Test Failed");
        }

        driver.close();
    }
}

這是 maven 項目,這里是依賴項 -

<dependencies>
        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-server -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-server</artifactId>
            <version>3.13.0</version>
        </dependency>
</dependencies>

它給了我以下錯誤-

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap
    at org.openqa.selenium.remote.service.DriverService$Builder.<init>(DriverService.java:250)
    at org.openqa.selenium.chrome.ChromeDriverService$Builder.<init>(ChromeDriverService.java:98)
    at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:91)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
    at org.qlikhain.auto_liker.App.main(App.java:11)
Caused by: java.lang.ClassNotFoundException: com.google.common.collect.ImmutableMap
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    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)
    ... 5 more

我仔細檢查了驅動程序路徑並確保它存在於文件夾中。 完全相同的代碼在我的 Windows 10 系統中工作。 在這兩個系統中,我都使用 chrome v68、chromedriver 2.40 和 jdk 1.8。 知道為什么它不能在 ubuntu 中工作嗎? 我錯過了任何重要的步驟嗎?

com/google/common/collect/ImmutableMap文件很可能已損壞。

我已經提供了解決該問題的方法:

java.lang.NoClassDefFoundError:com / google / common / collect / ImmutableMap,同時在Java Selenium中將WebDriver與Maven依賴關系一起使用

我能夠通過單獨包含com.google.guava 的 31.1-jre 版本來解決這個問題,但它不想要

<type>bundle</type>

代碼段中的行。 在 MacOS Monterey 12.4 上,M1 Apple Silicon 芯片

整個 pom 依賴部分:

  <dependencies>
    <!-- https://search.maven.org/artifact/io.cucumber/cucumber-java/7.4.1/jar -->
    <dependency>
      <groupId>io.cucumber</groupId>
      <artifactId>cucumber-java</artifactId>
      <version>7.4.1</version>
    </dependency>
    
    <!-- https://search.maven.org/artifact/io.cucumber/cucumber-junit/7.4.1/jar -->
    <dependency>
      <groupId>io.cucumber</groupId>
      <artifactId>cucumber-junit</artifactId>
      <version>7.4.1</version>
    </dependency>
    
    <!-- https://search.maven.org/artifact/org.robolectric/junit/4.8.1/jar -->
    <dependency>
      <groupId>org.robolectric</groupId>
      <artifactId>junit</artifactId>
      <version>4.8.1</version>
    </dependency>
    
    <!-- https://search.maven.org/artifact/org.seleniumhq.selenium/selenium-java/4.3.0/jar -->
    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-java</artifactId>
      <version>4.3.0</version>
    </dependency>
    
    <!-- https://search.maven.org/artifact/com.google.guava/guava/31.1-jre/bundle -->
    <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <version>31.1-jre</version>
    </dependency>
        
  </dependencies>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

相關問題 線程“main”中的異常 java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap error using Selenium Java java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap 在 Java 中通過 Selenium 使用 GeckoDriver Firefox 時出錯 "java.lang.NoClassDefFoundError: com\/google\/common\/collect\/ImmutableMap 在 Java Selenium 中使用帶有 Maven 依賴關系的 WebDriver" java.lang.NoSuchMethodError: 'com.google.common.collect.ImmutableMap 嘗試使用 Chromedriver 和 Maven 執行測試時出錯 Dropwizard-線程“ main”中的異常java.lang.NoClassDefFoundError:com / google / common / collect / ImmutableMap $ Builder java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap 執行測試文件時 不兼容的類型:com.google.common.collect.ForwardingImmutableMap 無法轉換為 com.google.common.collect.ImmutableMap 生成源 無法解決以下問題:Lcom / google / common / collect / ImmutableMap; 在com.my.app.di.DaggerMyApplicationComponent.getMapOfClassOfAndProviderOfFactoryOf( java.lang.NoSuchMethodError:帶有Selenium和Java的com.google.common.collect.ImmutableSet.of([Ljava / lang / Object;) .WeldService:com.google.common.collect.ComputationException:java.lang.ArrayInd exOutOfBoundsException:3“}}}}當將硒與jboss一起使用時
 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM