• <bdo id='zkRcv'></bdo><ul id='zkRcv'></ul>

    <small id='zkRcv'></small><noframes id='zkRcv'>

  • <i id='zkRcv'><tr id='zkRcv'><dt id='zkRcv'><q id='zkRcv'><span id='zkRcv'><b id='zkRcv'><form id='zkRcv'><ins id='zkRcv'></ins><ul id='zkRcv'></ul><sub id='zkRcv'></sub></form><legend id='zkRcv'></legend><bdo id='zkRcv'><pre id='zkRcv'><center id='zkRcv'></center></pre></bdo></b><th id='zkRcv'></th></span></q></dt></tr></i><div id='zkRcv'><tfoot id='zkRcv'></tfoot><dl id='zkRcv'><fieldset id='zkRcv'></fieldset></dl></div>
    <tfoot id='zkRcv'></tfoot>

      <legend id='zkRcv'><style id='zkRcv'><dir id='zkRcv'><q id='zkRcv'></q></dir></style></legend>

        Testcafe - 在测试用例之外测试命令行参数

        时间:2023-09-06
          <bdo id='6ctYp'></bdo><ul id='6ctYp'></ul>

              • <i id='6ctYp'><tr id='6ctYp'><dt id='6ctYp'><q id='6ctYp'><span id='6ctYp'><b id='6ctYp'><form id='6ctYp'><ins id='6ctYp'></ins><ul id='6ctYp'></ul><sub id='6ctYp'></sub></form><legend id='6ctYp'></legend><bdo id='6ctYp'><pre id='6ctYp'><center id='6ctYp'></center></pre></bdo></b><th id='6ctYp'></th></span></q></dt></tr></i><div id='6ctYp'><tfoot id='6ctYp'></tfoot><dl id='6ctYp'><fieldset id='6ctYp'></fieldset></dl></div>

                • <small id='6ctYp'></small><noframes id='6ctYp'>

                    <tbody id='6ctYp'></tbody>
                  <legend id='6ctYp'><style id='6ctYp'><dir id='6ctYp'><q id='6ctYp'></q></dir></style></legend>

                  <tfoot id='6ctYp'></tfoot>
                  本文介绍了Testcafe - 在测试用例之外测试命令行参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  随着我对 Testcafe 的熟悉,我尝试使用命令行参数为用户提供有关如何运行测试的更多信息.出于这个原因,我正在使用 minimist 包.

                  As I'm getting familiar with Testcafe, I'm trying to use a command line argument to give the user more information on how to run tests. For that reason, I'm using the minimist package.

                  但是,我无法打印或使用测试用例之外的任何变量.请在下面找到我的代码.

                  However, I cannot print or use any variables outside the test cases. Please find below my code.

                  import { Selector } from 'testcafe';
                  import minimist from 'minimist';
                  
                  const args = minimist(process.argv.slice(2));
                  const env = args.env;
                  
                  console.log('*** A SAMPLE CONSOLE OUTPUT ***'); // does not print
                  
                  fixture `Getting Started`
                    .page `http://devexpress.github.io/testcafe/example`;
                  
                  test('My first test', async t => {
                    console.log('*** ANOTHER SAMPLE CONSOLE OUTPUT ***'); // prints
                    await t
                      .typeText('#developer-name', 'John Smith')
                      .wait(1000)
                      .click('#submit-button')
                  
                      // Use the assertion to check if the actual header text is equal to the expected one
                      .expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');
                  });
                  

                  我想编写一个 if 语句来检查是否 env === '' 或使用默认参数.

                  I want to write an if statement that checks if env === '' or use a default argument.

                  我怎样才能做到这一点?

                  How can I accomplish this?

                  推荐答案

                  但是,我无法打印或使用测试用例之外的任何变量.

                  However, I cannot print or use any variables outside the test cases.  

                  请使用编程方式运行TestCafe.我已经更改了您的代码示例 (test.js) 并创建了一个以编程方式运行 TestCafe 的文件 (run.js).将这些文件放入文件夹并在终端中执行命令 'node run.js --env value'.然后你会看到如下输出:

                  Please use a programming way to run TestCafe. I've changed you code example (test.js) and created a file that runs TestCafe programmatically (run.js). Put these files into a folder and perform command 'node run.js --env value' in your terminal. Then you will see the following output:

                  '*** A SAMPLE CONSOLE OUTPUT ***'
                  Getting Started
                  value
                  

                  test.js
                  
                  import { Selector } from 'testcafe';
                  import minimist from 'minimist';
                  
                  const args = minimist(process.argv.slice(2));
                  const env = args.env;
                  
                  console.log('*** A SAMPLE CONSOLE OUTPUT ***'); 
                  
                  fixture `Getting Started`
                    .page `http://devexpress.github.io/testcafe/example`;
                  
                  test('My first test', async t => {
                    console.log(env); // prints
                    await t
                      .typeText('#developer-name', 'John Smith')
                      .wait(1000)
                      .click('#submit-button')
                      .expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');
                  });
                  

                  run.js
                  const createTestCafe = require('testcafe');
                  let runner           = null;
                  
                  createTestCafe('localhost', 1337, 1338, void 0, true)
                      .then(testcafe => {
                          runner = testcafe.createRunner();
                      })
                      .then(() => {
                           return runner
                              .src('test.js')
                              .browsers('chrome')
                              .run()
                              .then(failedCount => {
                                  console.log(`Finished. Count failed tests:${failedCount}`);
                                  process.exit(failedCount)
                              });
                      })
                      .catch(error => {
                          console.log(error);
                          process.exit(1);
                      });
                  

                  这篇关于Testcafe - 在测试用例之外测试命令行参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:检查测试是否在 Jest 的 afterEach 中失败 下一篇:如何使用 vue.js v-select 通过 cypress.io 查找元素并选

                  相关文章

                  最新文章

                  <i id='d14rp'><tr id='d14rp'><dt id='d14rp'><q id='d14rp'><span id='d14rp'><b id='d14rp'><form id='d14rp'><ins id='d14rp'></ins><ul id='d14rp'></ul><sub id='d14rp'></sub></form><legend id='d14rp'></legend><bdo id='d14rp'><pre id='d14rp'><center id='d14rp'></center></pre></bdo></b><th id='d14rp'></th></span></q></dt></tr></i><div id='d14rp'><tfoot id='d14rp'></tfoot><dl id='d14rp'><fieldset id='d14rp'></fieldset></dl></div>

                  <small id='d14rp'></small><noframes id='d14rp'>

                    <bdo id='d14rp'></bdo><ul id='d14rp'></ul>
                • <tfoot id='d14rp'></tfoot>

                    <legend id='d14rp'><style id='d14rp'><dir id='d14rp'><q id='d14rp'></q></dir></style></legend>