如何使用cucumber获取javascript?

如何使用cucumber获取javascript?,javascript,cucumber,Javascript,Cucumber,我使用黄瓜时遇到一些问题 这是我的树木园 -- app1 |-- features | |-- addition.feature | |-- step_definitions | `-- support | `-- env.js |-- public | `-- javascripts | |-- Player.js | `-- Song.js |-- Rakefi

我使用黄瓜时遇到一些问题

这是我的树木园

-- app1
    |-- features
    |   |-- addition.feature
    |   |-- step_definitions
    |   `-- support
    |       `-- env.js
    |-- public
    |   `-- javascripts
    |       |-- Player.js
    |       `-- Song.js
    |-- Rakefile
    `-- spec
        `-- javascripts
            |-- helpers
            |   `-- SpecHelper.js
            |-- PlayerSpec.js
            `-- support
                |-- jasmine_config.rb
                |-- jasmine_runner.rb
                `-- jasmine.yml
这是我的文件“addition.feature”

当我跑的时候

黄瓜特性

Feature: Addition
  In order to avoid silly mistakes
  As a math idiot
  I want to be told the sum of two numbers

  Scenario: Add two numbers
    Given I have entered 50 into the calculator
    And I have entered 70 into the calculator
    When  press add
    Then the result should be 120 on the screen
我明白了


为什么输出是ruby语言,考虑到我在“support/”目录中有一个“.js”文件,我不应该得到javascript吗?

据我所知,您可以使用capybara测试javascript。在谷歌上快速搜索:

解决方案:

gem安装therubyracer


在您可能感兴趣的

上找到。它是Cucumber到JavaScript的官方端口

请记住,与cucumber ruby相比,它仍然缺少一些特性(背景、表、标记等)


不过,您在这里公开的场景在cucumber.js上应该可以正常运行。

如果您使用的是Windows 10,您可以安装CuckeTest。只需在Windows应用商店中搜索CukeTest,它提供了编辑小黄瓜文件和自动生成JavaScript函数的可视化方法。

谢谢,但我的一位朋友正在执行相同的过程(我们有相同的ruby版本,相同的cucumber版本),并获得js输出。我找到了解决方案,宝石“therubyracer”不见了。谢谢Michael Koper anywayOP有一个特定的问题并找到了解决方案。提供一个可以做类似事情的程序是没有帮助的。
Feature: Addition
  In order to avoid silly mistakes
  As a math idiot
  I want to be told the sum of two numbers

  Scenario: Add two numbers                     # features/addition.feature:6
    Given I have entered 50 into the calculator # features/addition.feature:7
    And I have entered 70 into the calculator   # features/addition.feature:8
    When press add                              # features/addition.feature:9
    Then the result should be 120 on the screen # features/addition.feature:10

1 scenario (1 undefined)
4 steps (4 undefined)
0m0.003s

You can implement step definitions for undefined steps with these snippets:

Given /^I have entered (\d+) into the calculator$/ do |arg1|
  pending # express the regexp above with the code you wish you had
end

When /^press add$/ do
  pending # express the regexp above with the code you wish you had
end

Then /^the result should be (\d+) on the screen$/ do |arg1|
  pending # express the regexp above with the code you wish you had
end

If you want snippets in a different programming language, just make sure a file
with the appropriate file extension exists where cucumber looks for step definitions.