Index: patch
===================================================================
--- patch (revision 123)
+++ patch (working copy)
@@ -3,183 +3,183 @@
--- FireWatir/unittests/checkbox_test.rb (revisão 110)
+++ FireWatir/unittests/checkbox_test.rb (cópia de trabalho)
@@ -19,6 +19,7 @@
- assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ff.checkbox(:name, "noName").value }

-

- assert_equal("box1" , $ff.checkbox(:index, 1).name )

-+ assert_instance_of(CheckBox,$ff.checkbox(:index,1))

- assert_equal("" , $ff.checkbox(:index, 1).id )

- assert_equal("checkbox" , $ff.checkbox(:index, 1).type )

- assert_equal("on" , $ff.checkbox(:index, 1).value )

+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ff.checkbox(:name, "noName").value }
+
+ assert_equal("box1" , $ff.checkbox(:index, 1).name )
++ assert_instance_of(CheckBox,$ff.checkbox(:index,1))
+ assert_equal("" , $ff.checkbox(:index, 1).id )
+ assert_equal("checkbox" , $ff.checkbox(:index, 1).type )
+ assert_equal("on" , $ff.checkbox(:index, 1).value )
Index: FireWatir/unittests/buttons_test.rb
===================================================================
--- FireWatir/unittests/buttons_test.rb (revisão 110)
+++ FireWatir/unittests/buttons_test.rb (cópia de trabalho)
@@ -124,10 +124,10 @@
- end

-

- def test_button2

-- assert($ff.button(:caption, "Click Me2").exists?)

-+ assert($ff.button(:caption, "Click Me2").exists?, 'Can\'t find Button with caption "Click Me2"')

-

-- assert($ff.button(:caption, "Disabled Button2").exists?)

-- assert($ff.button(:caption, "Sign In").exists?)

-+ assert($ff.button(:caption, "Disabled Button2").exists?, 'Can\'t find Button with caption "Disabled Button2"')

-+ assert($ff.button(:caption, "Sign In").exists?, 'Can\'t find Button with caption "Sign In"')

-

- assert_equal("b6" , $ff.button(:id, "b7").name )

- assert_equal("b7" , $ff.button(:name, "b6").id )

+ end
+
+ def test_button2
+- assert($ff.button(:caption, "Click Me2").exists?)
++ assert($ff.button(:caption, "Click Me2").exists?, 'Can\'t find Button with caption "Click Me2"')
+
+- assert($ff.button(:caption, "Disabled Button2").exists?)
+- assert($ff.button(:caption, "Sign In").exists?)
++ assert($ff.button(:caption, "Disabled Button2").exists?, 'Can\'t find Button with caption "Disabled Button2"')
++ assert($ff.button(:caption, "Sign In").exists?, 'Can\'t find Button with caption "Sign In"')
+
+ assert_equal("b6" , $ff.button(:id, "b7").name )
+ assert_equal("b7" , $ff.button(:name, "b6").id )
@@ -142,15 +142,15 @@
- assert_equal("" , $ff.button(:name, "b8").class_name )

- assert_equal("Sign In", $ff.button(:caption, "Sign In").value)

-

-- assert($ff.button(:caption, "Click Me").enabled?)

-+ assert($ff.button(:caption, "Click Me").enabled?, 'Button wih caption "Click Me" should be enabled')

-

-- assert_false($ff.button(:caption, "Disabled Button2").enabled?)

-+ assert_false($ff.button(:caption, "Disabled Button2").enabled?, 'Button wih caption "Disabled Button2" should be disabled')

-

-

- assert_raises(ObjectDisabledException , "ObjectDisabledException was supposed to be thrown" ) { $ff.button(:caption, "Disabled Button2").click }

-

- $ff.button(:caption, "Click Me2").click

-- assert($ff.text.include?("PASS"))

-+ assert($ff.text.include?("PASS"), 'Clicking on "Click Me2" button should\'ve taken to the "PASS" page')

-

- end

-

+ assert_equal("" , $ff.button(:name, "b8").class_name )
+ assert_equal("Sign In", $ff.button(:caption, "Sign In").value)
+
+- assert($ff.button(:caption, "Click Me").enabled?)
++ assert($ff.button(:caption, "Click Me").enabled?, 'Button wih caption "Click Me" should be enabled')
+
+- assert_false($ff.button(:caption, "Disabled Button2").enabled?)
++ assert_false($ff.button(:caption, "Disabled Button2").enabled?, 'Button wih caption "Disabled Button2" should be disabled')
+
+
+ assert_raises(ObjectDisabledException , "ObjectDisabledException was supposed to be thrown" ) { $ff.button(:caption, "Disabled Button2").click }
+
+ $ff.button(:caption, "Click Me2").click
+- assert($ff.text.include?("PASS"))
++ assert($ff.text.include?("PASS"), 'Clicking on "Click Me2" button should\'ve taken to the "PASS" page')
+
+ end
+
@@ -176,5 +176,39 @@
- assert_equal("Sign In",arrButtons[7].value)

- end

-

-+ def test_class_buttons

-+ arr_buttons = $ff.buttons

-+ arr_buttons.each do |b|

-+ assert(b.instance_of?(Button),"element class should be #{Button}; got #{b.class}")

- end

-+ # test properties

-+ assert_equal("b2", arr_buttons[1].id)

-+ assert_equal("b1", arr_buttons[1].name)

-+ assert_equal("button", arr_buttons[1].type)

