简体   繁体   中英

getting exception while running selenium test in maven

I am using java,maven,selenium-webdriver.I have added dependencies ' selenium-server 2.32.0','selenium-java 2.32.0 '.But I am getting Exception as follows: Here is the code:-

public class ABC{
   private static WebDriver webDriver ;
    public static void main(String [] args) throws IOException{
        ChromeDriverService service = new ChromeDriverService.Builder()
        .usingDriverExecutable(
                new File("/root/Downloads/chromedriver"))
                .usingAnyFreePort().build();
        service.start();
        webDriver = new RemoteWebDriver(service.getUrl(),
                DesiredCapabilities.chrome());
          //webDriver = new FirefoxDriver(); 
    }
} 

As you see,I also created firefoxdriver instance but getting same exception.

 Exception in thread "main" java.lang.NoSuchMethodError: org.apache.http.conn.scheme.Scheme.<init>(Ljava/lang/String;ILorg/apache/http/conn/scheme/SchemeSocketFactory;)V
    at org.openqa.selenium.remote.internal.HttpClientFactory.getClientConnectionManager(HttpClientFactory.java:59)
    at org.openqa.selenium.remote.internal.HttpClientFactory.<init>(HttpClientFactory.java:48)
    at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:100)
    at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:81)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:129).

Also added ' httpclient 4.1.2 '.But getting same exception,please guide me how to solve this

Use correct structure below example of service usage(And then just extends Settings inside your class with tests)

import com.google.common.collect.ImmutableMap;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.*;
import java.io.File;
import java.io.IOException;

public class Settings {
    protected static WebDriver driver;
    protected static String baseURL = "base url for tests";
    public static ChromeDriverService service;
    @BeforeClass
    public static void createAndStartService() {
        service = new ChromeDriverService.Builder().usingDriverExecutable(new File("pass to your browser")).usingAnyFreePort()
                 .build();
        try {
            service.start();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    @AfterClass
    public static void createAndStopService() {
        service.stop();
    }
    @BeforeMethod
    public void setUp() throws IOException {
        driver = new RemoteWebDriver(service.getUrl(), DesiredCapabilities.chrome());
        driver.get(baseURL);
        driver.manage().window().maximize();
    }
    @AfterMethod
    public void tearDown()
    {
        driver.quit();
    }

    public static WebDriver getDriver()
    {
        return driver;
    }
   }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM