Jquery 黄瓜试验无效

Jquery 黄瓜试验无效,jquery,ruby-on-rails,cucumber,Jquery,Ruby On Rails,Cucumber,我是测试新手,我很难弄清楚为什么我的测试不起作用。这是我的功能文件,名为child\u user\u selected\u categories.feature @no-database-cleaner Feature: Managing selected_categories In order to use portal I want to create selected_categories for child user Scenario: Creating a child

我是测试新手,我很难弄清楚为什么我的测试不起作用。这是我的功能文件,名为child\u user\u selected\u categories.feature

@no-database-cleaner
Feature: Managing selected_categories
  In order to use portal
  I want to create selected_categories for child user


  Scenario:  Creating a child selected_categories for a child user
    Given the database contains no test data
    And an user and sub user exists
    Given I am on the homepage

    When I attempt to sign in with following user account:
      | email address         | password |
      | abc@company1.com   | password |

    Then I should see "abc@company1.com" message on page
    When I follow "All Child Users"
    And I view "Child Categories" for sub user "xyztest@gmail.com"
    Then I should see "Default Filter Level for User xyztest@gmail.com is"
    When I press "APPLY"
    Then I should see "Custom Filter Created for xyztest@gmail.com"
我正在使用工厂女孩插入记录。这是我的步骤定义文件,名为child_user_selected_categories.rb

And /^I view "([^"]*)" for sub user "([^"]*)"$/ do |link, user|
  selector = find('tr', text: user)
  within selector do
    click_link(link)
  end
end

Given(/^an user and sub user exists$/) do
  parent = FactoryGirl.create(:user)
  user = FactoryGirl.create(:user, email: "xyztest@gmail.com", parent_id: parent.id, default_filter_level: parent.default_filter_level)
  account = FactoryGirl.create(:account, user_id: parent.id)
  FactoryGirl.create(:filter, user_id: user.id, account_id: account.id)
  FactoryGirl.create(:filter, user_id: parent.id, account_id: account.id)
end
features/support下名为user.rb的字段具有覆盖某些用户字段的代码 需要“工厂\女孩\轨道”

FactoryGirl.define do
  factory :user do |u|
    u.email 'recdns@company1.com'
    u.password 'password'
    u.src_ip_addr 'hostname -I'
    u.ar_id true
    u.default_filter_level 'Medium'
    u.src_netmask '255.255.255.0'
  end
end
使用jquerypost应用提交按钮

//on sibmit this will create a records for user for selected categories
        $("#selectes_categories").submit(function(){

            // get alll the selected category ids in list box 2
            var options = $("select#lstBox2").children().map(function() {return $(this).val();}).get();

            //var values = $('#categories_ids_').val()
            $('#selected_category_ids').val(options);
            $.post($(this).attr("action"),$(this).serialize(),function(response){
                $("#flash_notice").html(response);
            });
            return false;
        });

<%= form_tag "/levels/create_user_selected_categories", :id=> "selectes_categories" do %>
    <%= hidden_field_tag 'selected_category_ids' %>
    <%= hidden_field_tag 'user_id',@user.id %>
    <%= submit_tag "APPLY",:class => 'btn btn-primary'%>
<% end %>

有什么建议吗?谢谢

假设您将水豚与黄瓜一起使用,默认情况下不会执行Javascript。一个非常简单的解决方案可能是将
@javascript
标记添加到场景中:

@javascript 
Scenario:  Creating a child selected_categories for a child user
...
这将使用驱动程序运行您的场景,驱动程序将实际打开一个浏览器窗口,并像实际用户一样测试您的应用程序,其中包括Javascript执行。默认情况下,它将尝试使用Firefox,因此请确保您已经安装了Firefox


更多信息:

假设您正在将Capybara与Cucumber一起使用,默认情况下不会执行Javascript。一个非常简单的解决方案可能是将
@javascript
标记添加到场景中:

@javascript 
Scenario:  Creating a child selected_categories for a child user
...
这将使用驱动程序运行您的场景,驱动程序将实际打开一个浏览器窗口,并像实际用户一样测试您的应用程序,其中包括Javascript执行。默认情况下,它将尝试使用Firefox,因此请确保您已经安装了Firefox


更多信息:

我添加了@javascript,现在当我尝试使用以下用户帐户登录时,它说的是
:#功能/step|定义/user|steps.rb:65 |电子邮件地址|密码|recdns@company1.com|密码|找不到字段“email”(Capybara::ElementNotFound)
这是用户的步骤。rb code
给定/^我尝试使用电子邮件“(.*?”、密码“.*?”$/do |电子邮件、密码|登录(电子邮件、密码)结束
def login(电子邮件、密码)填写('user_email',:with=>email)填写('user_password',:with=>password)点击按钮('login')结束
您的测试似乎正在尝试运行登录步骤,但浏览器不在正确的页面上。您应该能够查看浏览器并查看其导航到的页面,以确保其正确。如果我在主页步骤中,您还可以将
保存和_打开页面
放在
的最后,这将打开一个“快照”我添加了@javascript,现在当我尝试使用以下用户帐户登录时,它说:#features/step_definitions/user_steps.rb:65 |电子邮件地址| password |recdns@company1.com|密码|找不到字段“email”(Capybara::ElementNotFound)
这是用户的步骤。rb code
给定/^我尝试使用电子邮件“(.*?”、密码“.*?”$/do |电子邮件、密码|登录(电子邮件、密码)结束
def login(电子邮件、密码)填写('user_email',:with=>email)填写('user_password',:with=>password)点击按钮('login')结束
您的测试似乎正在尝试运行登录步骤,但浏览器不在正确的页面上。您应该能够查看浏览器并查看其导航到的页面,以确保其正确。如果我在主页步骤中,您还可以将
保存和打开页面
放在
的最后,这将打开您的测试导航到的页面的“快照”。