use of org.openqa.grid.internal.TestSession in project zalenium by zalando.
the class TestingBotRemoteProxyTest method testInformationIsRetrievedWhenStoppingSession.
@Test
public void testInformationIsRetrievedWhenStoppingSession() {
// Capability which should result in a created session
Map<String, Object> requestedCapability = new HashMap<>();
requestedCapability.put(CapabilityType.BROWSER_NAME, BrowserType.CHROME);
requestedCapability.put(CapabilityType.PLATFORM_NAME, Platform.MAC);
// Getting a test session in the TestingBot node
TestingBotRemoteProxy spyProxy = spy(testingBotProxy);
TestSession testSession = spyProxy.getNewSession(requestedCapability);
Assert.assertNotNull(testSession);
String mockSeleniumSessionId = "2cf5d115-ca6f-4bc4-bc06-a4fca00836ce";
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();
spyProxy.afterCommand(testSession, request, response);
verify(spyProxy, timeout(1000 * 5)).getTestInformation(mockSeleniumSessionId);
TestInformation testInformation = spyProxy.getTestInformation(mockSeleniumSessionId);
Assert.assertEquals("loadZalandoPageAndCheckTitle", testInformation.getTestName());
Assert.assertThat(testInformation.getFileName(), CoreMatchers.containsString("testingbot_loadZalandoPageAndCheckTitle_Safari9_CAPITAN"));
Assert.assertEquals("Safari9 9, CAPITAN", testInformation.getBrowserAndPlatform());
Assert.assertEquals("https://s3-eu-west-1.amazonaws.com/eurectestingbot/2cf5d115-ca6f-4bc4-bc06-a4fca00836ce.mp4", testInformation.getVideoUrl());
}
use of org.openqa.grid.internal.TestSession in project zalenium by zalando.
the class TestingBotRemoteProxyTest 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 TestingBot node
TestSession testSession = testingBotProxy.getNewSession(requestedCapability);
Assert.assertNotNull(testSession);
// We need to mock all the needed objects to forward the session and see how in the beforeMethod
// the TestingBot 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.forward(request, response, true);
// The body should not be affected and not contain the TestingBot variables
Assert.assertThat(request.getBody(), CoreMatchers.containsString(jsonObject.toString()));
Assert.assertThat(request.getBody(), CoreMatchers.not(CoreMatchers.containsString("key")));
Assert.assertThat(request.getBody(), CoreMatchers.not(CoreMatchers.containsString("secret")));
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("key")));
Assert.assertThat(request.getBody(), CoreMatchers.not(CoreMatchers.containsString("secret")));
}
use of org.openqa.grid.internal.TestSession in project zalenium by zalando.
the class ZaleniumRegistry method takeRequestHandler.
private boolean takeRequestHandler(RequestHandler handler) {
final TestSession session = proxies.getNewSession(handler.getRequest().getDesiredCapabilities());
final boolean sessionCreated = session != null;
if (sessionCreated) {
String remoteName = "";
if (session.getSlot().getProxy() instanceof DockerSeleniumRemoteProxy) {
remoteName = ((DockerSeleniumRemoteProxy) session.getSlot().getProxy()).getRegistration().getContainerId();
}
long timeToAssignProxy = System.currentTimeMillis() - handler.getRequest().getCreationTime();
LOG.info(String.format("Test session with internal key %s assigned to remote (%s) after %s seconds (%s ms).", session.getInternalKey(), remoteName, timeToAssignProxy / 1000, timeToAssignProxy));
activeTestSessions.add(session);
handler.bindSession(session);
}
return sessionCreated;
}
use of org.openqa.grid.internal.TestSession in project zalenium by zalando.
the class BrowserStackRemoteProxyTest method credentialsAreAddedInSessionCreation.
@Test
public void credentialsAreAddedInSessionCreation() 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 BrowserStack user and api key get added to the body request.
WebDriverRequest request = TestUtils.getMockedWebDriverRequestStartSession(BrowserType.IE, Platform.WIN8);
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);
Environment env = new Environment();
// The body should now have the BrowserStack variables
String expectedBody = String.format("{\"desiredCapabilities\":{\"browserName\":\"internet explorer\",\"platformName\":" + "\"WIN8\",\"browserstack.user\":\"%s\",\"browserstack.key\":\"%s\"}}", env.getStringEnvVariable("BROWSER_STACK_USER", ""), env.getStringEnvVariable("BROWSER_STACK_KEY", ""));
verify(request).setBody(expectedBody);
}
Aggregations