搭建Selenium Grid压力测试环境

  1. In one machine, run registry file MaxUserPort.reg
  2. Windows Registry Editor Version 5.00
    
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters]
    "EnableICMPRedirect"=dword:00000000
    "TcpTimedWaitDelay"=dword:0000001e
    "MaxUserPort"=dword:0000ea60
    "DisableIPSourceRouting"=dword:00000002
    "EnableDeadGWDetect"=dword:00000000
    "KeepAliveTime"=dword:000493e0
    "TcpMaxDataRetransmissions"=dword:00000004
     
         
/**
 * @author junjshi, created on Sep 3, 2013
 * 
 */


import java.io.File;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.testng.annotations.Test;

import com.ebay.maui.controller.TestPlan;
@Test
public class GridTest extends TestPlan{
	private static String browser="firefox";
	
	private static final int threadPoolSize = 200;
	private static int count = 0;
	private static String profilePath = "C:\\grid\\profile\\customProfileDirCUSTFF";
	private static String url = "http://gear2-hub-8915.phx-os1.stratus.dev.ebay.com:8080/wd/hub";
	private static final int interval = 2;//minutes
	
	public static void main(String[] args) {
		ExecutorService exec = Executors.newFixedThreadPool(threadPoolSize);
		CommonTest.setUrl(url);
		CommonTest.setProfilePath(profilePath);
		CommonTest.setInterval(interval);
		Runnable task = new Runnable() {
			@Override
			public void run() {
				while (true) {
					try {
						
						System.out.println("Clean "+System.getProperty("java.io.tmpdir"));
						File tempDir = new File(System.getProperty("java.io.tmpdir"));
						CommonTest.deleteDirectory(tempDir);
						System.out.println("Executing thread #"+ count++);
						new CommonTest().testGrid(browser);
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
		};

		for (int i = 0; i < threadPoolSize; i++) {
			exec.execute(task);
		}
	}

	

}
 
  CommonTest.java  
import java.io.File;
import java.net.MalformedURLException;
import java.util.Calendar;
import java.util.Date;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import org.openqa.selenium.WebDriver;

import com.ebay.maui.driver.web.WebUXDriver;

/**
 * @author junjshi, created on Dec 9, 2013
 * 
 */

public class CommonTest {
	private static String profilePath = "C:\\grid\\profile\\customProfileDirCUSTFF";
	private static String url = "http://gear2-hub-8915.phx-os1.stratus.dev.ebay.com:8080/wd/hub";
	private static int interval = 2;//minutes
	
	
	
	public static void setInterval(int interval) {
		CommonTest.interval = interval;
	}

	public static String getProfilePath() {
		return profilePath;
	}

	public static void setProfilePath(String profilePath) {
		CommonTest.profilePath = profilePath;
	}

	public static String getUrl() {
		return url;
	}

	public static void setUrl(String url) {
		CommonTest.url = url;
	}

	public static int getInterval() {
		return interval;
	}

	public void runTest(String url) throws MalformedURLException{
		WebUXDriver.getWebUXDriver().setMode("ExistingGrid");
		WebUXDriver.getWebUXDriver().setHubUrl(url);
		WebUXDriver.getWebUXDriver().setFfProfilePath(profilePath);
		WebDriver driver = WebUXDriver.getWebDriver(true);
		driver.get("http://www.qa.ebay.com");
		driver.get("http://www.qa.ebay.com");
		driver.get("http://www.qa.ebay.com");
		System.out.println(driver.getTitle());
		try{
			driver.quit();
		}catch(Exception ex){}
	}
	
	public void runChromeTest(String url) throws MalformedURLException{

		WebUXDriver.getWebUXDriver().setBrowser("chrome");
		WebUXDriver.getWebUXDriver().setMode("ExistingGrid");
		WebUXDriver.getWebUXDriver().setHubUrl(url);
		WebDriver driver = WebUXDriver.getWebDriver(true);
		driver.get("http://www.qa.ebay.com");
		driver.get("http://www.qa.ebay.com");
		driver.get("http://www.qa.ebay.com");
		System.out.println(driver.getTitle());
		try{
			driver.quit();
		}catch(Exception ex){}
	}
	
	public void runIETest(String url) throws MalformedURLException{

		WebUXDriver.getWebUXDriver().setBrowser("iexplore");
		WebUXDriver.getWebUXDriver().setMode("ExistingGrid");
		WebUXDriver.getWebUXDriver().setHubUrl(url);
		WebDriver driver = WebUXDriver.getWebDriver(true);
		driver.get("http://www.qa.ebay.com");
		System.out.println(driver.getTitle());
		try{
			driver.quit();
		}catch(Exception ex){}
	}
	
	public void testGrid(String browser) throws MalformedURLException, InterruptedException{
		ExecutorService exec = Executors.newCachedThreadPool();    
        int timeout =  60 * 30;
        final String browserName = browser;
        Callable<Boolean> task = new Callable<Boolean>(){

			@Override
			public Boolean call() throws Exception {
				if(browserName.equalsIgnoreCase("chrome")){
					runChromeTest(url);
					return Boolean.TRUE;  
				}else if(browserName.equalsIgnoreCase("firefox")){
					runTest(url);
					return Boolean.TRUE;
				}else
				{
					runIETest(url);
					return Boolean.TRUE;	
				}
			}
	    };
	    Calendar start = Calendar.getInstance();
	    start.setTime(new Date());
       
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值