-+ assert_equal("Click Me", arr_buttons[1].value)

-+ assert_equal(false, arr_buttons[1].disabled)

-+ assert_equal("italic_button", arr_buttons[1].class_name)

-+ assert_equal( "this is button1", arr_buttons[1].title)

-

-+ assert_equal("b5", arr_buttons[2].id)

-+ assert_equal("b4", arr_buttons[2].name)

-+ assert_equal("button", arr_buttons[2].type)

-+ assert_equal("Disabled Button", arr_buttons[2].value)

-+ assert_equal(true, arr_buttons[2].disabled)

-+ assert_equal( "", arr_buttons[2].title)

-+ assert_equal("", arr_buttons[2].class_name)

-+

-+ assert_equal("Submit", arr_buttons[3].value)

-+ assert_equal("sub3", arr_buttons[4].name)

-+ assert_equal("b7", arr_buttons[5].id)

-+ assert_equal("b9", arr_buttons[6].id)

-+ assert_equal("Sign In", arr_buttons[7].value)

-+

-+

-+

-+

-+ end

-+

-+

-+end

-+

+ assert_equal("Sign In",arrButtons[7].value)
+ end
+
++ def test_class_buttons
++ arr_buttons = $ff.buttons
++ arr_buttons.each do |b|
++ assert(b.instance_of?(Button),"element class should be #{Button}; got #{b.class}")
+ end
++ # test properties
++ assert_equal("b2", arr_buttons[1].id)
++ assert_equal("b1", arr_buttons[1].name)
++ assert_equal("button", arr_buttons[1].type)
++ assert_equal("Click Me", arr_buttons[1].value)
++ assert_equal(false, arr_buttons[1].disabled)
++ assert_equal("italic_button", arr_buttons[1].class_name)
++ assert_equal( "this is button1", arr_buttons[1].title)
+
++ assert_equal("b5", arr_buttons[2].id)
++ assert_equal("b4", arr_buttons[2].name)
++ assert_equal("button", arr_buttons[2].type)
++ assert_equal("Disabled Button", arr_buttons[2].value)
++ assert_equal(true, arr_buttons[2].disabled)
++ assert_equal( "", arr_buttons[2].title)
++ assert_equal("", arr_buttons[2].class_name)
++
++ assert_equal("Submit", arr_buttons[3].value)
++ assert_equal("sub3", arr_buttons[4].name)
++ assert_equal("b7", arr_buttons[5].id)
++ assert_equal("b9", arr_buttons[6].id)
++ assert_equal("Sign In", arr_buttons[7].value)
++
++
++
++
++ end
++
++
++end
++
Index: FireWatir/unittests/html/buttons1.html
===================================================================
--- FireWatir/unittests/html/buttons1.html (revisão 110)
+++ FireWatir/unittests/html/buttons1.html (cópia de trabalho)
@@ -17,8 +17,8 @@
- <input type = button class="italic_button" name = b1 id = b2 value = "Click Me" onClick="javascript:document.location='pass.html';" title = "this is button1">

- <br><input type = button name = b4 id=b5 value = "Disabled Button" onClick="javascript:document.location='fail.html';" disabled>

- <input type=text id="text_id" value="OldValue" size="20"/>

-+</form>

- </td>

--</form>

- <td> The top button is for testing buttons with names

- <br> The second button is used for testing disabled buttons

- </td>

+ <input type = button class="italic_button" name = b1 id = b2 value = "Click Me" onClick="javascript:document.location='pass.html';" title = "this is button1">
+ <br><input type = button name = b4 id=b5 value = "Disabled Button" onClick="javascript:document.location='fail.html';" disabled>
+ <input type=text id="text_id" value="OldValue" size="20"/>
++</form>
+ </td>
+-</form>
+ <td> The top button is for testing buttons with names
+ <br> The second button is used for testing disabled buttons
+ </td>
@@ -29,6 +29,7 @@
- <form name = test2 method = get action = pass2.html>

- <br><input type = submit value=Submit>

- </form>

-+</td>

- <td> This button is a submit ( the others are buttons)

- </td>

- </tr>

+ <form name = test2 method = get action = pass2.html>
+ <br><input type = submit value=Submit>
+ </form>
++</td>
+ <td> This button is a submit ( the others are buttons)
+ </td>
+ </tr>
@@ -36,6 +37,7 @@
- <td>

- <form name = test3 method = get action = pass3.html>

- <br><input type = image src=images/button.jpg name =sub3>

-+</form>

- </td>

- <td> This button is an image. It should behave the same as a submit

-

+ <td>
+ <form name = test3 method = get action = pass3.html>
+ <br><input type = image src=images/button.jpg name =sub3>
++</form>
+ </td>
+ <td> This button is an image. It should behave the same as a submit
+
@@ -43,7 +45,6 @@
- </tr>

- <tr>

- <td>

--</form>

- <form name = test1 method = get action = pass.html>

-

- <button class="italic_button" name=b6 id = b7 value="Click Me2" onClick="javascript:document.location='pass.html';" title="this is button2">Click Me2</button>

+ </tr>
+ <tr>
+ <td>
+-</form>
+ <form name = test1 method = get action = pass.html>
+
+ <button class="italic_button" name=b6 id = b7 value="Click Me2" onClick="javascript:document.location='pass.html';" title="this is button2">Click Me2</button>
@@ -56,4 +57,5 @@
- </td>

