【问题标题】:Why Protractor (in a Angular (v.4) project) doesn't find any spec to test?为什么量角器(在 Angular (v.4) 项目中)找不到任何要测试的规范?
【发布时间】:2018-03-13 18:18:33
【问题描述】:

我在一个 Angular (v.4) 项目中工作并使用 Protractor 我遇到了这个问题

从终端:

I/launcher - 运行 1 个 WebDriver 实例

I/hosted - 在http://localhost:4444/wd/hub 使用 selenium 服务器 已开始 未找到规格 0.003 秒内完成

I/launcher - 0 个 WebDriver 实例仍在运行 [17:06:38] I/launcher - chrome #01 已通过

它运行快速关闭的浏览器,它不运行(查找)任何规范。

量角器.conf.js:

require('ts-node/register');
var helpers = require('./helpers');

exports.config = {
  baseUrl: 'http://localhost:3000/',

  // use `npm run e2e`
  specs: [
    helpers.root('test/e2e/**/**.e2e.ts'),
    helpers.root('test/e2e/**/*.e2e.ts')
  ],
  exclude: [],

  framework: 'jasmine2',

  allScriptsTimeout: 110000,

  jasmineNodeOpts: {
    showTiming: true,
    showColors: true,
    isVerbose: false,
    includeStackTrace: false,
    defaultTimeoutInterval: 400000
  },

  directConnect: true,

  capabilities: {
    browserName: 'chrome',
    chromeOptions: {
      args: ["--headless", "--disable-gpu", "--window-size=800x600"]
    }
  },

  onPrepare: function () {
    browser.ignoreSynchronization = true;
  },

  /**
   * Angular 2 configuration
   *
   * useAllAngular2AppRoots: tells Protractor to wait for any angular2 apps on the page instead of just the one matching
   * `rootEl`
   */
  useAllAngular2AppRoots: true
};

文件夹结构

-/App
|--/config
   |--protractor.conf.js
   |--helpers.js 
   |--(all webpack files)
   |--(other stuff)
|--/node_modules
|--/src
|--/test
   |--/e2e
      |-mytest.e2e.ts
   |--/features
   |--/mockBackend
   |--/pages
      |-mypage.page.ts
   |--config.js

package.json

"cucumber": "^2",
"cucumber-html-reporter": "^3.0.4",
"cucumber-snippets-tsflow": "^1.0.2",
"cucumber-tsflow": "^2.2.0",
"protractor": "^5.1.2",
"protractor-cucumber-framework": "^3",
"protractor-snapshot": "^1.2.0",

【问题讨论】:

  • 是的,无事可做
  • 没有伙伴,因为 helpers.root() 解析路径
  • 好吧,忘记 helpers.root,它不起作用。先打好基础。你是在告诉我硬编码../test/e2e/**/*.e2e.ts 没有helpers.root 不起作用??
  • 是的,无事可做
  • 抱歉,我看错了文件夹结构。 e2e下没有目录,和../test/e2e/*.e2e.ts有什么区别?删除上面的 cmets 以便为这些腾出空间

标签: angular jasmine protractor angular-e2e


【解决方案1】:

我刚刚意识到您可能执行npm run e2e 作为启动命令,表明您正在使用angular-cli 或类似的方式运行量角器。因此,运行命令而不是路径定义中可能存在问题。据我所见,方式上有一些变化/问题,量角器开始了,即here

我建议试试这些:

  1. 将您的规格部分放在capabilities: { ... }-part 中,因为这是offered by protractor。也许其中一个 angular-cli-configuration 期望在那里而不是作为一个单独的部分
  2. 使用像Cliptor.js 这样的配置帮助工具来创建一个新的配置文件,然后比较您的文件的差异。
  3. 通过执行命令protractor protractor.conf.js (from the official protractor site) 而不是npm run e2e 直接启动Protractor,以验证/伪造问题是在angular-cli 内还是在protractor 内。

【讨论】:

    【解决方案2】:

    任何路径都从存储protractor.conf.js 的位置开始(因此您从配置文件夹开始)。鉴于提供的文件夹结构,我将从正常路径开始:

    // use `npm run e2e`
    specs: [
        //one level up, then below test/e2e/ all files ending with '.e2e.ts'
       // '../test/e2e/**/**.e2e.ts', //if *.ts is a file, no need for double ** 
        '../test/e2e/**/*.e2e.ts'  
    ],
    exclude: [],
    

    如果**.e2e.ts 代表一个文件夹而不是一个文件,您的路径应该以/**e2e.ts/*.js 结尾(或者您为测试文件本身选择的任何文件结尾)。

    还有你的helpers.js-文件,你应该得到var helpers = require('./helpers.js');

    我看不到,this.root 背后的内容我无法为helpers.root() 提供任何东西

    您是否还想使用 TestSuites 或者您可能想构建一个辅助函数,在其中您可以从基本目录而不是 conf.js 的相对路径开始。查看这些链接:

    Test Suites vs specs.

    baseDir instead of relative path.

    希望我能帮上忙。

    【讨论】:

    • ./helpersProjectFolder/config/ 文件夹中的一个 js 文件
    • 你尝试var helpers = require('./helpers.js');了吗?在这种情况下this.root的内容是什么?
    • 是的,我得到了同样的错误,我也尝试了一个正常的路径 specs:['./test/e2e/**/*.e2e.ts'],什么都没有得到那个“错误”
    • 您的测试文件夹在您的配置文件夹中吗?对于正常路径,您从 conf.js 的位置开始。 specs:['../test/e2e/**/*.e2e.ts']
    • 我添加了文件夹结构和 package.json 的一部分相关 Protractor 和 Cucumber
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-20
    • 2021-01-10
    • 1970-01-01
    • 2018-02-17
    • 2018-09-30
    相关资源
    最近更新 更多