所以我已经编写了我的自动化机器人框架测试,它们在 GitLab 存储库中。我想每天自动运行一次。
- 这可能吗?
- 我需要一个 .gitlab-ci.yml 文件吗? (如果是,我在里面放了什么?)
最佳答案
是的,您完全可以在 gitlab ci 中运行机器人测试。
所以回答
- 是的,这很有可能,事实上这就是您执行管道测试的方式。您只需要构建一个 Dockerfile,其中包含在 docker 中执行框架所需的内容。这是示例 dockerfile。我建议您包装 .robot 脚本以从 bash 脚本运行(如 robot -d *.robot)。
FROM ubuntu:18.04
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8
RUN apt-get update --fix-missing && \
apt-get install -y python3-setuptools wget git bzip2 ca-certificates curl bash chromium-browser chromium-chromedriver firefox python3.8 python3-pip nano && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
RUN wget https://github.com/mozilla/geckodriver/releases/download/v0.27.0/geckodriver-v0.27.0-linux64.tar.gz
RUN tar xvf geckodriver*
RUN chmod +x geckodriver
RUN mv geckodriver /usr/bin
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 2
RUN pip3 install --upgrade pip
RUN ln -s /usr/bin/python3 /usr/bin/python
RUN ln -s /usr/bin/pip3 /usr/bin/pip
RUN pip install rpaframework
COPY . /usr/src/
ADD robot.sh /usr/local/bin/robot.sh
RUN chmod +x /usr/local/bin/robot.sh
WORKDIR /usr/src
- 现在您的存储库中需要 .gitlab-ci.yml 才能拥有这样的内容。
stages:
- build
- run
variables:
ARTIFACT_REPORT_PATH: "${CI_PROJECT_DIR}/reports"
build_image:
stage: build
variables:
DOCKER_IMAGE_TAG: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_NAME}
script:
- docker build -t ${DOCKER_IMAGE_TAG} .
after_script:
- docker push ${DOCKER_IMAGE_TAG}
- docker logout
robot_tests:
stage: run
variables:
DOCKER_IMAGE_TAG: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_TAG}
image: ${DOCKER_IMAGE_TAG}
script:
- robot-test.sh
artifacts:
paths:
- $ARTIFACT_REPORT_PATH
when: always
应该就是这样,作业完成后,您会在存储库中的路径位置看到作业中的输出。
关于continuous-integration - 使用 GitLab CI/CD 设置机器人框架管道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65090053/