A-K
A-K

Reputation: 161

Unable to set maven dependencies for RemoteWebDriver

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

Upvotes: 0

Views: 4142

Answers (1)

Dmitri T
Dmitri T

Reputation: 168072

  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:

Upvotes: 1

Related Questions