use of org.openqa.grid.web.servlet.handler.WebDriverRequest in project zalenium by zalando.
the class SauceLabsRemoteProxyTest method checkBeforeSessionInvocation.
@Test
public void checkBeforeSessionInvocation() throws IOException {
// Capability which should result in a created session
Map<String, Object> requestedCapability = new HashMap<>();
requestedCapability.put(CapabilityType.BROWSER_NAME, BrowserType.SAFARI);
requestedCapability.put(CapabilityType.PLATFORM_NAME, Platform.MAC);
// Getting a test session in the sauce labs node
TestSession testSession = sauceLabsProxy.getNewSession(requestedCapability);
System.out.println(requestedCapability.toString());
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 = TestUtils.getMockedWebDriverRequestStartSession(BrowserType.SAFARI, Platform.MAC);
HttpServletResponse response = mock(HttpServletResponse.class);
ServletOutputStream stream = mock(ServletOutputStream.class);
when(response.getOutputStream()).thenReturn(stream);
testSession.forward(request, response, true);
Environment env = new Environment();
// The body should now have the SauceLabs variables
String expectedBody = String.format("{\"desiredCapabilities\":{\"browserName\":\"safari\",\"platformName\":" + "\"MAC\",\"username\":\"%s\",\"accessKey\":\"%s\",\"version\":\"latest\"}}", env.getStringEnvVariable("SAUCE_USERNAME", ""), env.getStringEnvVariable("SAUCE_ACCESS_KEY", ""));
verify(request).setBody(expectedBody);
}
use of org.openqa.grid.web.servlet.handler.WebDriverRequest in project zalenium by zalando.
the class TestingBotRemoteProxyTest 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 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 = TestUtils.getMockedWebDriverRequestStartSession(BrowserType.IE, Platform.WIN8);
HttpServletResponse response = mock(HttpServletResponse.class);
ServletOutputStream stream = mock(ServletOutputStream.class);
when(response.getOutputStream()).thenReturn(stream);
testSession.forward(request, response, true);
Environment env = new Environment();
// The body should now have the TestingBot variables
String expectedBody = String.format("{\"desiredCapabilities\":{\"browserName\":\"internet explorer\",\"platformName\":" + "\"WIN8\",\"key\":\"%s\",\"secret\":\"%s\",\"version\":\"latest\"}}", env.getStringEnvVariable("TESTINGBOT_KEY", ""), env.getStringEnvVariable("TESTINGBOT_SECRET", ""));
verify(request).setBody(expectedBody);
}
use of org.openqa.grid.web.servlet.handler.WebDriverRequest in project zalenium by zalando.
the class TestingBotRemoteProxyTest method dashboardFilesGetCopied.
@Test
public void dashboardFilesGetCopied() {
try {
// 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);
CommonProxyUtilities proxyUtilities = TestUtils.mockCommonProxyUtilitiesForDashboardTesting(temporaryFolder);
Dashboard.setCommonProxyUtilities(proxyUtilities);
TestInformation testInformation = spyProxy.getTestInformation(mockSeleniumSessionId);
Dashboard.updateDashboard(testInformation);
File videosFolder = new File(temporaryFolder.getRoot().getAbsolutePath(), "videos");
Assert.assertTrue(videosFolder.isDirectory());
File amountOfRunTests = new File(videosFolder, "executedTestsInfo.json");
Assert.assertTrue(amountOfRunTests.exists());
File dashboard = new File(videosFolder, "dashboard.html");
Assert.assertTrue(dashboard.exists());
Assert.assertTrue(dashboard.isFile());
File testList = new File(videosFolder, "list.html");
Assert.assertTrue(testList.exists());
Assert.assertTrue(testList.isFile());
File cssFolder = new File(videosFolder, "css");
Assert.assertTrue(cssFolder.exists());
Assert.assertTrue(cssFolder.isDirectory());
File jsFolder = new File(videosFolder, "js");
Assert.assertTrue(jsFolder.exists());
Assert.assertTrue(jsFolder.isDirectory());
} finally {
Dashboard.restoreCommonProxyUtilities();
}
}
use of org.openqa.grid.web.servlet.handler.WebDriverRequest in project zalenium by zalando.
the class TestUtils method getMockedWebDriverRequestStartSession.
public static WebDriverRequest getMockedWebDriverRequestStartSession(String browser, Platform platform) {
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.START_SESSION);
JsonObject jsonObject = new JsonObject();
JsonObject desiredCapabilities = new JsonObject();
desiredCapabilities.addProperty(CapabilityType.BROWSER_NAME, browser);
desiredCapabilities.addProperty(CapabilityType.PLATFORM_NAME, platform.name());
jsonObject.add("desiredCapabilities", desiredCapabilities);
when(request.getBody()).thenReturn(jsonObject.toString());
Enumeration<String> strings = Collections.emptyEnumeration();
when(request.getHeaderNames()).thenReturn(strings);
return request;
}
use of org.openqa.grid.web.servlet.handler.WebDriverRequest in project zalenium by zalando.
the class CloudTestingRemoteProxy method afterCommand.
@Override
public void afterCommand(TestSession session, HttpServletRequest request, HttpServletResponse response) {
if (request instanceof WebDriverRequest && "DELETE".equalsIgnoreCase(request.getMethod())) {
WebDriverRequest seleniumRequest = (WebDriverRequest) request;
if (seleniumRequest.getRequestType().equals(RequestType.STOP_SESSION)) {
long executionTime = (System.currentTimeMillis() - session.getSlot().getLastSessionStart()) / 1000;
getGa().testEvent(getProxyClassName(), session.getRequestedCapabilities().toString(), executionTime);
addTestToDashboard(session.getExternalKey().getKey(), true);
}
}
super.afterCommand(session, request, response);
}
Aggregations