Selenium之Driver比较

 

 

Selenium常见的又IE,firefox,chrome,phone等driver,可是他们的运行速度又怎么样呢;

 

 

最近做了一个小小的测试;

 

代码奉上:

 

long start = System.currentTimeMillis();
		System.setProperty("phantomjs.binary.path", "E:/softest/Selenium/phantomjs-1.9.2/phantomjs/phantomjs.exe");
		dCaps = new DesiredCapabilities();
		dCaps.setJavascriptEnabled(true);
		dCaps.setCapability("takesScreenshot", false);

		driver = new PhantomJSDriver(dCaps);
		baseUrl = "http://www.baidu.com";
		driver.get(baseUrl);
		driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
		List links = driver.findElements(By.tagName("a"));
		System.out.println("Total Links present is " + links.size());
		for (int i = 0; i < links.size(); i++) {
//			System.out.println("Links are listed " + ((WebElement) links.get(i)).getAttribute("href"));
		}
		System.out.println("The PhantomJSDriver driver cost : " + (System.currentTimeMillis() - start));
		driver.quit();
		
		start = System.currentTimeMillis();
		driver = new HtmlUnitDriver(dCaps);
		baseUrl = "http://www.baidu.com";
		driver.get(baseUrl);
		driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
		links = driver.findElements(By.tagName("a"));
		System.out.println("Total Links present is " + links.size());
		for (int i = 0; i < links.size(); i++) {
//			System.out.println("Links are listed " + ((WebElement) links.get(i)).getAttribute("href"));
		}
		System.out.println("The HtmlUnitDriver driver cost : " + (System.currentTimeMillis() - start));
		driver.quit();
		
		start = System.currentTimeMillis();
		System.setProperty("webdriver.firefox.bin", "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
		driver = new FirefoxDriver(dCaps);
		baseUrl = "http://www.baidu.com";
		driver.get(baseUrl);
		driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
		links = driver.findElements(By.tagName("a"));
		System.out.println("Total Links present is " + links.size());
		for (int i = 0; i < links.size(); i++) {
//			System.out.println("Links are listed " + ((WebElement) links.get(i)).getAttribute("href"));
		}
		System.out.println("The FirefoxDriver driver cost : " + (System.currentTimeMillis() - start));
		driver.quit();

 运行结果其实估计也能猜到:

 

Total Links present is 45
The PhantomJSDriver driver cost : 4541

Total Links present is 45
The HtmlUnitDriver driver cost : 6693

Total Links present is 45
The FirefoxDriver driver cost : 14882

 

当然这个测试结果不能作为一个判断的唯一标准,可能和我本机的性能有一定关系,而且这种测试方式也是不恰当。

 

 

转:


Selenium之Driver比较_第1张图片
 

 

你可能感兴趣的:(Selenium之Driver比较)