seleniumtesting在当地工作,但不在Gitlab CI中
我目前正在开发一个涉及经典后端/前端架构的Java Spring Boot项目。 我正在尝试使用Selenium WebDriver来编写一些基本的集成testing。
问题是我写的testing在我的本地开发机器上没有任何问题,但通过持续集成设置(Gitlab CI)运行时没有通过。
示例testing的代码如下:
@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @ActiveProfiles("test") public class ExampleTest { @LocalServerPort private int port; WebDriver wd; @Test public void successfulLogin(){ String url = "http://localhost:" + port; wd = new HtmlUnitDriver(); wd.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS); wd.get(url); } }
相对的gitlab-ci.yml
部分是:
stages: - test maven-test: image: maven:3.5.0-jdk-8 stage: test script: "mvn test -B -Dmaven.repo.local=/root/.m2/" only: - master
CI有一个单一的runner(版本9.5.0)并发1.它使用docker
执行程序和docker:stable
image。 我不知道是否需要,但它是在priviledged
模式下运行。 在CI环境中运行testing时,它们失败,并显示以下错误:
org.openqa.selenium.TimeoutException: java.net.SocketTimeoutException: Read timed out
我已经尝试使用url = "http://localhost:" + port
和url = InetAddress.getLocalHost().getHostName() + ":" + port
,都通过本地,没有在CI环境中传递。
我究竟做错了什么?
编辑:Alfagemebuild议更准确的testing方法。 在运行configuration项的同一台服务器上,我使用git clone
克隆了我的仓库,然后运行以下命令:
sudo gitlab-runner exec docker maven-test
testing通过没有任何问题。 我真的没有想法,有人有吗?
我不确定为什么,但清除CI机器上的各种runner-XXXXX-project-21-concurrent-0-cache-XXXXXXXXXXXXXXXXXXX
docker容器似乎解决了这个问题。
编辑:这只是暂时解决了这个问题。 问题再次发生,这一次清理cachingvoulmes没有帮助。 任何人有任何build议?