0

Team,

I was trying to build a basic selenium tests using maven. But i am the getting the error "FirefoxDriver cannot be resolved to a type" error. When i tried add the external jars via project build path, i am not seeing this error. Only when i use the maven dependency in POM i am seeing this error. Any help is deeply appreciated.

My Selenium Code:

package mavenramdemo;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;

public class HelloTest {

@Test
public void testOne() {
    // TODO Auto-generated method stub

    System.setProperty("webdriver.gecko.driver","D:\\Firefox 
    Driver\\geckodriver-v0.17.0-win64//geckodriver.exe");
    WebDriver d=new FirefoxDriver();
    d.get("https://www.google.com");
    String actualt=d.getTitle();
    String etitle="Google";
    if(actualt.equals(etitle)) 
    {

        System.out.println("Passed");
    }
    else 
    {

        System.out.println("Failed");
    }

}

}

in the above code i am getting error at WebDriver d=new FirefoxDriver();

My POM file:

<dependencies>
<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-java</artifactId>
<version>3.12.0</version>
</dependency>
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-firefox-driver</artifactId>
    <version>3.12.0</version>
</dependency>  
</dependencies>
</project>

I tried different options like putting only 1 repo for seleium, etc but no luck.

I am struck at this issue for last 2 weeks. I observed that couple of jars are not getting downloaded with selenium-java repo. But,again i am unable to fix this.please help

Krishnan Mahadevan
  • 14,121
  • 6
  • 34
  • 66
Ramdas Metla
  • 133
  • 3
  • 10
  • Possible duplicate of [WebDriver cannot be resolved to a type FirefoxDriver cannot be resolved to a type](https://stackoverflow.com/questions/31739392/webdriver-cannot-be-resolved-to-a-type-firefoxdriver-cannot-be-resolved-to-a-typ) – JeffC Jun 18 '18 at 04:08
  • Give your Driver Path in System Environment Variable D:\Firefox Driver\geckodriver-v0.17.0-win64 and remove system.setproperty line, Your define path seems incorrect slash. Also remove selenium-java dependency and Run Maven Test. Again add selenium-java dependency and Run Maven Test. You might have 2 possibility to check, 1. Driver syntax 2. Selenium Java dependency – Ishita Shah Jun 18 '18 at 04:58
  • Possible duplicate of [Selenium-TestNG-Maven - Getting "java.lang.NoClassDefFoundError: org/openqa/selenium/firefox/FirefoxDriver"](https://stackoverflow.com/questions/50730321/selenium-testng-maven-getting-java-lang-noclassdeffounderror-org-openqa-sele) – undetected Selenium Jun 18 '18 at 08:31
  • Ishita Shah : Tried your options: 1. Corrected my forward slashes.no luck. 2. Removed tge selenium java dependency and ran Maven test in eclipse . below is the response. T E S T S ------------------------------------------------------- Running mavenramdemo.HelloTest FAILURE! testOne(mavenramdemo.HelloTest) Time elapsed: 0.047 sec <<< FAILURE! java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap at org.openqa.selenium.remote.service.DriverService$Builder. – Ramdas Metla Jun 19 '18 at 02:53
  • Ishita Shah: After adding selenium-java dependency and ran maven clean test. below is the issue.T E S T S ------------------------------------------------------- Running mavenramdemo.HelloTest Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@198e2867 Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.89 sec <<< FAILURE! testOne(mavenramdemo.HelloTest) Time elapsed: 0.031 sec <<< FAILURE! java.lang.NoClassDefFoundError: org/openqa/selenium/firefox/FirefoxDriver – Ramdas Metla Jun 19 '18 at 03:00

1 Answers1

0

you missing selenium server dependency in your POM file add this and run your code again

        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-server -->
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-server</artifactId>
        <version>3.11.0</version>
    </dependency>
mbn217
  • 884
  • 7
  • 14