1

Hey I was writing a basic selenium program in java in my 64 bit ubuntu 16.04 system.

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();
    }
}

It's maven project, here are the dependencies -

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

It's giving me following error -

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

I double checked driver path and mase sure it exists in the folder. The exact same code worked in my windows 10 system. In both sytems I am using chrome v68, chromedriver 2.40 and jdk 1.8 . Any idea why its not working in ubuntu? AmI missing any vital steps?

Bopsi
  • 2,090
  • 5
  • 36
  • 58

2 Answers2

0

It is highly likely that the file com/google/common/collect/ImmutableMap is corrupted.

I have already provided a solution how to solve this problem:

java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap while using WebDriver with Maven Dependencies in Java Selenium

Hendrik
  • 413
  • 7
  • 17
0

I was able to resolve this by separately including the 31.1-jre version of com.google.guava, but it didn't want the

<type>bundle</type>

line in the snippet. On MacOS Monterey 12.4, M1 Apple Silicon chip

Entire pom dependency section:

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