Selenium + Java + Chrome environmental structures

Today, speaking about building automated test environment, the whole process is divided into four steps, very simple.

A, chrome browser installed

  1, download and install the chrome browser, many online download path.

       2, due to selenium only embedded firefox driver package, and does not include chrome, so we need to download the corresponding version of the browser chrome chromedriver, address: http://npm.taobao.org/mirrors/chromedriver/ ; and on chrome version corresponding driver has the latest documentation on the Web site, as follows:

  

  Details can be read on their own view, not repeat them here.

  After downloaded, the Chromedriver.exe on the Chrome browser installation directory, as follows:

  

Two, selenium

   Official website to download the latest selenium jar package, I downloaded this:

 

 

Three, java environment installation and configuration: jdk + eclipse

   1, the official website to download jdk, mounting configurations, the online document summarizes a lot, Baidu, you know

  

  2, eclipse download

  Available to the official website to download the latest eclipse, there are various online version, I am win7 Ultimate 64bit system, this is downloaded

  

  After installing the eclipse, the new Project, build path in the selenium introduced into the jar package in,

  

 

Fourth, the test

  Under the new eclipse project package, the new class, run the following code, if Chrome can automatically open your browser and open the URL is ok.  

  package com.test.selenium;

  import java.util.concurrent.TimeUnit;

  import org.openqa.selenium.WebDriver;
  import org.openqa.selenium.chrome.ChromeDriver;

  public class testSelenium {

  public static void main(String[] args) {

  //参数配置
  System.setProperty("webdriver.chrome.driver",
  "C:/Users/zdm/AppData/Local/Google/Chrome/Application/chromedriver.exe");

  WebDriver driver;
  driver = new ChromeDriver();
  driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);

  driver.get("http://www.baidu.com");
  driver.manage().deleteAllCookies();

  try {
  Thread.sleep(3000);
  } catch (InterruptedException e) {
  e.printStackTrace();
  }
  driver.close();
  }

  }

Guess you like

Origin www.cnblogs.com/pinktest/p/11094596.html