筹建Selenium Grid压力测试环境
搭建Selenium Grid压力测试环境Windows Registry Editor Version 5.00[HKEY_LOCAL_MACHINE\SYSTEM\Current
搭建Selenium Grid压力测试环境
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;@Testpublic 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;//minutespublic static void main(String[] args) {ExecutorService exec = Executors.newFixedThreadPool(threadPoolSize);CommonTest.setUrl(url);CommonTest.setProfilePath(profilePath);CommonTest.setInterval(interval);Runnable task = new Runnable() {@Overridepublic 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;//minutespublic 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>(){@Overridepublic 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()); Future<Boolean> future = exec.submit(task); Boolean taskResult = null; String failReason = null; try { taskResult = future.get(timeout, TimeUnit.SECONDS); } catch (InterruptedException e) { failReason = "Main thread was interrupted when waiting for computing result"; } catch (ExecutionException e) { failReason = "Main thread is wating for result, but excpetion throw."; e.printStackTrace(); } catch (TimeoutException e) { failReason = "Main thread is wating for result, but time out."; exec.shutdownNow(); } System.out.println(taskResult+";"+failReason); Calendar end = Calendar.getInstance(); end.setTime(new Date()); long duration = (end.getTimeInMillis()-start.getTimeInMillis())/1000/60; System.out.println("duration is "+duration); if(duration<interval){ System.out.println("Wating ..."+ String.valueOf(interval-duration)+" minutes"); Thread.sleep(1000*(interval-duration)*60); }}public static boolean deleteDirectory(File path) {if (path.exists()) {File[] files = path.listFiles();if(files==null)return true;for (int i = 0; i < files.length; i++) {if(files[i].lastModified()> Calendar.getInstance().getTimeInMillis()-1000*60*60)continue;if (files[i].isDirectory()) {deleteDirectory(files[i]);} else {files[i].delete();}}}return path.delete();}}?
Because stress testing brought a big burden to node machine, so it might occupied too much CPU & Memory in node machine, make node machine can't create driver successfully.
So change the c:\grid\service\watchdog\watchdog.config file, change run_time to 5, default is 15. And delete watchdog.log file.
netstat -na (check connection situation)Problems we might found:
org.openqa.selenium.remote.SessionNotFoundException: Unexpected error launching Internet Explorer. Could not get document from window handle
chrome crash
Solution: kill all related processes, clean the temp folder, restart selenium node service
?