Search in sources :

Example 16 with TestSession

use of org.openqa.grid.internal.TestSession in project zalenium by zalando.

the class SauceLabsRemoteProxyTest method doesNotCreateSessionWhenDockerSeleniumCanProcessRequest.

@Test
public void doesNotCreateSessionWhenDockerSeleniumCanProcessRequest() {
    // This capability is supported by docker-selenium, so it should return a null session
    Map<String, Object> requestedCapability = new HashMap<>();
    requestedCapability.put(CapabilityType.BROWSER_NAME, BrowserType.CHROME);
    requestedCapability.put(CapabilityType.PLATFORM_NAME, Platform.LINUX);
    TestSession testSession = sauceLabsProxy.getNewSession(requestedCapability);
    Assert.assertNull(testSession);
}
Also used : HashMap(java.util.HashMap) TestSession(org.openqa.grid.internal.TestSession) Test(org.junit.Test)

Example 17 with TestSession

use of org.openqa.grid.internal.TestSession 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 18 with TestSession

use of org.openqa.grid.internal.TestSession in project zalenium by zalando.

the class SauceLabsRemoteProxyTest 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.EDGE);
    requestedCapability.put(CapabilityType.PLATFORM_NAME, Platform.WIN10);
    TestSession testSession = sauceLabsProxy.getNewSession(requestedCapability);
    Assert.assertNotNull(testSession);
}
Also used : HashMap(java.util.HashMap) TestSession(org.openqa.grid.internal.TestSession) Test(org.junit.Test)

Example 19 with TestSession

use of org.openqa.grid.internal.TestSession 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 20 with TestSession

use of org.openqa.grid.internal.TestSession in project zalenium by zalando.

the class TestingBotRemoteProxyTest 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.IE);
    requestedCapability.put(CapabilityType.PLATFORM_NAME, Platform.WIN8);
    TestSession testSession = testingBotProxy.getNewSession(requestedCapability);
    Assert.assertNotNull(testSession);
}
Also used : HashMap(java.util.HashMap) TestSession(org.openqa.grid.internal.TestSession) JsonObject(com.google.gson.JsonObject) Test(org.junit.Test)

Aggregations

TestSession (org.openqa.grid.internal.TestSession)49 Test (org.junit.Test)43 HashMap (java.util.HashMap)32 HttpServletResponse (javax.servlet.http.HttpServletResponse)17 WebDriverRequest (org.openqa.grid.web.servlet.handler.WebDriverRequest)17 ExternalSessionKey (org.openqa.grid.internal.ExternalSessionKey)11 JsonObject (com.google.gson.JsonObject)9 CommonProxyUtilities (de.zalando.ep.zalenium.util.CommonProxyUtilities)6 Environment (de.zalando.ep.zalenium.util.Environment)6 ServletOutputStream (javax.servlet.ServletOutputStream)6 TestInformation (de.zalando.ep.zalenium.dashboard.TestInformation)4 Mockito.anyString (org.mockito.Mockito.anyString)4 Dimension (org.openqa.selenium.Dimension)4 RegistrationRequest (org.openqa.grid.common.RegistrationRequest)3 JsonElement (com.google.gson.JsonElement)2 DockerSeleniumRemoteProxy (de.zalando.ep.zalenium.proxy.DockerSeleniumRemoteProxy)2 ProcessedCapabilities (de.zalando.ep.zalenium.util.ProcessedCapabilities)2 TimeZone (java.util.TimeZone)2 ObjectName (javax.management.ObjectName)2 JMXHelper (org.openqa.selenium.remote.server.jmx.JMXHelper)2