how to use capybara has_text

流过昼夜 提交于 2019-12-19 11:16:03

问题


So now I've got cucumber/capybara/selenium hitting a google app script, which is great, but for some reason I can't seem to check for text in the body of the page in the way I expect. In the debugger I can grab the page object, which I can in the browser has the expected text. Scanning the html directly shows the text appearing twice, and yet page.has_text? appears false:

(rdb:1) p page.html.scan(/Introduction Video/)
["Introduction Video", "Introduction Video"]
(rdb:1) p page.has_text? 'Introduction Video'
false

an alternate scan gives more information on the text surrounding:

(rdb:1) p page.html.scan(/.{10}Introduction Video.{10}/)
["" Introduction Video\\u003C\\/a&", "lank\\\">Introduction Video\\u003C\\/a&"]

which makes me wonder if this is an encoding issue. I want to look at exactly what the has_text? method does, so I look at the docs:

http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Matchers#has_text%3F-instance_method

But I can't get the additional parameter to be accepted:

(rdb:1) p page.has_text? :all, "Introduction Video"
ArgumentError Exception: wrong number of arguments (2 for 1)

which makes me wonder if the code I am running is the same as in the docs - and brings me back to my usual Ruby bugbear of not being sure where to go to find the open source code I am relying on ...

Anyway, all the code I'm using is here:

https://github.com/tansaku/GoogleAppScriptBDD

Any help very much appreciated.


回答1:


In Capybara 2.0 has_text? has only one parameter - content.

type parameter of has_text? (with possible values :all and :visible) appeared in version 2.1 which is currently in beta.

However, Capybara 2.1.0.beta1 is stable and doesn't have any known regression bugs. Currently it's supported only by built-in Selenium and Racktest drivers. At the moment of writing available gem versions of Capybara-Webkit, Poltergeist and Terminus don't support Capybara 2.1.

I use 2.1.0.beta1 so I can recommend you to use it if you use built-in selenium or racktest drivers.



来源:https://stackoverflow.com/questions/15681615/how-to-use-capybara-has-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!