0

I am not able to resolve RemoteWebDriver in eclipse due issues in maven dependency. I need RemoteWebDriver to get the browser version (for reporting purpose). I have mentioned the following maven dependencies yet I am not able to resolve RemoteWebDriver. As per the earlier post The import org.openqa.selenium.remote.CapabilityType cannot be resolved I have to manually download selenium-standalone-server. I am not understanding as to why maven dependency is not sufficient? Is there any other maven dependency that can be added to resolve RemoteWebDriver

<dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.141.59</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-remote-driver</artifactId>
        <version>3.141.59</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-server</artifactId>
        <version>3.141.59</version>
    </dependency>

*************************
//Below is what I am trying to code
Capabilities cap = ((RemoteWebDriver) driver).getCapabilities();
String browserName = cap.getBrowserName().toLowerCase();
A-K
  • 161
  • 3
  • 13
  • I'm not really familiar with selenium but if your maven dependency is unsufficient as you mention you could try the following: Go to the site https://github.com/SeleniumHQ/selenium/wiki/RemoteWebDriver and follow the instructions. after you downloaded the zip and unpacked it, you'll see which JAR files are necessary and you can search in the mvnrepository.com if you'll find the needed JAR's there and then you know which dependencies are missing. Otherwise push the manually downloaded JAR's in your own nexus if you have one. – the hand of NOD May 13 '19 at 11:32
  • Manually it is possible. I was thinking of the bigger picture - running program is via jenkins, using virtual machine. PS: I am relatively new to Java – A-K May 13 '19 at 13:04

1 Answers1

1
  1. It is quite enough to have only selenium-java, it will resolve selenium-remote-driver via Maven transitive dependency mechanism

    enter image description here

  2. Given you mention that you have to manually download Selenium Standalone Server you don't need this selenium-server dependency as well

So it should be as simple as:

  • pom.xml:

     <?xml version="1.0" encoding="UTF-8"?>
     <project xmlns="http://maven.apache.org/POM/4.0.0"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
         <modelVersion>4.0.0</modelVersion>
    
         <groupId>com.example</groupId>
         <artifactId>selenium-java</artifactId>
         <version>1.0-SNAPSHOT</version>
    
         <dependencies>
             <dependency>
                 <groupId>org.seleniumhq.selenium</groupId>
                 <artifactId>selenium-java</artifactId>
                 <version>3.141.59</version>
             </dependency>
         </dependencies>
    
     </project>
    
  • Test class:

     import org.openqa.selenium.Capabilities;
     import org.openqa.selenium.remote.DesiredCapabilities;
     import org.openqa.selenium.remote.RemoteWebDriver;
    
     import java.net.URL;
    
     public class SeleniumTest {
    
         public static void main(String[] args) throws Exception {
             System.setProperty("webdriver.chrome.driver", "c:/apps/webdriver/chromedriver.exe");
             DesiredCapabilities capabilities = DesiredCapabilities.chrome();
             RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
             Capabilities cap = driver.getCapabilities();
             String browserName = cap.getBrowserName().toLowerCase();
             System.out.println(browserName);
             driver.quit();
         }
     }
    
  • Demo:

    enter image description here

More information:

samabcde
  • 6,988
  • 2
  • 25
  • 41
Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • Thanks for the info. I reset the dependencies as per your post and performed mvn clean install. – A-K May 13 '19 at 13:42