use of org.openqa.grid.web.servlet.handler.WebDriverRequest in project zalenium by zalando.
the class DockerSeleniumRemoteProxy method beforeCommand.
@Override
public void beforeCommand(TestSession session, HttpServletRequest request, HttpServletResponse response) {
super.beforeCommand(session, request, response);
LOGGER.debug(getId() + " lastCommand: " + request.getMethod() + " - " + request.getPathInfo() + " executing...");
if (request instanceof WebDriverRequest && "POST".equalsIgnoreCase(request.getMethod())) {
WebDriverRequest seleniumRequest = (WebDriverRequest) request;
if (seleniumRequest.getPathInfo().endsWith("cookie")) {
LOGGER.debug(getId() + " Checking for cookies..." + seleniumRequest.getBody());
JsonElement bodyRequest = new JsonParser().parse(seleniumRequest.getBody());
JsonObject cookie = bodyRequest.getAsJsonObject().getAsJsonObject("cookie");
JsonObject emptyName = new JsonObject();
emptyName.addProperty("name", "");
String cookieName = Optional.ofNullable(cookie.get("name")).orElse(emptyName.get("name")).getAsString();
if ("zaleniumTestPassed".equalsIgnoreCase(cookieName)) {
boolean testPassed = Boolean.parseBoolean(cookie.get("value").getAsString());
if (testPassed) {
testInformation.setTestStatus(TestInformation.TestStatus.SUCCESS);
} else {
testInformation.setTestStatus(TestInformation.TestStatus.FAILED);
}
}
if ("zaleniumMessage".equalsIgnoreCase(cookieName)) {
String message = cookie.get("value").getAsString();
String messageCommand = String.format(" 'Zalenium', '%s', --icon=/home/seluser/images/message.png", message);
processContainerAction(DockerSeleniumContainerAction.CLEAN_NOTIFICATION, getContainerId());
processContainerAction(DockerSeleniumContainerAction.SEND_NOTIFICATION, messageCommand, getContainerId());
}
}
}
}
use of org.openqa.grid.web.servlet.handler.WebDriverRequest in project zalenium by zalando.
the class BrowserStackRemoteProxyTest method testInformationIsRetrievedWhenStoppingSession.
@Test
public void testInformationIsRetrievedWhenStoppingSession() throws IOException {
// Capability which should result in a created session
try {
Map<String, Object> requestedCapability = new HashMap<>();
requestedCapability.put(CapabilityType.BROWSER_NAME, BrowserType.CHROME);
requestedCapability.put(CapabilityType.PLATFORM_NAME, Platform.WIN10);
JsonElement informationSample = TestUtils.getTestInformationSample("browserstack_testinformation.json");
TestUtils.ensureRequiredInputFilesExist(temporaryFolder);
CommonProxyUtilities commonProxyUtilities = TestUtils.mockCommonProxyUtilitiesForDashboardTesting(temporaryFolder);
Environment env = new Environment();
String mockTestInformationUrl = "https://www.browserstack.com/automate/sessions/77e51cead8e6e37b0a0feb0dfa69325b2c4acf97.json";
when(commonProxyUtilities.readJSONFromUrl(mockTestInformationUrl, env.getStringEnvVariable("BROWSER_STACK_USER", ""), env.getStringEnvVariable("BROWSER_STACK_KEY", ""))).thenReturn(informationSample);
BrowserStackRemoteProxy.setCommonProxyUtilities(commonProxyUtilities);
Dashboard.setCommonProxyUtilities(commonProxyUtilities);
// Getting a test session in the sauce labs node
BrowserStackRemoteProxy bsSpyProxy = spy(browserStackProxy);
TestSession testSession = bsSpyProxy.getNewSession(requestedCapability);
Assert.assertNotNull(testSession);
String mockSeleniumSessionId = "77e51cead8e6e37b0a0feb0dfa69325b2c4acf97";
testSession.setExternalKey(new ExternalSessionKey(mockSeleniumSessionId));
// We release the session, the node should be free
WebDriverRequest request = mock(WebDriverRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
when(request.getMethod()).thenReturn("DELETE");
when(request.getRequestType()).thenReturn(RequestType.STOP_SESSION);
testSession.getSlot().doFinishRelease();
bsSpyProxy.afterCommand(testSession, request, response);
verify(bsSpyProxy, timeout(1000 * 5)).getTestInformation(mockSeleniumSessionId);
Callable<Boolean> callable = () -> BrowserStackRemoteProxy.addToDashboardCalled;
await().pollInterval(Duration.FIVE_HUNDRED_MILLISECONDS).atMost(Duration.TWO_SECONDS).until(callable);
TestInformation testInformation = bsSpyProxy.getTestInformation(mockSeleniumSessionId);
Assert.assertEquals("loadZalandoPageAndCheckTitle", testInformation.getTestName());
Assert.assertThat(testInformation.getFileName(), CoreMatchers.containsString("browserstack_loadZalandoPageAndCheckTitle_safari_OS_X"));
Assert.assertEquals("safari 6.2, OS X Mountain Lion", testInformation.getBrowserAndPlatform());
Assert.assertEquals("https://www.browserstack.com/s3-upload/bs-video-logs-use/s3/77e51cead8e6e37b0" + "a0feb0dfa69325b2c4acf97/video-77e51cead8e6e37b0a0feb0dfa69325b2c4acf97.mp4?AWSAccessKeyId=" + "AKIAIOW7IEY5D4X2OFIA&Expires=1497088589&Signature=tQ9SCH1lgg6FjlBIhlTDwummLWc%3D&response-" + "content-type=video%2Fmp4", testInformation.getVideoUrl());
} finally {
BrowserStackRemoteProxy.restoreCommonProxyUtilities();
BrowserStackRemoteProxy.restoreGa();
BrowserStackRemoteProxy.restoreEnvironment();
Dashboard.restoreCommonProxyUtilities();
}
}
use of org.openqa.grid.web.servlet.handler.WebDriverRequest in project zalenium by zalando.
the class BrowserStackRemoteProxyTest method requestIsNotModifiedInOtherRequestTypes.
@Test
public void requestIsNotModifiedInOtherRequestTypes() throws IOException {
// Capability which should result in a created session
Map<String, Object> requestedCapability = new HashMap<>();
requestedCapability.put(CapabilityType.BROWSER_NAME, BrowserType.IE);
requestedCapability.put(CapabilityType.PLATFORM_NAME, Platform.WIN8);
// Getting a test session in the sauce labs node
TestSession testSession = browserStackProxy.getNewSession(requestedCapability);
Assert.assertNotNull(testSession);
// We need to mock all the needed objects to forward the session and see how in the beforeMethod
// the SauceLabs user and api key get added to the body request.
WebDriverRequest request = mock(WebDriverRequest.class);
when(request.getRequestURI()).thenReturn("session");
when(request.getServletPath()).thenReturn("session");
when(request.getContextPath()).thenReturn("");
when(request.getMethod()).thenReturn("POST");
when(request.getRequestType()).thenReturn(RequestType.REGULAR);
JsonObject jsonObject = new JsonObject();
JsonObject desiredCapabilities = new JsonObject();
desiredCapabilities.addProperty(CapabilityType.BROWSER_NAME, BrowserType.IE);
desiredCapabilities.addProperty(CapabilityType.PLATFORM_NAME, Platform.WIN8.name());
jsonObject.add("desiredCapabilities", desiredCapabilities);
when(request.getBody()).thenReturn(jsonObject.toString());
Enumeration<String> strings = Collections.emptyEnumeration();
when(request.getHeaderNames()).thenReturn(strings);
HttpServletResponse response = mock(HttpServletResponse.class);
ServletOutputStream stream = mock(ServletOutputStream.class);
when(response.getOutputStream()).thenReturn(stream);
testSession.setExternalKey(new ExternalSessionKey("BrowserStack Test"));
testSession.forward(request, response, true);
// The body should not be affected and not contain the BrowserStack variables
Assert.assertThat(request.getBody(), CoreMatchers.containsString(jsonObject.toString()));
Assert.assertThat(request.getBody(), CoreMatchers.not(CoreMatchers.containsString("browserstack.user")));
Assert.assertThat(request.getBody(), CoreMatchers.not(CoreMatchers.containsString("browserstack.key")));
when(request.getMethod()).thenReturn("GET");
testSession.forward(request, response, true);
Assert.assertThat(request.getBody(), CoreMatchers.containsString(jsonObject.toString()));
Assert.assertThat(request.getBody(), CoreMatchers.not(CoreMatchers.containsString("browserstack.user")));
Assert.assertThat(request.getBody(), CoreMatchers.not(CoreMatchers.containsString("browserstack.key")));
}
use of org.openqa.grid.web.servlet.handler.WebDriverRequest in project zalenium by zalando.
the class DockerSeleniumRemoteProxyTest method testIsMarkedAsPassedAndFailedWithCookie.
@Test
public void testIsMarkedAsPassedAndFailedWithCookie() {
// Supported desired capability for the test session
Map<String, Object> requestedCapability = getCapabilitySupportedByDockerSelenium();
// Start polling thread
proxy.startPolling();
// Get a test session
TestSession newSession = proxy.getNewSession(requestedCapability);
Assert.assertNotNull(newSession);
// The node should be busy since there is a session in it
Assert.assertTrue(proxy.isBusy());
// We release the session, the node should be free
WebDriverRequest request = mock(WebDriverRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
when(request.getMethod()).thenReturn("POST");
when(request.getRequestType()).thenReturn(RequestType.REGULAR);
when(request.getPathInfo()).thenReturn("/cookie");
when(request.getBody()).thenReturn("{\"cookie\": {\"name\": \"zaleniumTestPassed\", \"value\": true}}");
proxy.beforeCommand(newSession, request, response);
Assert.assertEquals(TestInformation.TestStatus.SUCCESS, proxy.getTestInformation().getTestStatus());
when(request.getBody()).thenReturn("{\"cookie\": {\"name\": \"zaleniumTestPassed\", \"value\": false}}");
proxy.beforeCommand(newSession, request, response);
Assert.assertEquals(TestInformation.TestStatus.FAILED, proxy.getTestInformation().getTestStatus());
}
use of org.openqa.grid.web.servlet.handler.WebDriverRequest in project zalenium by zalando.
the class DockerSeleniumRemoteProxyTest method nodeShutsDownWhenTestIsIdle.
@Test
public void nodeShutsDownWhenTestIsIdle() {
// Supported desired capability for the test session
Map<String, Object> requestedCapability = getCapabilitySupportedByDockerSelenium();
requestedCapability.put("idleTimeout", 1L);
DockerSeleniumRemoteProxy spyProxy = spy(proxy);
// Start pulling thread
spyProxy.startPolling();
// Get a test session
TestSession newSession = spyProxy.getNewSession(requestedCapability);
Assert.assertNotNull(newSession);
// Start the session
WebDriverRequest webDriverRequest = mock(WebDriverRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
when(webDriverRequest.getMethod()).thenReturn("POST");
when(webDriverRequest.getRequestType()).thenReturn(RequestType.START_SESSION);
when(webDriverRequest.getPathInfo()).thenReturn("/something");
spyProxy.beforeCommand(newSession, webDriverRequest, response);
// The node should be busy since there is a session in it
Assert.assertTrue(spyProxy.isBusy());
// The node should tear down after the maximum idle time is elapsed
Assert.assertTrue(spyProxy.isBusy());
Callable<Boolean> callable = () -> registry.getProxyById(spyProxy.getId()) == null;
await().pollInterval(Duration.FIVE_HUNDRED_MILLISECONDS).atMost(Duration.FIVE_SECONDS).until(callable);
}
Aggregations