Skip to content
This repository was archived by the owner on Sep 21, 2021. It is now read-only.

Commit

Permalink
Avoiding port mapping, this should not be needed anymore. (#363)
Browse files Browse the repository at this point in the history
* Avoiding port mapping, this should not be needed anymore.

* Mocking files and checking that dashboard addition is done

* Initialising registry properly for tests
  • Loading branch information
diemol authored Dec 16, 2017
1 parent fd6a51f commit 3a04fa7
Show file tree
Hide file tree
Showing 17 changed files with 230 additions and 57 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ jobs:
- env: step=minikube
script:
- docker pull elgalu/selenium
- kubernetes/minikube-ci-initialize.sh
- travis_retry ./kubernetes/minikube-ci-initialize.sh
- mvn clean package -Pbuild-docker-image -DskipTests=true
- cd target && docker build -t dosel/zalenium:minikube . && cd ..
- kubernetes/start-zalenium-in-minikube.sh
- ./kubernetes/start-zalenium-in-minikube.sh
- ./run_integration_tests.sh minikube

- stage: Push Image (only with a tag)
Expand Down
8 changes: 4 additions & 4 deletions run_integration_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ else
# If the environment var exists, then we run the integration tests. This is to allow external PRs ro tun
if [ "$INTEGRATION_TO_TEST" = sauceLabs ]; then
if [ -n "${SAUCE_USERNAME}" ]; then
sudo mvn clean
sudo env "PATH=$PATH" mvn clean
mvn clean verify -Pintegration-test -DthreadCountProperty=2 -Dskip.surefire.tests=true -DintegrationToTest=${INTEGRATION_TO_TEST}
# Check for generated videos
ls -la ${VIDEOS_FOLDER}/saucelabs*.mp4 || (echo "No Sauce Labs videos were downloaded." && exit 2)
Expand All @@ -23,7 +23,7 @@ else
fi
if [ "$INTEGRATION_TO_TEST" = browserStack ]; then
if [ -n "${BROWSER_STACK_USER}" ]; then
sudo mvn clean
sudo env "PATH=$PATH" mvn clean
mvn clean package -Pbuild-docker-image -DskipTests=true
mkdir -p "${VIDEOS_FOLDER}"
cd target && docker build -t dosel/zalenium:latest . && cd ..
Expand All @@ -38,7 +38,7 @@ else
fi
if [ "$INTEGRATION_TO_TEST" = testingBot ]; then
if [ -n "${TESTINGBOT_KEY}" ]; then
sudo mvn clean
sudo env "PATH=$PATH" mvn clean
mvn clean verify -Pintegration-test -DthreadCountProperty=2 -Dskip.surefire.tests=true -DintegrationToTest=${INTEGRATION_TO_TEST}
# Check for generated videos
ls -la ${VIDEOS_FOLDER}/testingbot*.mp4 || (echo "No TestingBot videos were downloaded." && exit 2)
Expand All @@ -47,7 +47,7 @@ else
fi
if [ "$INTEGRATION_TO_TEST" = dockerCompose ]; then
if [ -n "${SAUCE_USERNAME}" ]; then
sudo mvn clean
sudo env "PATH=$PATH" mvn clean
mvn clean package -Pbuild-docker-image -DskipTests=true
mkdir -p "${VIDEOS_FOLDER}"
chmod +x target/zalenium_in_docker_compose.sh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,6 @@ public ContainerCreationStatus createContainer(String zaleniumContainerName, Str

String noVncPort = envVars.get("NOVNC_PORT");

final Map<String, List<PortBinding>> portBindings = new HashMap<>();
List<PortBinding> portBindingList = new ArrayList<>();
portBindingList.add(PortBinding.of("", nodePort));
portBindings.put(nodePort, portBindingList);
portBindingList = new ArrayList<>();
portBindingList.add(PortBinding.of("", noVncPort));
portBindings.put(noVncPort, portBindingList);

String networkMode = getZaleniumNetwork(zaleniumContainerName);

List<String> extraHosts = new ArrayList<>();
Expand All @@ -215,7 +207,6 @@ public ContainerCreationStatus createContainer(String zaleniumContainerName, Str

HostConfig hostConfig = HostConfig.builder()
.appendBinds(binds)
.portBindings(portBindings)
.networkMode(networkMode)
.extraHosts(extraHosts)
.autoRemove(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ public static void restoreCommonProxyUtilities() {
commonProxyUtilities = new CommonProxyUtilities();
}

@VisibleForTesting
public static void setCommonProxyUtilities(CommonProxyUtilities commonProxyUtilities) {
Dashboard.commonProxyUtilities = commonProxyUtilities;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public class CloudTestingRemoteProxy extends DefaultRemoteProxy {

@VisibleForTesting
public static final long DEFAULT_MAX_TEST_IDLE_TIME_SECS = 90L;
@VisibleForTesting
public static boolean addToDashboardCalled = false;
private static final Logger logger = Logger.getLogger(CloudTestingRemoteProxy.class.getName());
private static final GoogleAnalyticsApi defaultGA = new GoogleAnalyticsApi();
private static final CommonProxyUtilities defaultCommonProxyUtilities = new CommonProxyUtilities();
Expand Down Expand Up @@ -228,6 +230,7 @@ public boolean convertVideoFileToMP4() {
}

public void addTestToDashboard(String seleniumSessionId, boolean testCompleted) {
addToDashboardCalled = false;
new Thread(() -> {
try {
TestInformation testInformation = getTestInformation(seleniumSessionId);
Expand All @@ -248,6 +251,7 @@ public void addTestToDashboard(String seleniumSessionId, boolean testCompleted)
}
createFeatureNotImplementedFile(testInformation.getLogsFolderPath());
Dashboard.updateDashboard(testInformation);
addToDashboardCalled = true;
} catch (Exception e) {
logger.log(Level.SEVERE, e.toString(), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -100,8 +101,8 @@ private String tabBrowsers() {
slotTitle = testSlot.getCapabilities().toString();
}
Map<String, String> browserValues = new HashMap<>();
browserValues.put("{{browserVersion}}", version);
browserValues.put("{{slotIcon}}", icon);
browserValues.put("{{browserVersion}}", Optional.ofNullable(version).orElse("N/A"));
browserValues.put("{{slotIcon}}", Optional.ofNullable(icon).orElse("N/A"));
browserValues.put("{{slotClass}}", slotClass);
browserValues.put("{{slotTitle}}", slotTitle);
browserSection.append(templateRenderer.renderSection("{{tabBrowsers}}", browserValues));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,75 @@

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import de.zalando.ep.zalenium.dashboard.Dashboard;
import de.zalando.ep.zalenium.registry.ZaleniumRegistry;
import de.zalando.ep.zalenium.util.CommonProxyUtilities;
import de.zalando.ep.zalenium.util.Environment;
import de.zalando.ep.zalenium.util.TestUtils;
import de.zalando.ep.zalenium.dashboard.TestInformation;
import org.awaitility.Duration;
import org.hamcrest.CoreMatchers;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.openqa.grid.common.RegistrationRequest;
import org.openqa.grid.internal.ExternalSessionKey;
import org.openqa.grid.internal.GridRegistry;
import org.openqa.grid.internal.RemoteProxy;
import org.openqa.grid.internal.TestSession;
import org.openqa.grid.internal.utils.configuration.GridHubConfiguration;
import org.openqa.grid.web.Hub;
import org.openqa.grid.web.servlet.handler.RequestType;
import org.openqa.grid.web.servlet.handler.WebDriverRequest;
import org.openqa.selenium.Platform;
import org.openqa.selenium.remote.BrowserType;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.server.jmx.JMXHelper;

import javax.management.InstanceNotFoundException;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.timeout;
import static org.awaitility.Awaitility.await;

public class BrowserStackRemoteProxyTest {

private BrowserStackRemoteProxy browserStackProxy;
private GridRegistry registry;

@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();

@SuppressWarnings("ConstantConditions")
@Before
public void setUp() {
registry = ZaleniumRegistry.newInstance();
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,
BrowserStackRemoteProxy.class.getCanonicalName());
Expand Down Expand Up @@ -142,13 +162,15 @@ public void testInformationIsRetrievedWhenStoppingSession() throws IOException {
requestedCapability.put(CapabilityType.PLATFORM, Platform.WIN10);

JsonElement informationSample = TestUtils.getTestInformationSample("browserstack_testinformation.json");
CommonProxyUtilities commonProxyUtilities = mock(CommonProxyUtilities.class);
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);
Expand All @@ -166,6 +188,8 @@ public void testInformationIsRetrievedWhenStoppingSession() throws IOException {
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(),
Expand All @@ -181,6 +205,7 @@ public void testInformationIsRetrievedWhenStoppingSession() throws IOException {
BrowserStackRemoteProxy.restoreCommonProxyUtilities();
BrowserStackRemoteProxy.restoreGa();
BrowserStackRemoteProxy.restoreEnvironment();
Dashboard.restoreCommonProxyUtilities();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,28 @@
import org.junit.Test;
import org.openqa.grid.common.RegistrationRequest;
import org.openqa.grid.internal.GridRegistry;
import org.openqa.grid.internal.utils.configuration.GridHubConfiguration;
import org.openqa.grid.web.Hub;
import org.openqa.selenium.remote.server.jmx.JMXHelper;
import org.testng.Assert;

import javax.management.InstanceNotFoundException;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import java.lang.management.ManagementFactory;

public class CloudTestingRemoteProxyTest {

@Test
public void defaultValuesAreAlwaysNull() {
GridRegistry registry = ZaleniumRegistry.newInstance();
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.
}
GridRegistry registry = ZaleniumRegistry.newInstance(new Hub(new GridHubConfiguration()));
RegistrationRequest request = TestUtils.getRegistrationRequestForTesting(30003,
CloudTestingRemoteProxy.class.getCanonicalName());
CloudTestingRemoteProxy proxy = CloudTestingRemoteProxy.getNewInstance(request, registry);
Expand Down
Loading

0 comments on commit 3a04fa7

Please # to comment.