如何在Gitlab CI管道上运行扑动积分测试?
我正在从事一个扑朔迷离的项目,需要在Gitlab CI管道上运行集成测试。
测试在本地效果很好,启动chromedriver -port = 4444
,然后flutter drive -driver = intemptration_test/test_driver/intermation_test.dart.dart -target = intempration_test_test/intermation/intermation/app_test.dart.dart.dart 。
但是,我不能让他们在CI中跑步。我的yaml文件看起来像这样:(
...
test_ui_integration:
needs:
- build_deploy_user_service
- populate_db
tags:
- docker
stage: test_ui_integration
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
when: always
before_script:
- chromedriver --port=4444 & # launching the chromedriver
- sleep 10
script:
- cd $CI_PROJECT_DIR/ui
- npm ${NODE_INSTALL_OPTIONS:-i}
- npm run build
- flutter drive --driver=integration_test/test_driver/integration_test.dart --target=integration_test/integration/app_test.dart -d chrome --web-run-headless --headless
# - flutter drive --driver=integration_test/test_driver/integration_test.dart --target=integration_test/integration/app_test.dart -d web-server --headless
# - flutter drive --driver=integration_test/test_driver/integration_test.dart --target=integration_test/integration/app_test.dart -d web-server --release --web-run-headless --headless
timeout: 40 minutes
请注意,管道使用了带有Chromedriver和Flutter的Docker IMG)
我已经尝试了各种不同的旗帜,,如这里所示。但是,似乎都没有用:即使在本地,我也无法使测试无头(没有浏览器)进行运行。
CI步骤通常会粘在这样的事情上,直到出来为止:
=== running with flags -d web-server --web-run-headless --headless ===
Waiting for connection from debug service on Web Server... 37.1s
integration_test/integration/app_test.dart is being served at http://localhost:44415
The web-server device requires the Dart Debug Chrome extension for debugging. Consider using the Chrome or Edge devices for an improved development workflow.
...
=== running with flags -d chrome --web-run-headless --headless ===
Waiting for connection from debug service on Chrome... 37.5s
[CHROME]:[1391:1391:0609/090100.591700:ERROR:zygote_host_impl_linux.cc(90)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
Failed to launch browser after 3 tries. Command used to launch it: google-chrome --user-data-dir=/tmp/flutter_tools.RDVJEL/flutter_tools_chrome_device.KRPHNF --remote-debugging-port=41647 --disable-background-timer-throttling --disable-extensions --disable-popup-blocking --bwsi --no-first-run --no-default-browser-check --disable-default-apps --disable-translate http://localhost:35691
我还注意到您可以使用flutter Run路径/to/my/test/dart
在本地运行集成测试,官方文档从未提及的东西。两者之间有区别吗?
我应该尝试使用移动模拟器运行CI测试吗?
任何帮助非常感谢!
编辑:按照 @MarkoSth09的要求,这是Dockerfile和相关的CI工作流程:
FROM fedora:35
# Add basic tools
RUN dnf -y install git make gcc gcc-c++ wget unzip zip jq diffutils \
&& dnf clean all
# Requirement of openapi generator
RUN dnf install -y java \
&& dnf clean all
# Install python
RUN dnf install -y python3 \
&& dnf clean all
# Install chromedriver
RUN wget https://chromedriver.storage.googleapis.com/99.0.4844.35/chromedriver_linux64.zip \
&& unzip chromedriver_linux64.zip \
&& cp chromedriver /usr/bin/chromedriver \
&& chown root /usr/bin/chromedriver \
&& chmod +x /usr/bin/chromedriver \
&& chmod 755 /usr/bin/chromedriver
# Install chrome
RUN wget https://dl.google.com/linux/chrome/rpm/stable/x86_64/google-chrome-stable-99.0.4844.84-1.x86_64.rpm \
&& yum install ./google-chrome-*.rpm -y
# Install AWS CLI V2
RUN curl -s https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip > awscliv2.zip \
&& unzip awscliv2.zip \
&& ./aws/install \
&& rm -rf aws awscliv2.zip
# Install and configure nvm for npm
# nvm environment variables
ENV NVM_DIR /opt/nvm
RUN mkdir -p $NVM_DIR
ENV NODE_VERSION 16.14.0
# install nvm
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
# install node and npm
RUN source $NVM_DIR/nvm.sh \
&& nvm install $NODE_VERSION \
&& nvm alias default $NODE_VERSION \
&& nvm use default
# add node and npm to path so the commands are available
ENV NODE_PATH $NVM_DIR/versions/node/v$NODE_VERSION/lib/node_modules
ENV NVM_BIN $NVM_DIR/versions/node/v$NODE_VERSION/bin
ENV NVM_INC $NVM_DIR/versions/node/v$NODE_VERSION/include/node
ENV PATH $NVM_BIN:$PATH
# Install serverless
RUN npm install -g [email protected]
# Install Flutter
RUN curl -s https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_3.0.0-stable.tar.xz > flutter.tar.xz \
&& tar xf flutter.tar.xz -C /opt/ \
&& rm flutter.tar.xz
ENV PATH $PATH:/opt/flutter/bin
RUN git config --global --add safe.directory /opt/flutter
CMD [ "/bin/bash" ]
ENTRYPOINT [ "/bin/bash", "-c" ]
include:
- '/ci/ci-build-deploy.yml'
- '/ci/ci-tests.yml'
- '/ci/ci-undeploy.yml'
image: registry.gitlab.com/project/project/build/project-build-env:4
variables:
PROJECT_API_URL: https://gitlab.com/api/v4/projects/12345678
NODE_INSTALL_OPTIONS: ci --cache $CI_PROJECT_DIR/.npm --prefer-offline
cache:
key: PROJECT_NODE_CACHE
paths:
- .npm/
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
variables:
AWS_STAGE: "ci${CI_PIPELINE_ID}"
STAGE_TYPE: "ci"
- if: $STAGE_TYPE == "staging" && $AWS_STAGE == "staging"
variables:
HOSTED_ZONE_NAME: "staging.project.io"
FRONT_DOMAIN: "staging.project.io"
- if: $STAGE_TYPE == "prod" && $AWS_STAGE == "prod"
variables:
HOSTED_ZONE_NAME: "project.io"
FRONT_DOMAIN: "project.io"
- when: always
stages:
- build_deploy_user_service
- build_deploy_shop_service
- build_deploy_brand_service
- build_deploy_product_service
- build_deploy_web_ui
- build_deploy_reverseproxy
- test_shop_ws
- test_brand_ws
- test_product_ws
- delete_test_objects
- populate_db
- test_ui
- populate_cognito_test_user
- test_ui_integration
- triggerundeploy
- undeploy
I'm working on a Flutter project and need to run integration tests on a Gitlab CI pipeline.
The tests work fine locally, launching chromedriver -port=4444
and then flutter drive --driver=integration_test/test_driver/integration_test.dart --target=integration_test/integration/app_test.dart
.
However, I cannot get them to run in CI. My yaml file looks like this :
...
test_ui_integration:
needs:
- build_deploy_user_service
- populate_db
tags:
- docker
stage: test_ui_integration
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
when: always
before_script:
- chromedriver --port=4444 & # launching the chromedriver
- sleep 10
script:
- cd $CI_PROJECT_DIR/ui
- npm ${NODE_INSTALL_OPTIONS:-i}
- npm run build
- flutter drive --driver=integration_test/test_driver/integration_test.dart --target=integration_test/integration/app_test.dart -d chrome --web-run-headless --headless
# - flutter drive --driver=integration_test/test_driver/integration_test.dart --target=integration_test/integration/app_test.dart -d web-server --headless
# - flutter drive --driver=integration_test/test_driver/integration_test.dart --target=integration_test/integration/app_test.dart -d web-server --release --web-run-headless --headless
timeout: 40 minutes
(note that the pipeline is using a docker img with chromedriver and Flutter installed)
I have tried all kinds of different combination for the flags, as seen here too. However, none of it seems to work: Even locally, I cannot get the test to run headless-ly (without a browser).
The CI step usually gets stuck on something like this, until it times out :
=== running with flags -d web-server --web-run-headless --headless ===
Waiting for connection from debug service on Web Server... 37.1s
integration_test/integration/app_test.dart is being served at http://localhost:44415
The web-server device requires the Dart Debug Chrome extension for debugging. Consider using the Chrome or Edge devices for an improved development workflow.
...
=== running with flags -d chrome --web-run-headless --headless ===
Waiting for connection from debug service on Chrome... 37.5s
[CHROME]:[1391:1391:0609/090100.591700:ERROR:zygote_host_impl_linux.cc(90)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
Failed to launch browser after 3 tries. Command used to launch it: google-chrome --user-data-dir=/tmp/flutter_tools.RDVJEL/flutter_tools_chrome_device.KRPHNF --remote-debugging-port=41647 --disable-background-timer-throttling --disable-extensions --disable-popup-blocking --bwsi --no-first-run --no-default-browser-check --disable-default-apps --disable-translate http://localhost:35691
I've also noticed that you can run integration tests locally with flutter run path/to/my/test/dart
, which is something that the official docs never mention. Is there a difference between the two?
Should I be trying to run the CI tests with a mobile emulator instead?
Any help much appreciated!
EDIT: As requested by @MarkosTh09, here is the dockerfile and relevant CI workflow :
FROM fedora:35
# Add basic tools
RUN dnf -y install git make gcc gcc-c++ wget unzip zip jq diffutils \
&& dnf clean all
# Requirement of openapi generator
RUN dnf install -y java \
&& dnf clean all
# Install python
RUN dnf install -y python3 \
&& dnf clean all
# Install chromedriver
RUN wget https://chromedriver.storage.googleapis.com/99.0.4844.35/chromedriver_linux64.zip \
&& unzip chromedriver_linux64.zip \
&& cp chromedriver /usr/bin/chromedriver \
&& chown root /usr/bin/chromedriver \
&& chmod +x /usr/bin/chromedriver \
&& chmod 755 /usr/bin/chromedriver
# Install chrome
RUN wget https://dl.google.com/linux/chrome/rpm/stable/x86_64/google-chrome-stable-99.0.4844.84-1.x86_64.rpm \
&& yum install ./google-chrome-*.rpm -y
# Install AWS CLI V2
RUN curl -s https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip > awscliv2.zip \
&& unzip awscliv2.zip \
&& ./aws/install \
&& rm -rf aws awscliv2.zip
# Install and configure nvm for npm
# nvm environment variables
ENV NVM_DIR /opt/nvm
RUN mkdir -p $NVM_DIR
ENV NODE_VERSION 16.14.0
# install nvm
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
# install node and npm
RUN source $NVM_DIR/nvm.sh \
&& nvm install $NODE_VERSION \
&& nvm alias default $NODE_VERSION \
&& nvm use default
# add node and npm to path so the commands are available
ENV NODE_PATH $NVM_DIR/versions/node/v$NODE_VERSION/lib/node_modules
ENV NVM_BIN $NVM_DIR/versions/node/v$NODE_VERSION/bin
ENV NVM_INC $NVM_DIR/versions/node/v$NODE_VERSION/include/node
ENV PATH $NVM_BIN:$PATH
# Install serverless
RUN npm install -g [email protected]
# Install Flutter
RUN curl -s https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_3.0.0-stable.tar.xz > flutter.tar.xz \
&& tar xf flutter.tar.xz -C /opt/ \
&& rm flutter.tar.xz
ENV PATH $PATH:/opt/flutter/bin
RUN git config --global --add safe.directory /opt/flutter
CMD [ "/bin/bash" ]
ENTRYPOINT [ "/bin/bash", "-c" ]
include:
- '/ci/ci-build-deploy.yml'
- '/ci/ci-tests.yml'
- '/ci/ci-undeploy.yml'
image: registry.gitlab.com/project/project/build/project-build-env:4
variables:
PROJECT_API_URL: https://gitlab.com/api/v4/projects/12345678
NODE_INSTALL_OPTIONS: ci --cache $CI_PROJECT_DIR/.npm --prefer-offline
cache:
key: PROJECT_NODE_CACHE
paths:
- .npm/
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
variables:
AWS_STAGE: "ci${CI_PIPELINE_ID}"
STAGE_TYPE: "ci"
- if: $STAGE_TYPE == "staging" && $AWS_STAGE == "staging"
variables:
HOSTED_ZONE_NAME: "staging.project.io"
FRONT_DOMAIN: "staging.project.io"
- if: $STAGE_TYPE == "prod" && $AWS_STAGE == "prod"
variables:
HOSTED_ZONE_NAME: "project.io"
FRONT_DOMAIN: "project.io"
- when: always
stages:
- build_deploy_user_service
- build_deploy_shop_service
- build_deploy_brand_service
- build_deploy_product_service
- build_deploy_web_ui
- build_deploy_reverseproxy
- test_shop_ws
- test_brand_ws
- test_product_ws
- delete_test_objects
- populate_db
- test_ui
- populate_cognito_test_user
- test_ui_integration
- triggerundeploy
- undeploy
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不再在那个特定的颤音项目上工作,但是我被告知E2E测试与以下设置相似:
dockerfile
.yml ci文件
显然我们不需要使用
flutter drive
在CI步骤上不再:I'm not working anymore on that particular Flutter project, but I've been told the e2e testing works with a setup similar to this:
Dockerfile
.yml CI file
Apparently we don't need to use
flutter drive
anymore on the CI step: