[英]Running Karate UI tests with “driverTarget” in GitLab CI
Question was: I would like to run Karate UI tests using the driverTarget options to test my Java Play app which is running locally during the same job with sbt run.问题是:我想使用 driverTarget 选项运行空手道 UI 测试,以测试我的 Java Play 应用程序,该应用程序在与 sbt 运行相同的作业期间在本地运行。
I have a simple assertion to check for a property but whenever the tests runs I keep getting "description":"TypeError: Cannot read property 'getAttribute' of null This is my karate-config.js:我有一个简单的断言来检查属性,但是每当测试运行时,我都会不断收到“描述”:“TypeError:无法读取 null 的属性 'getAttribute' 这是我的 karate-config.js:
if (env === 'ci') {
karate.log('using environment:', env);
karate.configure('driverTarget',
{
docker: 'justinribeiro/chrome-headless',
showDriverLog: true
});
}
This is my test scenario:这是我的测试场景:
Scenario: test 1: some test Given driver 'http://localhost:9000'场景:测试 1:一些测试给定驱动程序 'http://localhost:9000'
Is there any workaround for this?有什么解决方法吗? thanks
谢谢
A docker container cannot talk to localhost port as per what was posted: "My guess is that because justinribeiro/chrome-headless is running in its own container, localhost:9000 is different in the container compared to what's running outside of it."根据发布的内容,docker 容器无法与 localhost 端口通信:“我的猜测是,由于 justinribeiro/chrome-headless 在其自己的容器中运行,因此容器中的 localhost:9000 与在其外部运行的内容不同。”
To get around this and have docker container communicate with running app on localhost port use command host.docker.internal为了解决这个问题并让 docker 容器与 localhost 端口上正在运行的应用程序通信,请使用命令host.docker.internal
Change to make:更改为:
From: Given driver 'http://localhost:9000' .来自:给定驱动程序 'http://localhost:9000' 。
To: Given driver 'http://host.docker.internal:9000'致:给定驱动程序'http://host.docker.internal:9000'
Additionally, I was able to use the ptrthomas/karate-chrome image in CI (GITLAB) by inserting the following inside my gitlab-ci.yml file此外,通过在我的 gitlab-ci.yml 文件中插入以下内容,我能够在 CI (GITLAB) 中使用 ptrthomas/karate-chrome 图像
stages:
- uiTest
featureOne:
stage: uiTest
image: docker:latest
cache:
paths:
- .m2/repository/
services:
- docker:dind
script:
- docker run --name karate --rm --cap-add=SYS_ADMIN -v "$PWD":/karate -v
"$HOME"/.m2:/root/.m2 ptrthomas/karate-chrome &
- sleep 45
- docker exec -w /karate karate mvn test -DargLine='-Dkarate.env=docker' Dtest=testParallel
allow_failure: true
artifacts:
paths:
- reports
- ${CLOUD_APP_NAME}.log
my karate-config.js file looks like
if (karate.env == 'docker') {
karate.configure('driver', {
type: 'chrome',
showDriverLog: true,
start: false,
beforeStart: 'supervisorctl start ffmpeg',
afterStop: 'supervisorctl stop ffmpeg',
videoFile: '/tmp/karate.mp4'
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.