- </tr>

- </table>

-+</body>

- </html>

+ </td>
+ </tr>
+ </table>
++</body>
+ </html>
Index: FireWatir/unittests/bug_fixes_test.rb
===================================================================
--- FireWatir/unittests/bug_fixes_test.rb (revisão 110)
+++ FireWatir/unittests/bug_fixes_test.rb (cópia de trabalho)
@@ -24,6 +24,22 @@
- assert_equal("test_link", link.name)

- end

-

-+

-+ # element_by_xpath should return an element that's instance of the

-+ # appropriate class, not the generic Element class. So if it's a div,

-+ # it should return an instance of Div, if it's a checkbox, CheckBox,

-+ # and so on. TODO write tests for all classes

-+ def test_element_by_xpath_bug01

-+ $ff.goto($htmlRoot + "div.html")

-+ element = $ff.element_by_xpath("//div[@id='div1']")

-+ assert_not_nil(element) # helder

-+ # next assert always breaks, dunno why (error, not failure)

-+ #assert_instance_of(Div, element, "wrong constructor was used")

-+ # using this hack instead

-+ assert(element.instance_of?(Div),

-+ "element class should be: #{Div}; got: #{element.class}.")

-+ end

-+

- def test_elements_by_xpath_bug10

- $ff.goto($htmlRoot + "links1.html")

- elements = $ff.elements_by_xpath("//a")

+ assert_equal("test_link", link.name)
+ end
+
++
++ # element_by_xpath should return an element that's instance of the
++ # appropriate class, not the generic Element class. So if it's a div,
++ # it should return an instance of Div, if it's a checkbox, CheckBox,
++ # and so on. TODO write tests for all classes
++ def test_element_by_xpath_bug01
++ $ff.goto($htmlRoot + "div.html")
++ element = $ff.element_by_xpath("//div[@id='div1']")
++ assert_not_nil(element) # helder
++ # next assert always breaks, dunno why (error, not failure)
++ #assert_instance_of(Div, element, "wrong constructor was used")
++ # using this hack instead
++ assert(element.instance_of?(Div),
++ "element class should be: #{Div}; got: #{element.class}.")
++ end
++
+ def test_elements_by_xpath_bug10
+ $ff.goto($htmlRoot + "links1.html")
+ elements = $ff.elements_by_xpath("//a")
@@ -125,6 +141,6 @@
- $ff.file_field(:name, "file3").set("c:\\results.txt")

- $ff.button(:name, "upload").click()

- url = $ff.url

-- assert(url =~ /.*results.txt&upload=upload$/)

-+ assert_match(/.*results.txt&upload=upload$/,url)

- end

- end

+ $ff.file_field(:name, "file3").set("c:\\results.txt")
+ $ff.button(:name, "upload").click()
+ url = $ff.url
+- assert(url =~ /.*results.txt&upload=upload$/)
++ assert_match(/.*results.txt&upload=upload$/,url)
+ end
+ end
Index: FireWatir/firewatir.rb
===================================================================
--- FireWatir/firewatir.rb (revisão 110)
+++ FireWatir/firewatir.rb (cópia de trabalho)
@@ -201,6 +201,12 @@
- sleep waitTime

- # @@firefox_started = true

- #end

-+ elsif(RUBY_PLATFORM =~ /linux/i)

-+ puts RUBY_PLATFORM

-+ path_to_bin = `which firefox`.strip

-+ puts "#{path_to_bin} -jssh"

-+ @t = Thread.new { `#{path_to_bin} -jssh` }

-+ sleep waitTime

- end

-

- set_defaults()

+ sleep waitTime
+ # @@firefox_started = true
+ #end
++ elsif(RUBY_PLATFORM =~ /linux/i)
++ puts RUBY_PLATFORM
++ path_to_bin = `which firefox`.strip
++ puts "#{path_to_bin} -jssh"
++ @t = Thread.new { `#{path_to_bin} -jssh` }
++ sleep waitTime
+ end
+
+ set_defaults()
Index: htmlelements.rb
===================================================================
--- htmlelements.rb (revision 123)
+++ htmlelements.rb (working copy)
@@ -1108,7 +1108,7 @@
# - value - Value of that attribute.
#
def initialize (select_list, attribute, value)
- @select_list = select_list
+ @select_list = @container = select_list
@how = attribute
@what = value
@option = nil
Index: container.rb
===================================================================
--- container.rb (revision 123)
+++ container.rb (working copy)
@@ -816,7 +816,11 @@
# Test the index access.

# puts doc[35].to_s

end

-

+

+ def jssh_socket

+ @jssh_socket || @container.jssh_socket

+ end

+

#

# Description:

# Reads the javascript execution result from the jssh socket.

@@ -827,7 +831,7 @@
# Output:

# The javascript execution result as string.

#

- def read_socket(socket = $jssh_socket)

+ def read_socket(socket = jssh_socket)

return_value = ""

data = ""

#puts Thread.list

Index: MozillaBaseElement.rb
===================================================================
--- MozillaBaseElement.rb (revision 123)
+++ MozillaBaseElement.rb (working copy)
@@ -92,7 +92,7 @@
#if(@element_type == 'HTMLDivElement')
# ole_method_name = 'innerHTML'
#end
- $jssh_socket.send('typeof(' + element_object + '.#{ole_method_name});\n', 0)
+ jssh_socket.send('typeof(' + element_object + '.#{ole_method_name});\n', 0)
return_type = read_socket()

