【发布时间】:2011-02-18 14:51:44
【问题描述】:
我现在正在使用 Cucumber 和 Rails 测试视图,并且非常享受这种体验。我可以很容易地说:
Background:
Given I am logged in as a customer
Scenario: View the Welcome Page
When I go to the home page
Then I should be on the "Welcome" page
And I should see the following in the sidebar:
| selector | text |
| h3 | Search |
| .home-page | Home |
| .about-page | About |
现在我想知道,我怎样才能更进一步说:
And I should see the following colors on the "Welcome" page:
| selector | background |
| #content | white |
| #sidebar | grey |
| #navigation | blue |
我觉得我看到可以使用 Node.js 或其他服务器端 javascript 来执行此操作,因为它完全依赖于浏览器。有没有办法做到这一点,也许只在 Safari 和 Firefox 中使用 Selenium?
我只想测试主要的颜色和字体,不一定是跨浏览器疯狂的布局 b/c。我怎么能这样做?可能有点Jasmine 和Cucumber?
谢谢!
更新
感谢@idlefingers,以下是可行的方法:
设置:黄瓜,水豚。
功能/支持/env.rb:
Capybara.javascript_driver = :selenium
*features/step_definitions/css_steps.rb:*
Then /^I should see the color "([^"]+)" on the ([^"]+)$/ do |color, selector|
element_color = page.evaluate_script('$("##{selector}").css("border-left-color");') # "rgb(221, 221, 221)"
assert_equal color, some_color_conversion_method(element_color)
end
features/some.feature:
And I should see the color "red" on the sidebar
如果有更好的方法,我很想知道!
【问题讨论】:
标签: ruby-on-rails css tdd selenium