2013-05-10 65 views
0

我正在使用java,maven,selenium-webdriver.I已添加依賴關係'selenium-server 2.32.0','selenium-java 2.32.0'。但我越來越例外情況如下: 以下是代碼: -在maven中運行selenium測試時得到異常

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

正如你看到的,我也firefoxdriver實例,但得到相同的異常產生。

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

還增加了「的HttpClient 4.1.2」。但得到相同的異常,請指導我如何解決這個

+1

你能提供完整的堆棧跟蹤和代碼? – aimbire 2013-05-10 13:07:48

+0

在這裏有一個模板,你可以嘗試:https://github.com/Ardesco/Selenium-Maven-Template – Ardesco 2013-05-10 13:21:49

回答

0

使用正確的結構示例服務使用以下(然後就是擴展您的內部設置類與測試)

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; 
    } 
    } 
相關問題