return_value = get_attribute_value(\"#{ole_method_name}\")
@@ -114,10 +114,10 @@
def get_attribute_value(attribute_name)
#if the attribut name is columnLength get number of cells in first row if rows exist.
if(attribute_name == "columnLength")
- $jssh_socket.send("#{element_object}.columns;\n", 0)
+ jssh_socket.send("#{element_object}.columns;\n", 0)
rowsLength = read_socket()
if(rowsLength != 0 || rowsLength != "")
- $jssh_socket.send("#{element_object}.rows[0].cells.length;\n", 0)
+ jssh_socket.send("#{element_object}.rows[0].cells.length;\n", 0)
return_value = read_socket()
return return_value
end
@@ -126,7 +126,7 @@
return text()
end
if(attribute_name == "url" or attribute_name == "href" or attribute_name == "src" or attribute_name == "action" or attribute_name == "name")
- $jssh_socket.send("#{element_object}.getAttribute(\"#{attribute_name}\");\n" , 0)
+ jssh_socket.send("#{element_object}.getAttribute(\"#{attribute_name}\");\n" , 0)
return_value = read_socket()
else
jssh_command = "var attribute = '';
@@ -136,19 +136,19 @@
attribute = #{element_object}.getAttribute(\"#{attribute_name}\");
attribute;"
jssh_command.gsub!("\n", "")
- $jssh_socket.send("#{jssh_command};\n", 0)
+ jssh_socket.send("#{jssh_command};\n", 0)
#puts jssh_command
return_value = read_socket()
end
if(attribute_name == "value")
- $jssh_socket.send("#{element_object}.tagName;\n", 0)
+ jssh_socket.send("#{element_object}.tagName;\n", 0)
tagName = read_socket().downcase
- $jssh_socket.send("#{element_object}.type;\n", 0)
+ jssh_socket.send("#{element_object}.type;\n", 0)
type = read_socket().downcase

if(tagName == "button" or type == "image" or type == "submit" or type == "reset" or type == "button")
if(return_value == "" or return_value == "null")
- $jssh_socket.send("#{element_object}.innerHTML;\n",0)
+ jssh_socket.send("#{element_object}.innerHTML;\n",0)
return_value = read_socket()
end
end
@@ -214,12 +214,12 @@

# TODO: Need to change this so that it would work if user sets any other color.
#puts "color is : #{DEFAULT_HIGHLIGHT_COLOR}"
- $jssh_socket.send("#{jssh_command}\n", 0)
+ jssh_socket.send("#{jssh_command}\n", 0)
@original_color = read_socket()

else # BUG: assumes is :clear, but could actually be anything
begin
- $jssh_socket.send("#{element_object}.style.background = \"#{@original_color}\";\n", 0)
+ jssh_socket.send("#{element_object}.style.background = \"#{@original_color}\";\n", 0)
read_socket()
rescue
# we could be here for a number of reasons...
@@ -241,7 +241,7 @@
def get_rows()
#puts "#{element_object} and #{element_type}"
if(element_type == "HTMLTableElement")
- $jssh_socket.send("#{element_object}.rows.length;\n", 0)
+ jssh_socket.send("#{element_object}.rows.length;\n", 0)
length = read_socket().to_i
#puts "The number of rows in the table are : #{no_of_rows}"
return_array = Array.new(length)
@@ -473,7 +473,7 @@
# Remove \n that are there in the string as a result of pressing enter while formatting.
jssh_command.gsub!(/\n/, "")
#puts jssh_command
- $jssh_socket.send("#{jssh_command};\n", 0)
+ jssh_socket.send("#{jssh_command};\n", 0)
element_name = read_socket();
#puts "element name in find control is : #{element_name}"
@@current_level = @@current_level + 1
@@ -592,7 +592,7 @@
jssh_command.gsub!("\n", "")
#puts "jssh_command for finding frame is : #{jssh_command}"

- $jssh_socket.send("#{jssh_command};\n", 0)
+ jssh_socket.send("#{jssh_command};\n", 0)
element_name = read_socket()
@@current_level = @@current_level + 1
#puts "element_name for frame is : #{element_name}"
@@ -605,15 +605,15 @@
end

def get_frame_html
- $jssh_socket.send("var htmlelem = #{DOCUMENT_VAR}.getElementsByTagName('html')[0]; htmlelem.innerHTML;\n", 0)
- #$jssh_socket.send("#{BODY_VAR}.innerHTML;\n", 0)
+ jssh_socket.send("var htmlelem = #{DOCUMENT_VAR}.getElementsByTagName('html')[0]; htmlelem.innerHTML;\n", 0)
+ #jssh_socket.send("#{BODY_VAR}.innerHTML;\n", 0)
result = read_socket()
return "<html>" + result + "</html>"
end

def submit_form
#puts "form name is : #{element_object}"
- $jssh_socket.send("#{element_object}.submit();\n" , 0)
+ jssh_socket.send("#{element_object}.submit();\n" , 0)
read_socket()
end

@@ -668,7 +668,7 @@
def elements_by_xpath(container, xpath)
rand_no = rand(1000)
#jssh_command = "var xpathResult = #{DOCUMENT_VAR}.evaluate(\"count(#{xpath})\", #{DOCUMENT_VAR}, null, #{NUMBER_TYPE}, null); xpathResult.numberValue;"
- #$jssh_socket.send("#{jssh_command}\n", 0);
+ #jssh_socket.send("#{jssh_command}\n", 0);
#node_count = read_socket()

jssh_command = "var element_xpath_#{rand_no} = new Array();"
@@ -686,7 +686,7 @@
# Remove \n that are there in the string as a result of pressing enter while formatting.
jssh_command.gsub!(/\n/, "")
#puts jssh_command
- $jssh_socket.send("#{jssh_command};\n", 0)
+ jssh_socket.send("#{jssh_command};\n", 0)
node_count = read_socket()
#puts "value of count is : #{node_count}"

@@ -717,7 +717,7 @@
rand_no = rand(1000)
jssh_command = "var element_xpath_#{rand_no} = null; element_xpath_#{rand_no} = #{DOCUMENT_VAR}.evaluate(\"#{xpath}\", #{DOCUMENT_VAR}, null, #{FIRST_ORDERED_NODE_TYPE}, null).singleNodeValue; element_xpath_#{rand_no};"

- $jssh_socket.send("#{jssh_command}\n", 0)
+ jssh_socket.send("#{jssh_command}\n", 0)
result = read_socket()
#puts "command send to jssh is : #{jssh_command}"
#puts "result is : #{result}"
@@ -761,7 +761,7 @@
def element_type
#puts "in element_type object is : #{element_object}"
# Get the type of the element.
- $jssh_socket.send("#{element_object};\n", 0)
+ jssh_socket.send("#{element_object};\n", 0)
temp = read_socket()

if temp == ""
@@ -801,7 +801,7 @@
event = $1 if $1

# check if we've got an old-school on-event
- #$jssh_socket.send("typeof(#{element_object}.#{event});\n", 0)
+ #jssh_socket.send("typeof(#{element_object}.#{event});\n", 0)
#is_defined = read_socket()

# info about event types harvested from:
@@ -840,7 +840,7 @@

#puts "JSSH COMMAND:\n#{jssh_command}\n"

- $jssh_socket.send("#{jssh_command}\n", 0)
+ jssh_socket.send("#{jssh_command}\n", 0)
read_socket() if wait
wait() if wait

@@ -890,7 +890,7 @@
#
def enabled?
assert_exists
- $jssh_socket.send("#{element_object}.disabled;\n", 0)
+ jssh_socket.send("#{element_object}.disabled;\n", 0)
value = read_socket()
@@current_level = 0
return true if(value == "false")
@@ -941,9 +941,9 @@
assert_exists

if(element_type == "HTMLFrameElement")
- $jssh_socket.send("#{BODY_VAR}.textContent;\n", 0)
+ jssh_socket.send("#{BODY_VAR}.textContent;\n", 0)
else
- $jssh_socket.send("#{element_object}.textContent;\n", 0)
+ jssh_socket.send("#{element_object}.textContent;\n", 0)
end

return_value = read_socket().strip()
@@ -1038,15 +1038,15 @@
jssh_command += "#{element_object}.dispatchEvent(event);\n"

#puts "jssh_command is: #{jssh_command}"
- $jssh_socket.send("#{jssh_command}", 0)
+ jssh_socket.send("#{jssh_command}", 0)
read_socket()
else
- $jssh_socket.send("typeof(#{element_object}.click);\n", 0)
+ jssh_socket.send("typeof(#{element_object}.click);\n", 0)
isDefined = read_socket()
if(isDefined == "undefined")
fire_event("onclick")
else
- $jssh_socket.send("#{element_object}.click();\n" , 0)
+ jssh_socket.send("#{element_object}.click();\n" , 0)
read_socket()
end
end
@@ -1109,12 +1109,12 @@
# win.confirm = function(param) {popuptext = param; return false; };"
# end
# jssh_command.gsub!(/\n/, "")
- # $jssh_socket.send("#{jssh_command}\n", 0)
+ # jssh_socket.send("#{jssh_command}\n", 0)
# read_socket()
# click_js_popup_creator_button()
- # #$jssh_socket.send("popuptext_alert;\n", 0)
+ # #jssh_socket.send("popuptext_alert;\n", 0)
# #read_socket()
- # $jssh_socket.send("\n", 0)
+ # jssh_socket.send("\n", 0)
# read_socket()
#end

@@ -1125,7 +1125,7 @@
#
#def click_js_popup_creator_button
# #puts @@current_js_object.element_name
- # $jssh_socket.send("#{@@current_js_object.element_name}\n;", 0)
+ # jssh_socket.send("#{@@current_js_object.element_name}\n;", 0)
# temp = read_socket()
# temp =~ /\[object\s(.*)\]/
# if $1
@@ -1144,10 +1144,10 @@
# jssh_command += "event.initMouseEvent('click',true,true,null,1,0,0,0,0,false,false,false,false,0,null);"
# jssh_command += "#{@@current_js_object.element_name}.dispatchEvent(event);\n"
#
- # $jssh_socket.send("#{jssh_command}", 0)
+ # jssh_socket.send("#{jssh_command}", 0)
# read_socket()
# when "HTMLDivElement", "HTMLSpanElement"
- # $jssh_socket.send("typeof(#{element_object}.#{event.downcase});\n", 0)
+ # jssh_socket.send("typeof(#{element_object}.#{event.downcase});\n", 0)
# isDefined = read_socket()
# #puts "is method there : #{isDefined}"
# if(isDefined != "undefined")
@@ -1156,16 +1156,16 @@
# event.initEvent(\"click\", true, true);
# #{element_object}.dispatchEvent(event);"
# jssh_command.gsub!(/\n/, "")
- # $jssh_socket.send("#{jssh_command}\n", 0)
+ # jssh_socket.send("#{jssh_command}\n", 0)
# read_socket()
# else
- # $jssh_socket.send("#{element_object}.#{event.downcase}();\n", 0)
+ # jssh_socket.send("#{element_object}.#{event.downcase}();\n", 0)
# read_socket()
# end
# end
# else
# jssh_command = "#{@@current_js_object.element_name}.click();\n";
- # $jssh_socket.send("#{jssh_command}", 0)
+ # jssh_socket.send("#{jssh_command}", 0)
# read_socket()
# end
# @@current_level = 0
@@ -1181,7 +1181,7 @@
# Array of option elements.
#
def options
- $jssh_socket.send("#{element_object}.options.length;\n", 0)
+ jssh_socket.send("#{element_object}.options.length;\n", 0)
length = read_socket().to_i
#puts "options length is : #{length}"
arr_options = Array.new(length)
@@ -1200,7 +1200,7 @@
# Class name of option element.
#
def option_class_name
- $jssh_socket.send("#{element_object}.className;\n", 0)
+ jssh_socket.send("#{element_object}.className;\n", 0)
return read_socket()
end
private :option_class_name
@@ -1213,7 +1213,7 @@
# Text of option element.
#
def option_text
- $jssh_socket.send("#{element_object}.text;\n", 0)
+ jssh_socket.send("#{element_object}.text;\n", 0)
return read_socket()
end
private :option_text
@@ -1226,7 +1226,7 @@
# Value of option element.
#
def option_value
- $jssh_socket.send("#{element_object}.value;\n", 0)
+ jssh_socket.send("#{element_object}.value;\n", 0)
return read_socket()
end
private :option_value
@@ -1239,7 +1239,7 @@
# True if option is selected, false otherwise.
#
def option_selected
- $jssh_socket.send("#{element_object}.selected;\n", 0)
+ jssh_socket.send("#{element_object}.selected;\n", 0)
value = read_socket()
return true if value == "true"
return false if value == "false"
@@ -1257,7 +1257,7 @@
assert_exists
#puts "element name in cells is : #{element_object}"
if(element_type == "HTMLTableRowElement")
- $jssh_socket.send("#{element_object}.cells.length;\n", 0)
+ jssh_socket.send("#{element_object}.cells.length;\n", 0)
length = read_socket.to_i
return_array = Array.new(length)
for i in 0..length - 1 do
@@ -1291,7 +1291,7 @@
#jssh_command += "textBox.value = \"#{setPath}\";\n";

#puts jssh_command
- $jssh_socket.send("#{element_object}.value = \"#{setPath}\";\n", 0)
+ jssh_socket.send("#{element_object}.value = \"#{setPath}\";\n", 0)
read_socket()
@@current_level = 0
end
@@ -1319,7 +1319,7 @@
jssh_command += i;
end
#puts "#{jssh_command}"
- $jssh_socket.send("#{jssh_command};\n", 0)
+ jssh_socket.send("#{jssh_command};\n", 0)
return_value = read_socket()
#puts "return value is : #{return_value}"
return return_value
@@ -1339,7 +1339,7 @@
end
#puts "temp is : #{temp}"

- $jssh_socket.send("typeof(#{temp});\n", 0)
+ jssh_socket.send("typeof(#{temp});\n", 0)
method_type = read_socket()
#puts "method_type is : #{method_type}"

@@ -1353,7 +1353,7 @@
jssh_command = "#{element_object}.#{methodName}#{args[0]}"
end
#puts "jssh_command is : #{jssh_command}"
- $jssh_socket.send("#{jssh_command};\n", 0)
+ jssh_socket.send("#{jssh_command};\n", 0)
read_socket()
return
end
@@ -1391,7 +1391,7 @@
jssh_command = jssh_command.gsub("\"true\"", "true")
end
#puts "jssh_command is #{jssh_command}"
- $jssh_socket.send("#{jssh_command}", 0)
+ jssh_socket.send("#{jssh_command}", 0)
returnValue = read_socket()
#puts "return value is : #{returnValue}"

@@ -1467,7 +1467,7 @@
# Remove \n that are there in the string as a result of pressing enter while formatting.
jssh_command.gsub!(/\n/, "")
#puts jssh_command
- $jssh_socket.send("#{jssh_command};\n", 0)
+ jssh_socket.send("#{jssh_command};\n", 0)
@length = read_socket().to_i;
#puts "elements length is in locate_tagged_elements is : #{@length}"

@@ -1526,7 +1526,7 @@
# Array containing Form elements
#
def get_forms()
- $jssh_socket.send("var element_forms = #{DOCUMENT_VAR}.forms; element_forms.length;\n", 0)
+ jssh_socket.send("var element_forms = #{DOCUMENT_VAR}.forms; element_forms.length;\n", 0)
length = read_socket().to_i
forms = Array.new(length)

@@ -1729,7 +1729,7 @@
# Remove \n that are there in the string as a result of pressing enter while formatting.
jssh_command.gsub!(/\n/, "")
#puts jssh_command
- $jssh_socket.send("#{jssh_command};\n", 0)
+ jssh_socket.send("#{jssh_command};\n", 0)
length = read_socket().to_i;
#puts "elements length is in locate_tagged_elements is : #{length}"

Index: firewatir.rb
===================================================================
--- firewatir.rb (revision 123)
+++ firewatir.rb (working copy)
@@ -184,11 +184,13 @@
#

def initialize(options = {})
+ @port = options[:port] || 9997
+
if(options.kind_of?(Integer))
options = {:waitTime => options}
end

- if(options[:profile])
+ if(options[:profile] ||= ENV['WATIR_PROFILE'])
profile_opt = "-P #{options[:profile]}"
else
profile_opt = ""
@@ -215,12 +217,12 @@

puts "Starting Firefox using the executable : #{path_to_exe}"
puts "Waiting for #{waitTime} seconds for Firefox to get started."
- @t = Thread.new { system("\"#{path_to_exe}\" -jssh #{profile_opt}") }
+ @t = Thread.new { system("\"#{path_to_exe}\" -no-remote -jssh #{@port} #{profile_opt}") }
elsif(RUBY_PLATFORM =~ /linux/i)
puts RUBY_PLATFORM
path_to_bin = `which firefox`.strip
- puts "#{path_to_bin} -jssh #{profile_opt}"
- @t = Thread.new { `#{path_to_bin} -jssh #{profile_opt}` }
+ puts "#{path_to_bin} -jssh #{@port} #{profile_opt}"
+ @t = Thread.new { `#{path_to_bin} -jssh #{@port} #{profile_opt}` }
end

sleep waitTime
@@ -251,7 +253,7 @@
# Gets the window number opened. Used internally by Firewatir.
#
def get_window_number()
- $jssh_socket.send("getWindows().length;\n", 0)
+ @jssh_socket.send("getWindows().length;\n", 0)
@@current_window = read_socket().to_i - 1
# This will store the information about the window.
#@@window_stack.push(@@current_window)
@@ -272,7 +274,7 @@
get_window_number()
set_browser_document()
# Load the given url.
- $jssh_socket.send("#{BROWSER_VAR}.loadURI(\"#{url}\");\n" , 0)
+ @jssh_socket.send("#{BROWSER_VAR}.loadURI(\"#{url}\");\n" , 0)
read_socket()

wait()
@@ -284,7 +286,7 @@
#
def back()
#set_browser_document()
- $jssh_socket.send("if(#{BROWSER_VAR}.canGoBack) #{BROWSER_VAR}.goBack();\n", 0)
+ @jssh_socket.send("if(#{BROWSER_VAR}.canGoBack) #{BROWSER_VAR}.goBack();\n", 0)
read_socket();
wait()
end
@@ -295,7 +297,7 @@
#
def forward()
#set_browser_document()
- $jssh_socket.send("if(#{BROWSER_VAR}.canGoForward) #{BROWSER_VAR}.goForward();\n", 0)
+ @jssh_socket.send("if(#{BROWSER_VAR}.canGoForward) #{BROWSER_VAR}.goForward();\n", 0)
read_socket();
wait()
end
@@ -306,7 +308,7 @@
#
def refresh()
#set_browser_document()
- $jssh_socket.send("#{BROWSER_VAR}.reload();\n", 0)
+ @jssh_socket.send("#{BROWSER_VAR}.reload();\n", 0)
read_socket();
wait()
end
@@ -317,15 +319,14 @@
# Generatesi UnableToStartJSShException if cannot connect to jssh even after 3 tries.
#
def set_defaults(no_of_tries = 0)
- # JSSH listens on port 9997. Create a new socket to connect to port 9997.
begin
- $jssh_socket = TCPSocket::new(MACHINE_IP, "9997")
- $jssh_socket.sync = true
+ @jssh_socket = TCPSocket::new(MACHINE_IP, @port)
+ @jssh_socket.sync = true
read_socket()
rescue
no_of_tries += 1
retry if no_of_tries < 3
- raise UnableToStartJSShException, "Unable to connect to machine : #{MACHINE_IP} on port 9997. Make sure that JSSh is properly installed and Firefox is running with '-jssh' option"
+ raise UnableToStartJSShException, "Unable to connect to machine : #{MACHINE_IP} on port #{@port}. Make sure that JSSh is properly installed and Firefox is running with '-jssh' option [#{$!.inspect}]"
end
end
private :set_defaults
@@ -349,13 +350,13 @@
jssh_command += "var #{DOCUMENT_VAR} = #{BROWSER_VAR}.contentDocument;"
jssh_command += "var #{BODY_VAR} = #{DOCUMENT_VAR}.body;"

- $jssh_socket.send("#{jssh_command}\n", 0)
+ @jssh_socket.send("#{jssh_command}\n", 0)
read_socket()

# Get window and window's parent title and url
- $jssh_socket.send("#{DOCUMENT_VAR}.title;\n", 0)
+ @jssh_socket.send("#{DOCUMENT_VAR}.title;\n", 0)
@window_title = read_socket()
- $jssh_socket.send("#{DOCUMENT_VAR}.URL;\n", 0)
+ @jssh_socket.send("#{DOCUMENT_VAR}.URL;\n", 0)
@window_url = read_socket()
end
private :set_browser_document
@@ -367,7 +368,7 @@
def close()
#puts "current window number is : #{@@current_window}"
if @@current_window == 0
- $jssh_socket.send(" getWindows()[0].close(); \n", 0)
+ @jssh_socket.send(" getWindows()[0].close(); \n", 0)
@t.join
#sleep 5
else
@@ -377,7 +378,7 @@

# If matching window found. Close the window.
if(window_number > 0)
- $jssh_socket.send(" getWindows()[#{window_number}].close();\n", 0)
+ @jssh_socket.send(" getWindows()[#{window_number}].close();\n", 0)
read_socket();
end

@@ -424,7 +425,7 @@
#
def find_window(how, what)
jssh_command = "getWindows().length;";
- $jssh_socket.send("#{jssh_command}\n", 0)
+ @jssh_socket.send("#{jssh_command}\n", 0)
@@total_windows = read_socket()
#puts "total windows are : " + @@total_windows.to_s

@@ -473,7 +474,7 @@

jssh_command.gsub!(/\n/, "")
#puts "jssh_command is : #{jssh_command}"
- $jssh_socket.send("#{jssh_command}\n", 0)
+ @jssh_socket.send("#{jssh_command}\n", 0)
window_number = read_socket()
#puts "window number is : " + window_number.to_s

@@ -534,8 +535,8 @@
# HTML shown on the page.
#
def html()
- $jssh_socket.send("var htmlelem = #{DOCUMENT_VAR}.getElementsByTagName('html')[0]; htmlelem.innerHTML;\n", 0)
- #$jssh_socket.send("#{BODY_VAR}.innerHTML;\n", 0)
+ @jssh_socket.send("var htmlelem = #{DOCUMENT_VAR}.getElementsByTagName('html')[0]; htmlelem.innerHTML;\n", 0)
+ #@jssh_socket.send("#{BODY_VAR}.innerHTML;\n", 0)
result = read_socket()
return "<html>" + result + "</html>"
end
@@ -548,7 +549,7 @@
# Text shown on the page.
#
def text()
- $jssh_socket.send("#{BODY_VAR}.textContent;\n", 0)
+ @jssh_socket.send("#{BODY_VAR}.textContent;\n", 0)
return read_socket().strip
end

@@ -557,7 +558,7 @@
# Maximize the current browser window.
#
def maximize()
- $jssh_socket.send("#{WINDOW_VAR}.maximize();\n", 0)
+ @jssh_socket.send("#{WINDOW_VAR}.maximize();\n", 0)
read_socket()
end

@@ -566,7 +567,7 @@
# Minimize the current browser window.
#
def minimize()
- $jssh_socket.send("#{WINDOW_VAR}.minimize();\n", 0)
+ @jssh_socket.send("#{WINDOW_VAR}.minimize();\n", 0)
read_socket()
end

@@ -578,7 +579,7 @@
#puts "In wait function "
isLoadingDocument = ""
while isLoadingDocument != "false"
- $jssh_socket.send("#{BROWSER_VAR}=#{WINDOW_VAR}.getBrowser(); #{BROWSER_VAR}.webProgress.isLoadingDocument;\n" , 0)
+ @jssh_socket.send("#{BROWSER_VAR}=#{WINDOW_VAR}.getBrowser(); #{BROWSER_VAR}.webProgress.isLoadingDocument;\n" , 0)
isLoadingDocument = read_socket()
#puts "Is browser still loading page: #{isLoadingDocument}"
end
@@ -622,7 +623,7 @@
wait;"
#puts "command in wait is : #{jssh_command}"
jssh_command = jssh_command.gsub(/\n/, "")
- $jssh_socket.send("#{jssh_command}; \n", 0)
+ @jssh_socket.send("#{jssh_command}; \n", 0)
wait_time = read_socket();
#puts "wait time is : #{wait_time}"
begin
@@ -630,7 +631,7 @@
if(wait_time != -1)
sleep(wait_time)
# Call wait again. In case there are multiple redirects.
- $jssh_socket.send("#{BROWSER_VAR} = #{WINDOW_VAR}.getBrowser(); \n",0)
+ @jssh_socket.send("#{BROWSER_VAR} = #{WINDOW_VAR}.getBrowser(); \n",0)
read_socket()
wait()
end
@@ -729,7 +730,7 @@
end
jssh_command.gsub!(/\n/, "")
#puts "jssh command sent for js pop up is : #{jssh_command}"
- $jssh_socket.send("#{jssh_command}\n", 0)
+ @jssh_socket.send("#{jssh_command}\n", 0)
read_socket()
end

@@ -741,10 +742,10 @@
# Text shown in javascript pop up.
#
def get_popup_text()
- $jssh_socket.send("popuptext;\n", 0)
+ @jssh_socket.send("popuptext;\n", 0)
return_value = read_socket()
# reset the variable
- $jssh_socket.send("popuptexti = '';\n", 0)
+ @jssh_socket.send("popuptexti = '';\n", 0)
read_socket()
return return_value
end
@@ -786,7 +787,7 @@
candidate_class = jssh_type =~ /HTML(.*)Element/ ? $1 : ''
#puts candidate_class # DEBUG
if candidate_class == 'Input'
- $jssh_socket.send("#{element_name}.type;\n", 0)
+ @jssh_socket.send("#{element_name}.type;\n", 0)
input_type = read_socket().downcase.strip
puts input_type # DEBUG
firewatir_class = input_class(input_type)
@@ -1065,7 +1066,7 @@
elements_frames.length;"

jssh_command.gsub!("\n", "")
- $jssh_socket.send("#{jssh_command};\n", 0)
+ @jssh_socket.send("#{jssh_command};\n", 0)
length = read_socket().to_i

puts "There are #{length} frames"