Search in sources :

Example 6 with CommonProxyUtilities

use of de.zalando.ep.zalenium.util.CommonProxyUtilities 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();
    }
}
Also used : TestInformation(de.zalando.ep.zalenium.dashboard.TestInformation) ExternalSessionKey(org.openqa.grid.internal.ExternalSessionKey) CommonProxyUtilities(de.zalando.ep.zalenium.util.CommonProxyUtilities) HashMap(java.util.HashMap) TestSession(org.openqa.grid.internal.TestSession) HttpServletResponse(javax.servlet.http.HttpServletResponse) JsonObject(com.google.gson.JsonObject) WebDriverRequest(org.openqa.grid.web.servlet.handler.WebDriverRequest) File(java.io.File) Test(org.junit.Test)

Example 7 with CommonProxyUtilities

use of de.zalando.ep.zalenium.util.CommonProxyUtilities in project zalenium by zalando.

the class DashboardCleanupServletTest method getDoCleanupAll.

@Test
public void getDoCleanupAll() throws IOException {
    try {
        CommonProxyUtilities proxyUtilities = TestUtils.mockCommonProxyUtilitiesForDashboardTesting(temporaryFolder);
        Dashboard.setCommonProxyUtilities(proxyUtilities);
        when(request.getParameter("action")).thenReturn("doCleanupAll");
        dashboardCleanupServlet.doGet(request, response);
        Assert.assertEquals("SUCCESS", response.getOutputStream().toString());
    } finally {
        Dashboard.restoreCommonProxyUtilities();
    }
}
Also used : CommonProxyUtilities(de.zalando.ep.zalenium.util.CommonProxyUtilities) Test(org.junit.Test)

Example 8 with CommonProxyUtilities

use of de.zalando.ep.zalenium.util.CommonProxyUtilities in project zalenium by zalando.

the class DashboardTest method initDashboard.

@Before
public void initDashboard() throws IOException {
    ti.setVideoRecorded(true);
    Dashboard.setExecutedTests(0, 0);
    TestUtils.ensureRequiredInputFilesExist(temporaryFolder);
    CommonProxyUtilities proxyUtilities = TestUtils.mockCommonProxyUtilitiesForDashboardTesting(temporaryFolder);
    Dashboard.setCommonProxyUtilities(proxyUtilities);
}
Also used : CommonProxyUtilities(de.zalando.ep.zalenium.util.CommonProxyUtilities) Before(org.junit.Before)

Example 9 with CommonProxyUtilities

use of de.zalando.ep.zalenium.util.CommonProxyUtilities 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();
    }
}
Also used : TestInformation(de.zalando.ep.zalenium.dashboard.TestInformation) ExternalSessionKey(org.openqa.grid.internal.ExternalSessionKey) CommonProxyUtilities(de.zalando.ep.zalenium.util.CommonProxyUtilities) HashMap(java.util.HashMap) HttpServletResponse(javax.servlet.http.HttpServletResponse) Mockito.anyString(org.mockito.Mockito.anyString) JsonElement(com.google.gson.JsonElement) TestSession(org.openqa.grid.internal.TestSession) Environment(de.zalando.ep.zalenium.util.Environment) JsonObject(com.google.gson.JsonObject) WebDriverRequest(org.openqa.grid.web.servlet.handler.WebDriverRequest) Test(org.junit.Test)

Example 10 with CommonProxyUtilities

use of de.zalando.ep.zalenium.util.CommonProxyUtilities in project zalenium by zalando.

the class SauceLabsRemoteProxyTest method testInformationIsRetrievedWhenStoppingSession.

@Test
public void testInformationIsRetrievedWhenStoppingSession() throws IOException {
    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 sauce labs node
        SauceLabsRemoteProxy sauceLabsSpyProxy = spy(sauceLabsProxy);
        JsonElement informationSample = TestUtils.getTestInformationSample("saucelabs_testinformation.json");
        CommonProxyUtilities commonProxyUtilities = mock(CommonProxyUtilities.class);
        when(commonProxyUtilities.readJSONFromUrl(anyString(), anyString(), anyString())).thenReturn(informationSample);
        doCallRealMethod().when(commonProxyUtilities).convertFlvFileToMP4(any(TestInformation.class));
        SauceLabsRemoteProxy.setCommonProxyUtilities(commonProxyUtilities);
        TestSession testSession = sauceLabsSpyProxy.getNewSession(requestedCapability);
        Assert.assertNotNull(testSession);
        String mockSeleniumSessionId = "72e4f8ecf04440fe965faf657864ed52";
        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();
        sauceLabsSpyProxy.afterCommand(testSession, request, response);
        verify(sauceLabsSpyProxy, timeout(1000 * 5)).getTestInformation(mockSeleniumSessionId);
        TestInformation testInformation = sauceLabsSpyProxy.getTestInformation(mockSeleniumSessionId);
        Assert.assertEquals(mockSeleniumSessionId, testInformation.getTestName());
        Assert.assertThat(testInformation.getFileName(), CoreMatchers.containsString("saucelabs_72e4f8ecf04440fe965faf657864ed52_googlechrome_Windows_2008"));
        Assert.assertEquals("googlechrome 56, Windows 2008", testInformation.getBrowserAndPlatform());
        Assert.assertThat(testInformation.getVideoUrl(), CoreMatchers.containsString("jobs/72e4f8ecf04440fe965faf657864ed52/assets/video.flv"));
    } finally {
        SauceLabsRemoteProxy.restoreCommonProxyUtilities();
    }
}
Also used : TestInformation(de.zalando.ep.zalenium.dashboard.TestInformation) ExternalSessionKey(org.openqa.grid.internal.ExternalSessionKey) CommonProxyUtilities(de.zalando.ep.zalenium.util.CommonProxyUtilities) HashMap(java.util.HashMap) JsonElement(com.google.gson.JsonElement) TestSession(org.openqa.grid.internal.TestSession) HttpServletResponse(javax.servlet.http.HttpServletResponse) WebDriverRequest(org.openqa.grid.web.servlet.handler.WebDriverRequest) Test(org.junit.Test)

Aggregations

CommonProxyUtilities (de.zalando.ep.zalenium.util.CommonProxyUtilities)14 Test (org.junit.Test)9 HttpServletResponse (javax.servlet.http.HttpServletResponse)7 RegistrationRequest (org.openqa.grid.common.RegistrationRequest)7 ObjectName (javax.management.ObjectName)6 TestSession (org.openqa.grid.internal.TestSession)6 WebDriverRequest (org.openqa.grid.web.servlet.handler.WebDriverRequest)6 JMXHelper (org.openqa.selenium.remote.server.jmx.JMXHelper)6 Before (org.junit.Before)5 ExternalSessionKey (org.openqa.grid.internal.ExternalSessionKey)5 InstanceNotFoundException (javax.management.InstanceNotFoundException)4 MalformedObjectNameException (javax.management.MalformedObjectNameException)4 GridHubConfiguration (org.openqa.grid.internal.utils.configuration.GridHubConfiguration)4 Hub (org.openqa.grid.web.Hub)4 JsonElement (com.google.gson.JsonElement)3 TestInformation (de.zalando.ep.zalenium.dashboard.TestInformation)3 Environment (de.zalando.ep.zalenium.util.Environment)3 HashMap (java.util.HashMap)3 JsonObject (com.google.gson.JsonObject)2 BrowserStackRemoteProxy (de.zalando.ep.zalenium.proxy.BrowserStackRemoteProxy)1