1

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.

Sam Joseph
  • 4,584
  • 4
  • 31
  • 47
  • I don't see anything related to `has_text` at https://github.com/tansaku/GoogleAppScriptBDD – Andrei Botalov Mar 30 '13 at 09:30
  • I have a "have_content" check in https://github.com/tansaku/GoogleAppScriptBDD/blob/master/features/step_definitions/gas_steps.rb which I assumed was being converted to "has_content?" by rspec and I thought has_content? and has_text? were the same ... - you can see the debugger statement there - that's where I'm dropping in and executing the statements you see above ... perhaps I am barking up the wrong tree ... – Sam Joseph Mar 31 '13 at 09:52
  • When I visited https://script.google.com/macros/s/AKfycbzVweiPGHCLcxLR0HlWRtr5QuxJbtUONOY_o6RSp1xQu2XyptE/exec in my browser I saw text like "The script Assignment Status CSCI4702 Spring 2013 owned by tansaku@gmail.com and last edited by tansaku@gmail.com on Mar 29, 2013, 8:07:45 AM requires your authorization to run". There is no text "You have watched the Introduction Video" here – Andrei Botalov Mar 31 '13 at 10:55
  • Yes, you have to have approved the scriptaim the first instance, but the browser will remember. I haven't automated that step yet, but the debugger output above shows that that text is available when running for me ... I.e. that HTML.scan statement – Sam Joseph Mar 31 '13 at 14:57

1 Answers1

2

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.

Andrei Botalov
  • 20,686
  • 11
  • 89
  • 123
  • Hi andrey, thanks so much for your quick response. Doing gem update capybara I got 2.0.3 Forgive me if this is silly question, but how would I get the beta version? And either way, have you any idea why the has_text? operation in 2.0.2 (which is where I encountered that issue) is not detecting the text that the html.scan operation does? I tried again with 2.0.3 and get the same result - am I misunderstanding what has_text? is supposed to do? What are the restrictions on the text it finds? – Sam Joseph Mar 29 '13 at 12:10
  • @SamJoseph If you use Gemfile, you can use `gem 'capybara', '~> 2.1.0.beta1'` – Andrei Botalov Mar 29 '13 at 14:16
  • In Capybara 2.0.x `has_text` returns only visible text if `Capybara.ignore_hidden_elements = true` – Andrei Botalov Mar 29 '13 at 14:17
  • In driver is Selenium visibility is checked using `displayed?` method – Andrei Botalov Mar 29 '13 at 14:19