小编anu*_*ter的帖子

运行脚本时抛出找不到模块“dotenv”

在加载.env文件以将 env 值传递给getToken.jscypress 根文件夹中的脚本时,会抛出无法找到模块 'dotenv' 错误。我已经安装了npm install dotenv. 有人可以告诉我在这里缺少什么吗?.env文件位于 cypress 根文件夹中。

环境:Windows 10 > git bash /命令提示符

    const puppeteer = require("puppeteer");
    require('dotenv').config({path: '.env'})
    
    const baseURL = process.env.CYPRESS_BASE_URL
    const testsUser = process.env.CYPRESS_TESTS_USERNAME
puppeteer
  .launch({ headless: true, chromeWebSecurity: false, args: ['--no-sandbox'] })
  .then(async browser => {
    const page = await browser.newPage();
    await page.goto(`${baseURL}/login`);

    await page.waitFor(2000);
    await page.waitForSelector("input[name=username]");
    await page.type("input[name=username]", testsUser , {
      delay: 50
    });

    browser.close();
  });
Run Code Online (Sandbox Code Playgroud)

包.json

"scripts": {
    "cy:run": "cypress run",
    "get-token-main": …
Run Code Online (Sandbox Code Playgroud)

puppeteer cypress dotenv

17
推荐指数
3
解决办法
4万
查看次数

使用 TestCafe 发出真实的 HTTP 请求

由于严格通过前端自动化我们工作流程的某些部分的复杂性,我们需要在前端自动化测试运行之前发出 HTTP 请求以设置测试数据。

使用 TestCafe 文档,我尝试将一些东西拼凑在一起,当测试运行时,http 请求没有得到执行。这是我的代码:

import {Selector, ClientFunction, RequestHook, RequestLogger} from 'testcafe';
import https from 'https';


fixture `Call Create Test Move`
    .before(async ctx => {
        test('test', async t => {
            const executeRequest = () => {
                return new Promise(resolve => {
                    const options = {
                        method: 'POST',
                        uri: 'https://api.com/move/sample',
                        headers: {
                            "X-Company-Secret": "xxxxxxx",
                            "X-Permanent-Access-Token": "xxxxxxx"
                        },
                        body: {
                            companyKey: 'xxxxxx'
                        },
                        json: true
                    };

                    const req = https.request(options, res => {
                        console.log('statusCode:', res.statusCode);
                        console.log('headers:', res.headers);
                        resolve();
                    });

                    req.on('error', …
Run Code Online (Sandbox Code Playgroud)

javascript testing automated-tests e2e-testing testcafe

0
推荐指数
1
解决办法
1458
查看次数