use of de.zalando.ep.zalenium.util.CommonProxyUtilities in project zalenium by zalando.
the class DockerSeleniumRemoteProxyTest method videoRecordingIsStartedAndStopped.
@Test
public void videoRecordingIsStartedAndStopped() throws MalformedObjectNameException, IOException {
try {
// Create a docker-selenium container
RegistrationRequest request = TestUtils.getRegistrationRequestForTesting(30000, DockerSeleniumStarterRemoteProxy.class.getCanonicalName());
DockerSeleniumStarterRemoteProxy dsProxy = new DockerSeleniumStarterRemoteProxy(request, registry);
DockerSeleniumStarterRemoteProxy.setMaxDockerSeleniumContainers(1);
DockerSeleniumStarterRemoteProxy.setConfiguredScreenSize(DockerSeleniumStarterRemoteProxy.DEFAULT_SCREEN_SIZE);
DockerSeleniumStarterRemoteProxy.setContainerClient(containerClient);
dsProxy.getNewSession(getCapabilitySupportedByDockerSelenium());
CommonProxyUtilities commonProxyUtilities = TestUtils.mockCommonProxyUtilitiesForDashboardTesting(temporaryFolder);
TestUtils.ensureRequiredInputFilesExist(temporaryFolder);
Dashboard.setCommonProxyUtilities(commonProxyUtilities);
// Creating a spy proxy to verify the invoked methods
DockerSeleniumRemoteProxy spyProxy = spy(proxy);
// Start pulling thread
spyProxy.startPolling();
// Get a test session
TestSession newSession = spyProxy.getNewSession(getCapabilitySupportedByDockerSelenium());
newSession.setExternalKey(new ExternalSessionKey("DockerSeleniumRemoteProxy Test"));
Assert.assertNotNull(newSession);
// We start the session, in order to start recording
WebDriverRequest webDriverRequest = mock(WebDriverRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
when(webDriverRequest.getMethod()).thenReturn("POST");
when(webDriverRequest.getRequestType()).thenReturn(RequestType.START_SESSION);
spyProxy.afterCommand(newSession, webDriverRequest, response);
// Assert video recording started
String containerId = spyProxy.getContainerId();
verify(spyProxy, times(1)).videoRecording(DockerSeleniumRemoteProxy.DockerSeleniumContainerAction.START_RECORDING);
verify(spyProxy, times(1)).processContainerAction(DockerSeleniumRemoteProxy.DockerSeleniumContainerAction.START_RECORDING, containerId);
// We release the sessions, the node should be free
webDriverRequest = mock(WebDriverRequest.class);
response = mock(HttpServletResponse.class);
when(webDriverRequest.getMethod()).thenReturn("DELETE");
when(webDriverRequest.getRequestType()).thenReturn(RequestType.STOP_SESSION);
newSession.getSlot().doFinishRelease();
spyProxy.afterCommand(newSession, webDriverRequest, response);
spyProxy.afterSession(newSession);
Assert.assertFalse(spyProxy.isBusy());
verify(spyProxy, timeout(40000)).videoRecording(DockerSeleniumRemoteProxy.DockerSeleniumContainerAction.STOP_RECORDING);
verify(spyProxy, timeout(40000)).processContainerAction(DockerSeleniumRemoteProxy.DockerSeleniumContainerAction.STOP_RECORDING, containerId);
verify(spyProxy, timeout(40000)).copyVideos(containerId);
} finally {
ObjectName objectName = new ObjectName("org.seleniumhq.grid:type=RemoteProxy,node=\"http://localhost:30000\"");
new JMXHelper().unregister(objectName);
Dashboard.restoreCommonProxyUtilities();
}
}
use of de.zalando.ep.zalenium.util.CommonProxyUtilities in project zalenium by zalando.
the class DockerSeleniumRemoteProxyTest method videoRecordingIsDisabled.
@Test
public void videoRecordingIsDisabled() throws MalformedObjectNameException, IOException {
try {
// Create a docker-selenium container
RegistrationRequest request = TestUtils.getRegistrationRequestForTesting(30000, DockerSeleniumStarterRemoteProxy.class.getCanonicalName());
DockerSeleniumStarterRemoteProxy dsProxy = new DockerSeleniumStarterRemoteProxy(request, registry);
DockerSeleniumStarterRemoteProxy.setMaxDockerSeleniumContainers(1);
DockerSeleniumStarterRemoteProxy.setConfiguredScreenSize(DockerSeleniumStarterRemoteProxy.DEFAULT_SCREEN_SIZE);
DockerSeleniumStarterRemoteProxy.setConfiguredTimeZone(DockerSeleniumStarterRemoteProxy.DEFAULT_TZ.getID());
DockerSeleniumStarterRemoteProxy.setContainerClient(containerClient);
dsProxy.getNewSession(getCapabilitySupportedByDockerSelenium());
// Mocking the environment variable to return false for video recording enabled
Environment environment = mock(Environment.class);
when(environment.getEnvVariable(DockerSeleniumRemoteProxy.ZALENIUM_VIDEO_RECORDING_ENABLED)).thenReturn("false");
when(environment.getIntEnvVariable(DockerSeleniumRemoteProxy.ZALENIUM_MAX_TEST_SESSIONS, 1)).thenReturn(1);
// Creating a spy proxy to verify the invoked methods
CommonProxyUtilities commonProxyUtilities = TestUtils.mockCommonProxyUtilitiesForDashboardTesting(temporaryFolder);
TestUtils.ensureRequiredInputFilesExist(temporaryFolder);
Dashboard.setCommonProxyUtilities(commonProxyUtilities);
DockerSeleniumRemoteProxy spyProxy = spy(proxy);
DockerSeleniumRemoteProxy.setEnv(environment);
DockerSeleniumRemoteProxy.readEnvVars();
// Start pulling thread
spyProxy.startPolling();
// Get a test session
TestSession newSession = spyProxy.getNewSession(getCapabilitySupportedByDockerSelenium());
newSession.setExternalKey(new ExternalSessionKey("DockerSeleniumRemoteProxy Test"));
Assert.assertNotNull(newSession);
// We start the session, in order to start recording
WebDriverRequest webDriverRequest = mock(WebDriverRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
when(webDriverRequest.getMethod()).thenReturn("POST");
when(webDriverRequest.getRequestType()).thenReturn(RequestType.START_SESSION);
spyProxy.afterCommand(newSession, webDriverRequest, response);
// Assert no video recording was started, videoRecording is invoked but processContainerAction should not
verify(spyProxy, times(1)).videoRecording(DockerSeleniumRemoteProxy.DockerSeleniumContainerAction.START_RECORDING);
verify(spyProxy, never()).processContainerAction(DockerSeleniumRemoteProxy.DockerSeleniumContainerAction.START_RECORDING, "");
// We release the sessions, the node should be free
webDriverRequest = mock(WebDriverRequest.class);
response = mock(HttpServletResponse.class);
when(webDriverRequest.getMethod()).thenReturn("DELETE");
when(webDriverRequest.getRequestType()).thenReturn(RequestType.STOP_SESSION);
newSession.getSlot().doFinishRelease();
spyProxy.afterCommand(newSession, webDriverRequest, response);
spyProxy.afterSession(newSession);
Assert.assertFalse(spyProxy.isBusy());
// Now we assert that videoRecording was invoked but processContainerAction not, neither copyVideos
verify(spyProxy, timeout(40000)).videoRecording(DockerSeleniumRemoteProxy.DockerSeleniumContainerAction.STOP_RECORDING);
verify(spyProxy, never()).processContainerAction(DockerSeleniumRemoteProxy.DockerSeleniumContainerAction.STOP_RECORDING, "");
verify(spyProxy, never()).copyVideos("");
} finally {
DockerSeleniumRemoteProxy.restoreEnvironment();
Dashboard.restoreCommonProxyUtilities();
ObjectName objectName = new ObjectName("org.seleniumhq.grid:type=RemoteProxy,node=\"http://localhost:30000\"");
new JMXHelper().unregister(objectName);
}
}
use of de.zalando.ep.zalenium.util.CommonProxyUtilities in project zalenium by zalando.
the class DockerSeleniumRemoteProxyTest method pollingThreadTearsDownNodeAfterTestIsCompleted.
@Test
public void pollingThreadTearsDownNodeAfterTestIsCompleted() throws IOException {
try {
CommonProxyUtilities commonProxyUtilities = TestUtils.mockCommonProxyUtilitiesForDashboardTesting(temporaryFolder);
TestUtils.ensureRequiredInputFilesExist(temporaryFolder);
Dashboard.setCommonProxyUtilities(commonProxyUtilities);
// 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("DELETE");
when(request.getRequestType()).thenReturn(RequestType.STOP_SESSION);
newSession.getSlot().doFinishRelease();
proxy.afterCommand(newSession, request, response);
proxy.afterSession(newSession);
// After running one test, the node shouldn't be busy and also down
Assert.assertFalse(proxy.isBusy());
Callable<Boolean> callable = () -> registry.getProxyById(proxy.getId()) == null;
await().pollInterval(Duration.FIVE_HUNDRED_MILLISECONDS).atMost(Duration.TWO_SECONDS).until(callable);
} finally {
Dashboard.restoreCommonProxyUtilities();
}
}
use of de.zalando.ep.zalenium.util.CommonProxyUtilities in project zalenium by zalando.
the class SauceLabsRemoteProxyTest method setUp.
@Before
public void setUp() {
try {
ObjectName objectName = new ObjectName("org.seleniumhq.grid:type=Hub");
ManagementFactory.getPlatformMBeanServer().getObjectInstance(objectName);
new JMXHelper().unregister(objectName);
} catch (MalformedObjectNameException | InstanceNotFoundException e) {
// Might be that the object does not exist, it is ok. Nothing to do, this is just a cleanup task.
}
registry = ZaleniumRegistry.newInstance(new Hub(new GridHubConfiguration()));
// Creating the configuration and the registration request of the proxy (node)
RegistrationRequest request = TestUtils.getRegistrationRequestForTesting(30001, SauceLabsRemoteProxy.class.getCanonicalName());
CommonProxyUtilities commonProxyUtilities = mock(CommonProxyUtilities.class);
when(commonProxyUtilities.readJSONFromUrl(anyString(), anyString(), anyString())).thenReturn(null);
SauceLabsRemoteProxy.setCommonProxyUtilities(commonProxyUtilities);
sauceLabsProxy = SauceLabsRemoteProxy.getNewInstance(request, registry);
// we need to register a DockerSeleniumStarter proxy to have a proper functioning SauceLabsProxy
request = TestUtils.getRegistrationRequestForTesting(30000, DockerSeleniumStarterRemoteProxy.class.getCanonicalName());
DockerSeleniumStarterRemoteProxy dsStarterProxy = DockerSeleniumStarterRemoteProxy.getNewInstance(request, registry);
// We add both nodes to the registry
registry.add(sauceLabsProxy);
registry.add(dsStarterProxy);
}
use of de.zalando.ep.zalenium.util.CommonProxyUtilities in project zalenium by zalando.
the class TestingBotRemoteProxyTest method setUp.
@SuppressWarnings("ConstantConditions")
@Before
public void setUp() throws IOException {
try {
ObjectName objectName = new ObjectName("org.seleniumhq.grid:type=Hub");
ManagementFactory.getPlatformMBeanServer().getObjectInstance(objectName);
new JMXHelper().unregister(objectName);
} catch (MalformedObjectNameException | InstanceNotFoundException e) {
// Might be that the object does not exist, it is ok. Nothing to do, this is just a cleanup task.
}
registry = ZaleniumRegistry.newInstance(new Hub(new GridHubConfiguration()));
// Creating the configuration and the registration request of the proxy (node)
RegistrationRequest request = TestUtils.getRegistrationRequestForTesting(30002, TestingBotRemoteProxy.class.getCanonicalName());
JsonElement informationSample = TestUtils.getTestInformationSample("testingbot_testinformation.json");
String userInfoUrl = "https://api.testingbot.com/v1/user";
Environment env = new Environment();
CommonProxyUtilities commonProxyUtilities = mock(CommonProxyUtilities.class);
when(commonProxyUtilities.readJSONFromUrl(userInfoUrl, env.getStringEnvVariable("TESTINGBOT_KEY", ""), env.getStringEnvVariable("TESTINGBOT_SECRET", ""))).thenReturn(null);
String mockTestInfoUrl = "https://api.testingbot.com/v1/tests/2cf5d115-ca6f-4bc4-bc06-a4fca00836ce";
when(commonProxyUtilities.readJSONFromUrl(mockTestInfoUrl, env.getStringEnvVariable("TESTINGBOT_KEY", ""), env.getStringEnvVariable("TESTINGBOT_SECRET", ""))).thenReturn(informationSample);
TestingBotRemoteProxy.setCommonProxyUtilities(commonProxyUtilities);
testingBotProxy = TestingBotRemoteProxy.getNewInstance(request, registry);
// we need to register a DockerSeleniumStarter proxy to have a proper functioning testingBotProxy
request = TestUtils.getRegistrationRequestForTesting(30000, DockerSeleniumStarterRemoteProxy.class.getCanonicalName());
DockerSeleniumStarterRemoteProxy dsStarterProxy = DockerSeleniumStarterRemoteProxy.getNewInstance(request, registry);
// Temporal folder for dashboard files
TestUtils.ensureRequiredInputFilesExist(temporaryFolder);
// We add both nodes to the registry
registry.add(testingBotProxy);
registry.add(dsStarterProxy);
}
Aggregations