title: Selenium tests works in local but not in Gitlab CI
body: <p>I am currently working on a Java Spring Boot project which involves a classic backend/frontend architecture. I am trying to write some basic integration test by using the Selenium WebDriver.</p>
  <p>The problem is that the tests I write pass without any problem on my local development machine but do not pass when I run them thorugh the continuous integration setup (Gitlab CI).</p>
  <p>The code of the example test is the following:</p>
  <pre class="lang-java prettyprint-override"><code>@RunWith(SpringRunner.class)
  @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
  @ActiveProfiles(&quot;test&quot;)
  public class ExampleTest {
      
      @LocalServerPort 
      private int port;
      
      WebDriver wd;
      
      @Test
      public void successfulLogin(){
          String url = &quot;http://localhost:&quot; + port;
          wd = new HtmlUnitDriver();
          wd.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
          wd.get(url);
      }
  }
  </code></pre>
  <p>The relative <code>gitlab-ci.yml</code> portion is:</p>
  <pre><code>stages:
    - test
  
  maven-test:
    image: maven:3.5.0-jdk-8
    stage: test
    script: &quot;mvn test -B -Dmaven.repo.local=/root/.m2/&quot;
    only:
      - master
  </code></pre>
  <p>The CI has a single runner (version 9.5.0) with concurrency 1. It uses the <code>docker</code> executor with the <code>docker:stable</code> image. I don't know if it is needed, but it is running in <code>priviledged</code> mode.
  When running the tests on the CI environment, they fail with the following error:</p>
  <pre><code>org.openqa.selenium.TimeoutException: java.net.SocketTimeoutException: Read timed out
  </code></pre>
  <p>I have tried both with <code>url = &quot;http://localhost:&quot; + port</code> and <code>url =         InetAddress.getLocalHost().getHostName() + &quot;:&quot; + port</code>, both passed locally, none passed in the CI environment.</p>
  <p>What am I doing wrong?</p>
  <hr />
  <p>EDIT: Alfageme suggested a more accurate testing methodology. On the same server on which the CI is running, I cloned my repository with <code>git clone</code> and then run the following command:</p>
  <pre><code>sudo gitlab-runner exec docker maven-test
  </code></pre>
  <p>The test passed without any problem. I am really running out of ideas, does someone have any?</p>