硒2铬驱动器

时间:2011-09-16 21:09:29

标签: maven selenium webdriver selenium-webdriver

所以我已经阅读了关于将chromedriver添加到我的路径中的所有文档并且都遵循了所有这些文档。我在使用selenium2,maven,eclipse以及所有最新驱动程序的Mac上:

Error:
The path to the chromedriver executable must be set by the webdriver.chrome.driver system property;

我把chromedriver放在我的Applications文件夹中,我的路径如下:

echo $PATH  
/Users/tcerrato/selenium/BS_Sel_Project/auto_helper/test_scripts:/usr/local/apache-maven-2.2.1//bin:/Users/oracle/oracle/product/10.2.0/db_1/bin:/opt/local/bin:/opt/local/sbin:/Applications:

我错过了什么?我根本无法使用Chrome驱动程序。任何帮助都会很棒我现在正在尝试随机的东西。

这是我关于硒的pom部分:

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium</artifactId>
    <version>2.0rc2</version>
    <type>pom</type>
</dependency>
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-chrome-driver</artifactId>
    <version>2.5.0</version>
</dependency>
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-firefox-driver</artifactId>
    <version>2.6.0</version>
</dependency>

10 个答案:

答案 0 :(得分:31)

将此依赖项添加到项目中:

<dependency>
   <groupId>io.github.bonigarcia</groupId>
   <artifactId>webdrivermanager</artifactId>
    <version>3.6.0</version>
</dependency>

