Gabe wrote:
> I have some watir tests for my form validation code. Basically, I try
> entering some invalid text, submitting, making sure I got an error, etc.
>
> The problem is that I cannot set a text field after the first form submit.
> When I try, I get this error:
>
>
> test_address_validation(LocatorTests):
> WIN32OLERuntimeError: unknown property or method `disabled'
> HRESULT error code:0x80070005
> Access is denied.
> C:/ruby/lib/ruby/gems/1.8/gems/watir-1.4.1/./watir.rb:2063:in `invoke'
> C:/ruby/lib/ruby/gems/1.8/gems/watir-1.4.1/./watir.rb:2063:in `enabled?'
> C:/ruby/lib/ruby/gems/1.8/gems/watir-1.4.1/./watir.rb:1932:in
> `assert_enabled'
> C:/ruby/lib/ruby/gems/1.8/gems/watir-1.4.1/./watir.rb:3383:in `set'
> LocatorTests.rb:43:in `test_address_validation'
>
>
> This is my test code:
>
> def setup
> #initialize browser
> @ie = IE.new
>
> #load the page
> @ie.goto("http://localhost/site/page.aspx")
> @ie.wait
>
> #find buttons and fields
> @locate_button = @ie.button( :value, "Locate" )
> @addr_field = @ie.text_field( :id, "AddrTxt")
> @city_field = @ie.text_field( :id, "CityTxt")
> @state_field = @ie.select_list( :id, "StateDropDown")
> @zip_field = @ie.text_field( :id, 'ZipTxt')
>
This code tries to resolve these objects at setup time. Your problem is
that after you load a page, none of these references are valid any more.
> end
>
> def test_address_validation
> #must enter a minimum of zip or both city and state
> @locate_button.click
> assert( @ie.contains_text("City and State, or Zip Code is required!")
> )
>
> @zip_field.set("asdf") #ERROR HERE!
> @locate_button.click
> assert( @ie.contains_text("Invalid Zip Code!") )
> end
>
> And there is nothing special about the Zip element:
>
> <input name="ZipTxt" type="text" maxlength="5" id="ZipTxt" title="Enter Zip
> Code" class="ZipStyle" />
>
>
> Any help would be appreciated,
> Gabe
>
The best approach would be to use methods rather than variables. Thus:
def locate_button
@ie.button( :value, "Locate" )
end
and then use
locate_button.click
in your test
Bret
_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general