se chorme驱动

import java.io.File;
import java.io.IOException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

public class DemoTest {
	public WebDriver driver;

	public void setChromeDriver() {

		String chromePath = "E:/Driver/chromedriver.exe";

		String driverTpye = "webdriver.chrome.driver";

		System.setProperty(driverTpye, chromePath);

		ChromeDriverService service =

		new ChromeDriverService.Builder()
				.usingDriverExecutable(new File(chromePath)).usingAnyFreePort()
				.build();

		try {

			service.start();

		} catch (IOException e) {

			// TODO Auto-generated catch block

			e.printStackTrace();

		}

		driver = new RemoteWebDriver(service.getUrl(),
				DesiredCapabilities.chrome());

	}

	public void getBaidu(WebDriver driver) {
		driver.get("http://www.baidu.com");
	}

	public static void main(String args[]) {
		DemoTest demo = new DemoTest();
		demo.setChromeDriver();
		demo.getBaidu(demo.driver);

	}

}



目的:

执行以上代码你会发现ChromeDriver仅是在创建是启动,调用quit时关闭浏览器,ChromeDriver是轻量级的服务若在一个比较大的 测试套件中频繁的启动关闭,会增加一个比较明显的延时导致浏览器进程不被关闭的情况发生,为了避免这一状况我们可以通过ChromeDriverService来控制ChromeDriver进程的生死,达到用完就关闭的效果避免进程占用情况出现(Running the server in a child process)。





你可能感兴趣的:(orm)