此库下载您需要的最新版本的WebDriver二进制文件并导出适当的Java系统变量(webdriver.chrome.driverwebdriver.gecko.driverwebdriver.opera.driverphantomjs.binary.path,{{1 },webdriver.edge.driver),分别只使用以下句子之一:

webdriver.ie.driver

有关https://github.com/bonigarcia/webdrivermanager

的更多信息

答案 1 :(得分:21)

我不确定Maven,但这是我如何设置属性webdriver.chrome.driver

System.setProperty("webdriver.chrome.driver", "C:\\pathto\\my\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");

答案 2 :(得分:10)

通过maven设置webdriver.chrome.driver系统属性可以通过以下方式完成(并经过测试的工作):

  1. systemPropertyVariables个配置添加到maven-surefire-plugin中的pom.xml。这是(通常)因为surefire是测试的调用者以及将设置系统属性的位置。

    <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.7.1</version>
        <configuration>
            <systemPropertyVariables>
                <webdriver.chrome.driver>${webdriver.chrome}</webdriver.chrome.driver>
            </systemPropertyVariables>
        </configuration>
    </plugin>
    
  2. 现在在某处定义${webdriver.chrome}。一个良好的开端是<properties>

    中的pom.xml部分
    <properties>
        <webdriver.chrome>/home/gede/bin/chromedriver</webdriver.chrome>
    </properties>
    
  3. 通过在Simon Martinelli的example

    中使用<profiles>可能会更好地做到这一点

答案 3 :(得分:6)

您可以使用驱动程序二进制下载程序maven插件为您下载驱动程序二进制文件(https://github.com/Ardesco/selenium-standalone-server-plugin):

                <plugin>
                    <groupId>com.lazerycode.selenium</groupId>
                    <artifactId>driver-binary-downloader-maven-plugin</artifactId>
                    <version>1.0.7</version>
                    <configuration>
                        <rootStandaloneServerDirectory>${project.basedir}/src/test/resources/selenium_standalone_binaries</rootStandaloneServerDirectory>
                        <downloadedZipFileDirectory>${project.basedir}/src/test/resources/selenium_standalone_zips</downloadedZipFileDirectory>                            
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>selenium</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

这将下载二进制文件并设置一个maven属性,您可以在surefire / failsafe配置中使用,如下所示:

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <version>2.7.2</version>
                    <configuration>                            
                        <systemProperties>                              
                            <!--Set properties passed in by the driver binary downloader-->
                            <phantomjs.binary.path>${phantomjs.binary.path}</phantomjs.binary.path>
                            <webdriver.chrome.driver>${webdriver.chrome.driver}</webdriver.chrome.driver>
                            <webdriver.ie.driver>${webdriver.ie.driver}</webdriver.ie.driver>
                            <webdriver.opera.driver>${webdriver.opera.driver}</webdriver.opera.driver>
                        </systemProperties>
                        <includes>
                            <include>**/*WebDriver.java</include>
                        </includes>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>integration-test</goal>
                                <goal>verify</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

当您实例化一个新的驱动程序对象时,现在将设置指向驱动程序二进制位置的系统属性,它将起作用。

答案 4 :(得分:2)

所以在pom中你必须像这样设置它

                  <dependency>
                  <groupId>org.seleniumhq.selenium</groupId>
                  <artifactId>selenium-chrome-driver</artifactId>
                  <version>2.34.0</version>
                  </dependency>

这是使用selenium运行chrome的java代码

        System.setProperty("webdriver.chrome.driver","C:/chromedriver.exe");
        WebDriver myD = new ChromeDriver();

要运行Chrome,您需要从此处下载Chrome驱动程序。 https://code.google.com/p/chromedriver/downloads/list

完成后,您必须在环境变量中设置它。阅读此https://code.google.com/p/selenium/wiki/ChromeDriver

谢谢,

       Mediha

答案 5 :(得分:0)

试试这个:

System.setProperty("webdriver.chrome.driver","/location to/chromedriver folder");
WebDriver driver = new ChromeDriver();
driver.get("your.app");

答案 6 :(得分:0)

System.setproperty("webdriver.chrome.driver","your file path here with chromedriver.exe");
webDriver driver=new chromeDriver();
driver.get("http://google.com");

答案 7 :(得分:0)

在没有设置webdriver.chrome.driver属性的情况下,它适用于我。只需将chromedriver添加到PATH

即可
> echo $PATH
/usr/local/bin:/usr/local/sbin:~/bin:/usr/bin:/bin:/usr/sbin:/sbin
>    
> which chromedriver
/usr/local/bin/chromedriver

如果您使用Homebrew,安装chromedriver以及添加到PATH可以这样简单:

brew install chromedriver

有用的链接:

https://sites.google.com/a/chromium.org/chromedriver/

http://brewformulas.org/Chromedriver

答案 8 :(得分:-1)

只需在您的maven pom中添加WebDriverManager,如果您的浏览器设置为默认配置,则无需手动设置即可运行。

答案 9 :(得分:-1)

    Pom.xml code and Selenium code below:


   <groupId>com.HelloWorld</groupId>
   <artifactId>t</artifactId>
   <version>0.0.1-SNAPSHOT</version>
   <packaging>jar</packaging>

   <name>t</name>
   <url>http://maven.apache.org</url>

   <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>




     <webdriver.chrome>/home/gede/bin/chromedriver</webdriver.chrome>

     </properties>

     <build>
     <resources>
        <resource>
            <directory>src/main/java/resources</directory>
            <filtering>true</filtering> 
        </resource>
      </resources>
      <plugins>

      <plugin>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>2.7.1</version>
       <configuration>
        <systemPropertyVariables>
            <webdriver.chrome.driver>${webdriver.chrome}
       </webdriver.chrome.driver>
        </systemPropertyVariables>
      </configuration>
       </plugin>


      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.20</version>
        <configuration>
          <suiteXmlFiles>
            <suiteXmlFile>testng.xml</suiteXmlFile>
          </suiteXmlFiles>
        </configuration>
        </plugin>

      </plugins>


       </build>
       <dependencies>

       <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
      </dependency>

      <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-
     chrome-driver -->
     <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-chrome-driver</artifactId>
    <version>3.8.1</version>
    </dependency>



       <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.4.0</version>
      </dependency>  
      <dependency>
     <groupId>org.testng</groupId>
     <artifactId>testng</artifactId>
      <version>6.8</version>
     <scope>test</scope>
     </dependency>

     <dependency>   
            <groupId>org.seleniumhq.selenium</groupId>   
            <artifactId>selenium-chrome-driver</artifactId>   
            <version>3.8.1</version>   
        </dependency>   

        <dependency>
       <groupId>io.github.bonigarcia</groupId>
       <artifactId>webdrivermanager</artifactId>
      <version>2.1.0</version>
      </dependency>



      <dependency>
      <groupId>com.relevantcodes</groupId>
      <artifactId>extentreports</artifactId>
     <version>2.41.2</version>
     </dependency>



      <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-api</artifactId>
      <version>2.8.2</version>
      </dependency>
      <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-core</artifactId>
      <version>2.8.2</version>
      </dependency>
     </dependencies>
</project>


 Selenuim Code 

public class App 
{
static String currentDir = System.getProperty("user.dir");
static WebDriver driver;

   @BeforeClass
    public static void setupClass() {
        ChromeDriverManager.getInstance().setup();
        driver= new ChromeDriver();
        driver.get("https://www.google.com/");
    }


@Test
    public void test() {





    System.out.println( "Hello World!" );

    }
  }