use of org.openqa.grid.internal.TestSession 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.internal.TestSession in project zalenium by zalando.
the class ZaleniumRegistryTest method sessionIsProcessed.
@Test
public void sessionIsProcessed() {
Map<String, Object> requestedCapability = new HashMap<>();
requestedCapability.put(CapabilityType.BROWSER_NAME, BrowserType.CHROME);
requestedCapability.put(CapabilityType.PLATFORM_NAME, Platform.LINUX);
GridRegistry registry = ZaleniumRegistry.newInstance(new Hub(new GridHubConfiguration()));
RegistrationRequest req = TestUtils.getRegistrationRequestForTesting(40000, DockerSeleniumRemoteProxy.class.getCanonicalName());
req.getConfiguration().capabilities.clear();
req.getConfiguration().capabilities.addAll(TestUtils.getDockerSeleniumCapabilitiesForTesting());
DockerSeleniumRemoteProxy p1 = new DockerSeleniumRemoteProxy(req, registry);
try {
registry.add(p1);
RequestHandler newSessionRequest = TestUtils.createNewSessionHandler(registry, requestedCapability);
newSessionRequest.process();
TestSession session = newSessionRequest.getSession();
session.setExternalKey(new ExternalSessionKey(UUID.randomUUID().toString()));
registry.terminate(session, SessionTerminationReason.CLIENT_STOPPED_SESSION);
Callable<Boolean> callable = () -> registry.getActiveSessions().size() == 0;
await().pollInterval(Duration.FIVE_HUNDRED_MILLISECONDS).atMost(Duration.TWO_SECONDS).until(callable);
} finally {
registry.stop();
}
}
use of org.openqa.grid.internal.TestSession in project zalenium by zalando.
the class DockerSeleniumRemoteProxy method getNewSession.
/*
Incrementing the number of tests that will be executed when the session is assigned.
*/
@Override
public TestSession getNewSession(Map<String, Object> requestedCapability) {
/*
Validate first if the capability is matched
*/
if (!hasCapability(requestedCapability)) {
return null;
}
if (!requestedCapability.containsKey(CapabilityType.BROWSER_NAME)) {
LOGGER.debug(String.format("%s Capability %s does not contain %s key, a browser test cannot " + "start without it.", getId(), requestedCapability, CapabilityType.BROWSER_NAME));
return null;
}
if (!this.isBusy() && increaseCounter()) {
TestSession newSession = super.getNewSession(requestedCapability);
LOGGER.debug(getId() + " Creating session for: " + requestedCapability.toString());
String browserName = requestedCapability.get(CapabilityType.BROWSER_NAME).toString();
testName = getCapability(requestedCapability, ZaleniumCapabilityType.TEST_NAME, "");
if (testName.isEmpty()) {
testName = newSession.getExternalKey() != null ? newSession.getExternalKey().getKey() : newSession.getInternalKey();
}
testBuild = getCapability(requestedCapability, ZaleniumCapabilityType.BUILD_NAME, "");
if (requestedCapability.containsKey(ZaleniumCapabilityType.RECORD_VIDEO)) {
boolean videoRecording = Boolean.parseBoolean(getCapability(requestedCapability, ZaleniumCapabilityType.RECORD_VIDEO, "true"));
setVideoRecordingEnabledSession(videoRecording);
}
String screenResolution = getCapability(newSession.getSlot().getCapabilities(), ZaleniumCapabilityType.SCREEN_RESOLUTION, "N/A");
String browserVersion = getCapability(newSession.getSlot().getCapabilities(), CapabilityType.VERSION, "");
String timeZone = getCapability(newSession.getSlot().getCapabilities(), ZaleniumCapabilityType.TIME_ZONE, "N/A");
testInformation = new TestInformation.TestInformationBuilder().withTestName(testName).withSeleniumSessionId(testName).withProxyName("Zalenium").withBrowser(browserName).withBrowserVersion(browserVersion).withPlatform(Platform.LINUX.name()).withScreenDimension(screenResolution).withTimeZone(timeZone).withBuild(testBuild).withTestStatus(TestInformation.TestStatus.COMPLETED).build();
testInformation.setVideoRecorded(isVideoRecordingEnabled());
maxTestIdleTimeSecs = getConfiguredIdleTimeout(requestedCapability);
return newSession;
}
LOGGER.debug(String.format("%s No more sessions allowed", getId()));
return null;
}
use of org.openqa.grid.internal.TestSession in project zalenium by zalando.
the class BrowserStackRemoteProxyTest method sessionIsCreatedWithCapabilitiesThatDockerSeleniumCannotProcess.
@Test
public void sessionIsCreatedWithCapabilitiesThatDockerSeleniumCannotProcess() {
// 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);
Assert.assertEquals(0, browserStackProxy.getNumberOfSessions());
TestSession testSession = browserStackProxy.getNewSession(requestedCapability);
Assert.assertNotNull(testSession);
Assert.assertEquals(1, browserStackProxy.getNumberOfSessions());
}
use of org.openqa.grid.internal.TestSession 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();
}
}
Aggregations