public void setSession(TestSession session) { super.setSession(session); }
@Test(timeout = 10000) public void method() throws InterruptedException { final List<TestSession> sessions = new CopyOnWriteArrayList<TestSession>(); for (int i = 0; i < MAX; i++) { new Thread( new Runnable() { // Thread safety reviewed public void run() { RequestHandler newSessionRequest = GridHelper.createNewSessionHandler(registry, ie); newSessionRequest.process(); TestSession session = newSessionRequest.getSession(); inc(); sessions.add(session); } }) .start(); } for (int i = 0; i < MAX; i++) { new Thread( new Runnable() { // Thread safety reviewed public void run() { RequestHandler newSessionRequest = GridHelper.createNewSessionHandler(registry, ff); newSessionRequest.process(); TestSession session = newSessionRequest.getSession(); inc(); sessions.add(session); } }) .start(); } // 2 run on the hub. while (registry.getActiveSessions().size() != 2) { Thread.sleep(50); } // while the rest waits. while (registry.getNewSessionRequestCount() != 18) { Thread.sleep(50); } int stopped = 0; // all the tests ran via the registry. while (stopped < 2 * MAX) { for (TestSession session : sessions) { RequestHandler stopSessionRequest = GridHelper.createStopSessionHandler(registry, session); stopSessionRequest.process(); stopped++; sessions.remove(session); } } // all request got the stop session request assertEquals(2 * MAX, stopped); // nothing left waiting assertEquals(0, registry.getNewSessionRequestCount()); // nothing active. Waiting in case a stopSessionRequest.process() isn't finish. It's async. while (registry.getActiveSessions().size() != 0) { Thread.sleep(10); } assertEquals(0, registry.getActiveSessions().size()); // everything was started. assertEquals(2 * MAX, ran); }
@Test(timeout = 5000) public void testBrowserLocations() throws MalformedURLException { Map<String, Object> req_caps = null; RequestHandler newSessionRequest = null; // firefox req_caps = new HashMap<>(); req_caps.put(CapabilityType.BROWSER_NAME, BrowserType.FIREFOX); req_caps.put(CapabilityType.VERSION, "7"); newSessionRequest = new MockedRequestHandler(getNewRequest(req_caps)); newSessionRequest.process(); assertEquals( locationFF7, newSessionRequest.getSession().getRequestedCapabilities().get(FirefoxDriver.BINARY)); req_caps = new HashMap<>(); req_caps.put(CapabilityType.BROWSER_NAME, BrowserType.FIREFOX); req_caps.put(CapabilityType.VERSION, "3"); newSessionRequest = new MockedRequestHandler(getNewRequest(req_caps)); newSessionRequest.process(); assertEquals( locationFF3, newSessionRequest.getSession().getRequestedCapabilities().get(FirefoxDriver.BINARY)); req_caps = new HashMap<>(); req_caps.put(CapabilityType.BROWSER_NAME, BrowserType.FIREFOX); req_caps.put(CapabilityType.VERSION, "20"); req_caps.put(FirefoxDriver.BINARY, "custom"); newSessionRequest = new MockedRequestHandler(getNewRequest(req_caps)); newSessionRequest.process(); assertEquals( "custom", newSessionRequest.getSession().getRequestedCapabilities().get(FirefoxDriver.BINARY)); // chrome req_caps = new HashMap<>(); req_caps.put(CapabilityType.BROWSER_NAME, BrowserType.CHROME); req_caps.put(CapabilityType.VERSION, "27"); newSessionRequest = new MockedRequestHandler(getNewRequest(req_caps)); newSessionRequest.process(); Map<String, Object> json = (Map<String, Object>) newSessionRequest.getSession().getRequestedCapabilities().get(ChromeOptions.CAPABILITY); assertEquals(locationChrome27, json.get("binary")); req_caps = new HashMap<>(); req_caps.put(CapabilityType.BROWSER_NAME, BrowserType.CHROME); req_caps.put(CapabilityType.VERSION, "29"); newSessionRequest = new MockedRequestHandler(getNewRequest(req_caps)); newSessionRequest.process(); json = (Map<String, Object>) newSessionRequest.getSession().getRequestedCapabilities().get(ChromeOptions.CAPABILITY); assertEquals(locationChrome29, json.get("binary")); req_caps = new HashMap<>(); req_caps.put(CapabilityType.BROWSER_NAME, BrowserType.CHROME); req_caps.put(CapabilityType.VERSION, "29"); Map<String, Object> options = new HashMap<>(); options.put("test1", "test2"); req_caps.put(ChromeOptions.CAPABILITY, options); newSessionRequest = new MockedRequestHandler(getNewRequest(req_caps)); newSessionRequest.process(); json = (Map<String, Object>) newSessionRequest.getSession().getRequestedCapabilities().get(ChromeOptions.CAPABILITY); assertEquals(locationChrome29, json.get("binary")); assertEquals("test2", json.get("test1")); req_caps = new HashMap<>(); req_caps.put(CapabilityType.BROWSER_NAME, BrowserType.CHROME); req_caps.put(CapabilityType.VERSION, "30"); options = new HashMap<>(); options.put("test11", "test22"); options.put("binary", "custom"); req_caps.put(ChromeOptions.CAPABILITY, options); newSessionRequest = new MockedRequestHandler(getNewRequest(req_caps)); newSessionRequest.process(); json = (Map<String, Object>) newSessionRequest.getSession().getRequestedCapabilities().get(ChromeOptions.CAPABILITY); assertEquals("custom", json.get("binary")); assertEquals("test22", json.get("test11")); }