# Extending Watir::Checkbox class

**URL:** <https://www.ruby-forum.com/t/extending-watir-checkbox-class/71119>\
**Category:** Ruby\
**Created:** [October 5, 2006, 2:17pm UTC](https://www.ruby-forum.com/t/extending-watir-checkbox-class/71119 "2006-10-05T14:17:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pkspence](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a88e57/32.png) [@pkspence](https://www.ruby-forum.com/u/pkspence)\
**Post date:** [October 5, 2006, 2:17pm UTC](https://www.ruby-forum.com/t/extending-watir-checkbox-class/71119/1 "2006-10-05T14:17:30Z")

</div>

I have a script which contains class extensions. The Checkbox.test() is  
obviously just a stub right now, but I’m trying to get my head around  
the concept.

#-- contained in classExtensions.rb  
module Watir

class Checkbox \< Watir::RadioCheckCommon

```
def test(property, expectedResult)
  puts("Checkbox.test()")
end

```

end

end

In another script, I have the following…

require ‘watir’  
require ‘sqlClient’  
require ‘classExtensions’

.  
.  
.

ie.checkboxes.each {|cb|  
cb.test(“jfkdsajf”, “jfkdlas”, “jfkdlasjf”)  
}

However, I’m getting the following error:  
#\<NoMethodError: private method `test’ called for #Watir::CheckBox\>

What am I doing wrong here?

---

<div class="post-metadata">

**Author:** ![pkspence](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a88e57/32.png) [@pkspence](https://www.ruby-forum.com/u/pkspence)\
**Post date:** [October 6, 2006, 2:08pm UTC](https://www.ruby-forum.com/t/extending-watir-checkbox-class/71119/2 "2006-10-06T14:08:25Z")

</div>

Patrick S. wrote:

> However, I’m getting the following error:  
> #\<NoMethodError: private method `test’ called for #Watir::CheckBox\>
> 
> What am I doing wrong here?

Anyone?

---

<div class="post-metadata">

**Author:** ![pkspence](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a88e57/32.png) [@pkspence](https://www.ruby-forum.com/u/pkspence)\
**Post date:** [October 11, 2006, 2:45am UTC](https://www.ruby-forum.com/t/extending-watir-checkbox-class/71119/3 "2006-10-11T02:45:26Z")

</div>

> > What am I doing wrong here?
> 
> Anyone?

Could you please explain what you are trying to do?

---

<div class="post-metadata">

**Author:** ![pkspence](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a88e57/32.png) [@pkspence](https://www.ruby-forum.com/u/pkspence)\
**Post date:** [October 11, 2006, 2:34pm UTC](https://www.ruby-forum.com/t/extending-watir-checkbox-class/71119/4 "2006-10-11T14:34:49Z")

</div>

Bret P. wrote:

> > > What am I doing wrong here?
> > 
> > Anyone?
> 
> Could you please explain what you are trying to do?

I googled “extending watir” and found this…  
[http://wiki.openqa.org/pages/viewpage.action?pageId=1119](http://wiki.openqa.org/pages/viewpage.action?pageId=1119), which got me  
pointed in the right direction. Here’s the definition of the class  
extension, although I must admit I don’t fully understand it. At any  
rate, when I run the test script, “test” is now listed as _public_  
method.

class Watir::CheckBox

def test(property, expectedResult)  
puts(“CheckBox.test("#{property}", "#{expectedResult}")”)  
end

end

Bret, in response to your query… I’m having to modify the way we are  
checking properties on web page controls; visible, enabled, disabled…  
blahblah, in order to “conform” to a new way my supervisor wants tests  
run. When I started on this project, I was looking at the forms and  
running the tests on each form as a whole. We are now breaking the forms  
down to their individual components and testing each one, comparing the  
expected test results, contained in a SQL Server table, with the actual  
result. I only wish someone had thought about that 3-months ago,  
probably should’ve been me actually. Most of the work already done by  
myself and a coworker will have to be re-written to conform to the new  
testing “model”. Oh well… it beats standing in a line!

–Patrick

---

<div class="post-metadata">

**Author:** ![pkspence](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a88e57/32.png) [@pkspence](https://www.ruby-forum.com/u/pkspence)\
**Post date:** [October 11, 2006, 2:38pm UTC](https://www.ruby-forum.com/t/extending-watir-checkbox-class/71119/5 "2006-10-11T14:38:18Z")

</div>

Patrick S. wrote:

> I googled “extending watir” and found this…  
> [http://wiki.openqa.org/pages/viewpage.action?pageId=1119](http://wiki.openqa.org/pages/viewpage.action?pageId=1119)  
>   
> Sorry 'bout the password protected site, I’d forgotten about that.  
> Anyway, I found the following code posted:

class Watir::Element

# If any parent element isn’t visible then we cannot write to the

# element. The only realiable way to determine this is to iterate

# up the DOM element tree checking every element to make sure it’s

# visible.

def visible?  
# Now iterate up the DOM element tree and return false if any  
# parent element isn’t visible or is disabled.  
object = document  
while object  
begin  
if object.style.invoke(‘visibility’) =~ /^hidden$/i  
return false  
end  
if object.style.invoke(‘display’) =~ /^none$/i  
return false  
end  
if object.invoke(‘isDisabled’)  
return false  
end  
rescue WIN32OLERuntimeError  
end  
object = object.parentElement  
end  
true  
end  
end
