Playwright实战-在gitlab ci环境运行自动化测试

803 篇文章 0 订阅
35 篇文章 0 订阅

2024软件测试面试刷题,这个小程序(永久刷题),靠它快速找到工作了!(刷题APP的天花板)_软件测试刷题小程序-CSDN博客文章浏览阅读3.4k次,点赞86次,收藏15次。你知不知道有这么一个软件测试面试的刷题小程序。里面包含了面试常问的软件测试基础题,web自动化测试、app自动化测试、接口测试、性能测试、自动化测试、安全测试及一些常问到的人力资源题目。最主要的是他还收集了像阿里、华为这样的大厂面试真题,还有互动交流板块……_软件测试刷题小程序​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502icon-default.png?t=N7T8https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502

简介:CI/CD持续集成和持续部署是确保代码质量和快速交付的关键步骤。本文详细介绍了如何在GitLab CI环境中配置和运行Playwright测试。

1. 前置条件

开始之前,请确保满足以下前提条件:

  • • Playwright测试可以在本地环境中运行正常

  • • Gitlab账号及项目

  • • Node.jsnpm基础

2. Playwright配置

2.1 Playwright环境

首先,确保在您的项目中安装了 Playwright。如果没有的话,可使用npm进行安装:

npm install playwright

2.2 Playwright 测试

import { test, expect } from '@playwright/test';

test('basic test', async ({ page }) => {
  await page.goto('https://baidu.com');
  const title = await page.title();
  expect(title).toBe('百度一下,你就知道');
});

3.Gitlab CI配置

3.1 .ymal文件配置

在项目的根目录中创建 .gitlab-ci.yml 文件,并配置 GitLab CI 以运行 Playwright 测试。以下是一个示例配置:

image: mcr.microsoft.com/playwright:focal

stages:
  - test

playwright_tests:
  stage: test
  script:
    - npx playwright install --with-deps
    - npx playwright test
  artifacts:
    paths:
      - playwright-report/
    expire_in: 1 week

说明如下

  • • image: 使用官方的 Playwright Docker 镜像,确保环境中包含运行 Playwright 测试所需的所有依赖项。

  • • stages: 定义了一个名为 test 的阶段。

  • • playwright_tests: 定义了一个作业 playwright_tests,它将在test阶段运行。

  • • script: 定义了在作业中运行的脚本,包括安装 Playwright 依赖项和运行测试。

  • • artifacts: 指定要保存的测试报告路径和过期时间。

3.2 更新到Gitlab仓库

将更改推送到 GitLab 仓库:

git add .
git commit -m "Add Playwright tests and GitLab CI configuration"
git push origin main

3.3 查看测试结果

  • • 每次推送代码到 GitLab 仓库时,GitLab CI 会自动触发 Playwright 测试并生成测试报告。

  • • 可以在 GitLab 项目的 CI/CD 部分查看作业的执行状态和详细日志。

3.4 环境变量

可以在 .gitlab-ci.yml 文件中添加环境变量,以便在测试中使用:

playwright_tests:
  stage: test
  script:
    - npx playwright install --with-deps
    - npx playwright test
  variables:
    BASE_URL: 'https://example.com'
  artifacts:
    paths:
      - playwright-report/
    expire_in: 1 week

3.5 并行设置

可以利用 GitLab CI 的并行作业功能,加快测试执行速度:

playwright_tests:
  stage: test
  script:
    - npx playwright install --with-deps
    - npx playwright test
  parallel: 3
  artifacts:
    paths:
      - playwright-report/
    expire_in: 1 week

3.6 监控

3.7 日志检查

3.8 日志下载

4. 结论

Playwrght不仅提供了本地环境自动化测试运行方式,还支持在dockerjenkinsgitlab运行,配置相对容易,能把自动化测试融合到研发cicd流水线,提高交付效率和质量。

行动吧,在路上总比一直观望的要好,未来的你肯定会感谢现在拼搏的自己!如果想学习提升找不到资料,没人答疑解惑时,请及时加入群: 759968159,里面有各种测试开发资料和技术可以一起交流哦。

最后: 下方这份完整的软件测试视频教程已经整理上传完成,需要的朋友们可以自行领取【保证100%免费】

​​​软件测试面试文档

我们学习必然是为了找到高薪的工作,下面这些面试题是来自阿里、腾讯、字节等一线互联网大厂最新的面试资料,并且有字节大佬给出了权威的解答,刷完这一套面试资料相信大家都能找到满意的工作。

在这里插入图片描述

在这里插入图片描述

  • 13
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值