简体   繁体   English

在Maven中运行硒测试时出现异常

[英]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.

相关问题 使用 java-selenium 运行黄瓜测试时出现“java.lang.OutOfMemoryError”异常 - Getting "java.lang.OutOfMemoryError" exception while running a cucumber test using java-selenium 从 maven-Selenium 测试中获取 Initializer 异常 - Getting Exception In Initializer error from maven- Selenium test 通过Maven测试运行TestNG项目时获取&#39;SurefireExecutionException&#39; - Getting 'SurefireExecutionException' while running TestNG project via maven test 通过TestNG运行测试时获取Null Pointer异常 - Getting Null Pointer Exception while running a test through TestNG NoClassDefFoundError: org/openqa/selenium/virtualauthenticator/HasVirtualAuthenticator 在使用 TestNG 和 Maven 运行测试时出错 - NoClassDefFoundError: org/openqa/selenium/virtualauthenticator/HasVirtualAuthenticator error while running test using TestNG and Maven 运行TestNG测试时出现异常 - Exception while running a TestNG test 1. 运行 Maven 项目(Selenium,Java)时发生编译错误和构建失败,运行方式-&gt; Maven 测试。如何修复此编译器错误 - 1. COMPILATION ERROR and BUILD FAILURE occurred while running the Maven project (Selenium, Java) , Run As-> Maven test .How to fix this compiler error 使用硒运行自动化测试时如何捕获Internet异常丢失 - how to catch loss of internet exception while running a automation test using selenium 运行 selenium 测试时出现 Null 指针异常。 我正在使用页面 object model - Null pointer exception while running selenium test. I am using Page object model 线程“main”中的异常 java.lang.IllegalStateException:在 Ubuntu 上运行 Selenium 测试时驱动程序可执行文件不存在 - Exception in thread "main" java.lang.IllegalStateException: The driver executable does not exist while running Selenium Test on Ubuntu
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM