我正在测试我用Cucumber/Capybara创建的应用程序。它看起来没有看到我正在使用的x-tag。看起来Cucumber没有使用x标记正确地呈现页面。有没有办法解决这个问题?我认为这就是问题所在,因为当我使用id=login将输入字段放在xlogin.js外部并放入主体或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'发布于 2012-10-31 16:38:40
我解决了这个问题。哪里出了问题:
1:我使用的是Capybara的默认驱动程序。此驱动程序无法处理Javascript。
解决方案:使用驱动程序Selenium
Capybara.javascript_driver = :selenium2:我通过ssh使用Ubuntu服务器。所以Selenium使用的浏览器(firefox)无法工作。
解决方案:我切换到桌面Ubuntu,并使用vnc连接到它。
https://stackoverflow.com/questions/13119640
复制相似问题