[英]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:- 我正在使用java,maven,selenium-webdriver。我已经添加了依赖项' selenium-server 2.32.0','selenium-java 2.32.0 '。但是我得到了如下异常:这是代码:-
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. 如您所见,我还创建了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).
Also added ' httpclient 4.1.2 '.But getting same exception,please guide me how to solve this 还添加了“ httpclient 4.1.2 ”。但是出现相同的异常,请指导我如何解决此问题
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;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.