selenium2(webdriver)的“兄弟姐妹”

1.  web页面性能-browsermob-proxy

Browsermob-proxy开源工具,用来截取页面加载性能相关的数据。数据格式为HTML Archive(HAR), 本质上是json,用来存储http请求/响应的信息
。这些数据可以被其他支出har的http分析工具使用,如firebug,httpwatch,fiddler等。通过这些数据,来分析网站的web前端性能瓶颈。


1) 把 jar包 加入到项目中

2)  代码:
package seleniumTest;

import java.io.File;
import java.io.IOException;

import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;

import net.lightbody.bmp.core.har.Har;
import net.lightbody.bmp.proxy.ProxyServer;

public class browsermobproxyTest {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		ProxyServer server = new ProxyServer(9097);
		server.start();
		Proxy proxy = server.seleniumProxy();
		DesiredCapabilities desiredCapabilities =new DesiredCapabilities();
		desiredCapabilities.setCapability(CapabilityType.PROXY, proxy);
		WebDriver driver=new FirefoxDriver(desiredCapabilities);
        //driver.get("https://www.baidu.com/");
        driver.manage().window().maximize();
		server.newHar("baidu");
        driver.get("https://www.baidu.com/");
        
        Har har=server.getHar();<span style="font-family: Arial, Helvetica, sans-serif;">//获取</span><span class="s1" style="font-family: Arial, Helvetica, sans-serif;">har</span><span style="font-family: Arial, Helvetica, sans-serif;">数据</span>
        File harFile = new File("/Users/apple/Documents/harbaidu.com.json");
        har.writeTo(harFile);
        server.stop();
        driver.close();

	}

}
3) 生成的HAR文件harbaidu.com.json拖入下面的页面中:

效果如下图:看数据加载的时间消耗



2. jmeter 

如果想在jmeter中使用webdriver, 需要安装webdriver 插件,下载地址:

1)  下载解压后的lib中的jar放入jmeter的lib中
 注意:JMeterPlugins-WebDriver.jar 要放入jmeter/lib/ext文件中


var pkg = JavaImporter(org.openqa.selenium)
var support_UI =JavaImporter(org.openqa.selenium.support.ui.WebDriverWait)
var wait = new support_UI.WebDriverWait(WDS.browser,5000)

WDS.sampleResult.sampleStart()
WDS.browser.get('http://www.baidu.com/')


var searchField = WDS.browser.findElement(pkg.By.id('kw'))
searchField.click()

searchField.sendKeys(['jemter webdriver demo'])

var button = WDS.browser.findElement(pkg.By.id('su'))

button.click()


WDS.sampleResult.sampleEnd()



注: 自己试验的报如下错误: 
2015/11/14 22:35:31 ERROR - jmeter.threads.JMeterThread: Test failed! java.lang.NoClassDefFoundError: Could not initialize class org.apache.http.conn.ssl.SSLConnectionSocketFactory



junit4:webdriver+jmeter:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

多则惑少则明

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值