Search in sources :

Example 6 with Environment

use of de.zalando.ep.zalenium.util.Environment 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);
}
Also used : HashMap(java.util.HashMap) ServletOutputStream(javax.servlet.ServletOutputStream) TestSession(org.openqa.grid.internal.TestSession) HttpServletResponse(javax.servlet.http.HttpServletResponse) Environment(de.zalando.ep.zalenium.util.Environment) WebDriverRequest(org.openqa.grid.web.servlet.handler.WebDriverRequest) Test(org.junit.Test)

Example 7 with Environment

use of de.zalando.ep.zalenium.util.Environment 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);
}
Also used : HashMap(java.util.HashMap) ServletOutputStream(javax.servlet.ServletOutputStream) TestSession(org.openqa.grid.internal.TestSession) HttpServletResponse(javax.servlet.http.HttpServletResponse) 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 8 with Environment

use of de.zalando.ep.zalenium.util.Environment 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);
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) CommonProxyUtilities(de.zalando.ep.zalenium.util.CommonProxyUtilities) JMXHelper(org.openqa.selenium.remote.server.jmx.JMXHelper) InstanceNotFoundException(javax.management.InstanceNotFoundException) RegistrationRequest(org.openqa.grid.common.RegistrationRequest) ObjectName(javax.management.ObjectName) Hub(org.openqa.grid.web.Hub) JsonElement(com.google.gson.JsonElement) Environment(de.zalando.ep.zalenium.util.Environment) GridHubConfiguration(org.openqa.grid.internal.utils.configuration.GridHubConfiguration) Before(org.junit.Before)

Example 9 with Environment

use of de.zalando.ep.zalenium.util.Environment 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 Environment

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

the class DockerSeleniumStarterRemoteProxyTest method fallbackToDefaultAmountValuesWhenVariablesAreNotIntegers.

@Test
public void fallbackToDefaultAmountValuesWhenVariablesAreNotIntegers() throws MalformedObjectNameException {
    // Mock the environment class that serves as proxy to retrieve env variables
    Environment environment = mock(Environment.class, withSettings().useConstructor());
    when(environment.getEnvVariable(DockerSeleniumStarterRemoteProxy.ZALENIUM_DESIRED_CONTAINERS)).thenReturn("ABC_NON_INTEGER");
    when(environment.getEnvVariable(DockerSeleniumStarterRemoteProxy.ZALENIUM_MAX_DOCKER_SELENIUM_CONTAINERS)).thenReturn("ABC_NON_INTEGER");
    when(environment.getEnvVariable(DockerSeleniumStarterRemoteProxy.ZALENIUM_SCREEN_HEIGHT)).thenReturn("ABC_NON_INTEGER");
    when(environment.getEnvVariable(DockerSeleniumStarterRemoteProxy.ZALENIUM_SCREEN_WIDTH)).thenReturn("ABC_NON_INTEGER");
    when(environment.getEnvVariable(DockerSeleniumStarterRemoteProxy.ZALENIUM_TZ)).thenReturn("ABC_NON_STANDARD_TIME_ZONE");
    when(environment.getIntEnvVariable(any(String.class), any(Integer.class))).thenCallRealMethod();
    when(environment.getStringEnvVariable(any(String.class), any(String.class))).thenCallRealMethod();
    DockerSeleniumStarterRemoteProxy.setEnv(environment);
    try {
        ObjectName objectName = new ObjectName("org.seleniumhq.grid:type=RemoteProxy,node=\"http://localhost:30000\"");
        new JMXHelper().unregister(objectName);
    } finally {
        DockerSeleniumStarterRemoteProxy.getNewInstance(request, registry);
    }
    Assert.assertEquals(DockerSeleniumStarterRemoteProxy.DEFAULT_AMOUNT_DESIRED_CONTAINERS, DockerSeleniumStarterRemoteProxy.getDesiredContainersOnStartup());
    Assert.assertEquals(DockerSeleniumStarterRemoteProxy.DEFAULT_AMOUNT_DOCKER_SELENIUM_CONTAINERS_RUNNING, DockerSeleniumStarterRemoteProxy.getMaxDockerSeleniumContainers());
    Assert.assertEquals(DockerSeleniumStarterRemoteProxy.DEFAULT_SCREEN_SIZE.getHeight(), DockerSeleniumStarterRemoteProxy.getConfiguredScreenSize().getHeight());
    Assert.assertEquals(DockerSeleniumStarterRemoteProxy.DEFAULT_SCREEN_SIZE.getWidth(), DockerSeleniumStarterRemoteProxy.getConfiguredScreenSize().getWidth());
    Assert.assertEquals(DockerSeleniumStarterRemoteProxy.DEFAULT_TZ.getID(), DockerSeleniumStarterRemoteProxy.getConfiguredTimeZone().getID());
}
Also used : JMXHelper(org.openqa.selenium.remote.server.jmx.JMXHelper) Environment(de.zalando.ep.zalenium.util.Environment) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Aggregations

Environment (de.zalando.ep.zalenium.util.Environment)13 Test (org.junit.Test)11 HashMap (java.util.HashMap)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)6 ObjectName (javax.management.ObjectName)5 TestSession (org.openqa.grid.internal.TestSession)5 WebDriverRequest (org.openqa.grid.web.servlet.handler.WebDriverRequest)5 JMXHelper (org.openqa.selenium.remote.server.jmx.JMXHelper)4 JsonObject (com.google.gson.JsonObject)3 CommonProxyUtilities (de.zalando.ep.zalenium.util.CommonProxyUtilities)3 ServletOutputStream (javax.servlet.ServletOutputStream)3 ExternalSessionKey (org.openqa.grid.internal.ExternalSessionKey)3 JsonElement (com.google.gson.JsonElement)2 Mockito.anyString (org.mockito.Mockito.anyString)2 RegistrationRequest (org.openqa.grid.common.RegistrationRequest)2 ContainerClient (de.zalando.ep.zalenium.container.ContainerClient)1 ContainerClientRegistration (de.zalando.ep.zalenium.container.ContainerClientRegistration)1 ContainerCreationStatus (de.zalando.ep.zalenium.container.ContainerCreationStatus)1 TestInformation (de.zalando.ep.zalenium.dashboard.TestInformation)1 GoogleAnalyticsApi (de.zalando.ep.zalenium.util.GoogleAnalyticsApi)1