1

我正在测试我用 Cucumber/Capybara 创建的应用程序。看起来它没有看到我正在使用的x-tag 。看起来 Cucumber 没有使用 x-tag 正确呈现页面。有没有办法解决这个问题?我认为这是问题所在,因为当我将输入字段放在 xlogin.js 之外并放入 id=login 的正文或 div 时,它确实有效。

身体:

<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="js/jquery/jqueryMobile/jquery.mobile-1.2.0.css" />
    <link rel="stylesheet" href="components/login/login.css"/>
    <link rel="stylesheet" href="master.css"/>
</head>
<body>
    <div id="login" data-role="page" class="ui-tass-page">
        <x-login></x-login>
    </div>

    <div id="main" data-role="page" class="ui-tass-page">
    </div>


    <script src="js/x-tag.js"></script>
    <script src="components/login/login.js"></script>
    <script src="js/jquery/jquery-1.8.2.js"></script>
    <script src="js/jquery/jqueryMobile/jquery.mobile-1.2.0.js"></script>
</body>

特征:

Feature: log in
    In order to get access to the app's functionality
    As a user
    I want to log in

Scenario: happy flow
    Given I am on the index.html#login page
    Then I should be on the index.html page
    When I give my username
    And I give my password
    And I click on login
    Then I should go to the main page
    And the username and password are saved

脚步:

When /^I give my username$/ do
  fill_in 'username', :with => 'user@example.com'
end

Given /^I am on the (.*?) page$/ do |uri|
  visit uri
  response = page.driver.response
  response.status.should eql 200
  response.status.should_not eql 401
end 

Then /^I should be on the (.*?) page$/ do |uri|
  current_url.include?( uri ).should be true
end

输出:

 Scenario: happy flow                      # features/login.feature:6
    Given I am on the index.html#login page # features/step_definitions/generic_steps.rb:1
    Then I should be on the index.html page # features/step_definitions/generic_steps.rb:8
    When I give my username                 # features/step_definitions/login_steps.rb:1
      cannot fill in, no text field, text area or password field with id, name, or label 'username' found (Capybara::ElementNotFound)
      (eval):2:in `fill_in'
      ./features/step_definitions/login_steps.rb:2:in `/^I give my username$/'
      features/login.feature:9:in `When I give my username'
4

1 回答 1

0

我解决了这个问题。什么地方出了错:

1:我在 Capybara 中使用的是默认驱动程序。此驱动程序无法处理 Javascript。

解决方法:使用驱动 Selenium

  Capybara.javascript_driver = :selenium

2:我通过 ssh 使用 Ubuntu 服务器。所以 Selenium 使用的浏览器(firefox)不起作用。

解决方案:我切换到桌面Ubuntu并使用vnc连接它。

于 2012-10-31T08:38:39.947 回答