我正在测试我用 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'