This repository has been archived by the owner on Jun 6, 2018. It is now read-only.
/
textarea_xpath_test.rb
77 lines (59 loc) · 4.99 KB
/
textarea_xpath_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# feature tests for TextArea Fields
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
require 'unittests/setup'
class TC_TextArea_XPath < Test::Unit::TestCase
include Watir::Exception
def setup
goto_page "textArea.html"
end
def test_textarea_field_exists
#test for existance of 4 text area
assert(browser.text_field(:xpath , "//textarea[@name='txtMultiLine1']/").exists?)
assert(browser.text_field(:xpath , "//textarea[@name='txtMultiLine2']/").exists?)
assert(browser.text_field(:xpath , "//textarea[@name='txtMultiLine3']/").exists?)
assert(browser.text_field(:xpath , "//textarea[@name='txtReadOnly']/").exists?)
assert(browser.text_field(:xpath , "//textarea[@id='txtMultiLine1']/").exists?)
assert(browser.text_field(:xpath , "//textarea[@id='txtMultiLine2']/").exists?)
assert(browser.text_field(:xpath , "//textarea[@id='txtMultiLine3']/").exists?)
assert(browser.text_field(:xpath , "//textarea[@id='txtReadOnly']/").exists?)
#test for missing
assert_false(browser.text_field(:xpath , "//textarea[@name='missing']/").exists?)
assert_false(browser.text_field(:xpath , "//textarea[@name='txtMultiLine4']/").exists?)
end
def xtest_textarea_to_s
# bug reported by Zeljko Filipin
# assert_nothing_raised { browser.text_field(:xpath , "//textarea[@id='txtMultiLine3']/").to_s }
# The above assertion fails. No property or method called maxlength
end
def test_textarea_field
# test for read only method
assert_false(browser.text_field(:xpath , "//textarea[@name='txtMultiLine1']/").readonly? )
assert(browser.text_field(:xpath , "//textarea[@name='txtReadOnly']/").readonly?)
# test for enabled? method
assert_false(browser.text_field(:xpath , "//textarea[@name='txtDisabled']/").enabled? )
assert(browser.text_field(:xpath , "//textarea[@id='txtMultiLine1']/").enabled? )
t1 = browser.text_field(:xpath , "//textarea[@name='txtMultiLine1']/")
assert(t1.verify_contains("Hello World") )
assert(t1.verify_contains(/el/) )
t2 = browser.text_field(:xpath , "//textarea[@name='txtMultiLine2']/")
assert(t2.verify_contains(/IE/))
assert_raises(UnknownObjectException) { browser.text_field(:xpath , "//textarea[@name='NoName']/").verify_contains("No field to get a value of") }
assert_raises(UnknownObjectException) { browser.text_field(:xpath , "//textarea[@id='noID']/").verify_contains("No field to get a value of") }
assert_raises(UnknownObjectException , "ObjectReadOnlyException was supposed to be thrown" ) { browser.text_field(:xpath , "//textarea[@name='txtNone']/").append("Some Text") }
assert_raises(ObjectReadOnlyException , "ObjectReadOnlyException was supposed to be thrown" ) { browser.text_field(:xpath , "//textarea[@id='txtReadOnly']/").append("Some Text") }
assert_raises(ObjectDisabledException , "ObjectDisabledException was supposed to be thrown" ) { browser.text_field(:xpath , "//textarea[@name='txtDisabled']/").append("Some Text") }
assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { browser.text_field(:xpath , "//textarea[@name='missing_field']/").append("Some Text") }
browser.text_field(:xpath , "//textarea[@name='txtMultiLine1']/").append(" Some Text")
assert_equal( "Hello World Some Text" , browser.text_field(:xpath , "//textarea[@name='txtMultiLine1']/").value)
assert_raises(ObjectReadOnlyException , "ObjectReadOnlyException was supposed to be thrown" ) { browser.text_field(:xpath , "//textarea[@id='txtReadOnly']/").append("Some Text") }
assert_raises(ObjectDisabledException , "ObjectReadOnlyException was supposed to be thrown" ) { browser.text_field(:xpath , "//textarea[@name='txtDisabled']/").append("Some Text") }
assert_raises(UnknownObjectException , "ObjectReadOnlyException was supposed to be thrown" ) { browser.text_field(:xpath , "//textarea[@name='missing_field']/").append("Some Text") }
browser.text_field(:xpath , "//textarea[@name='txtMultiLine1']/").set("watir IE Controller")
assert_equal( "watir IE Controller" , browser.text_field(:xpath , "//textarea[@name='txtMultiLine1']/").value )
assert_raises(ObjectReadOnlyException , "ObjectReadOnlyException was supposed to be thrown" ) { browser.text_field(:xpath , "//textarea[@id='txtReadOnly']/").append("Some Text") }
assert_raises(ObjectDisabledException , "ObjectReadOnlyException was supposed to be thrown" ) { browser.text_field(:xpath , "//textarea[@name='txtDisabled']/").append("Some Text") }
assert_raises(UnknownObjectException , "ObjectReadOnlyException was supposed to be thrown" ) { browser.text_field(:xpath , "//textarea[@name='missing_field']/").append("Some Text") }
browser.text_field(:xpath , "//textarea[@name='txtMultiLine2']/").clear
assert_equal( "" , browser.text_field(:xpath , "//textarea[@name='txtMultiLine2']/").value )
end
end