Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Ruby Client: Made client methods a module

git-svn-id: https://svn.openqa.org/svn/selenium-rc/trunk/clients/ruby@2273 0891141a-5dea-0310-ad27-ebc607f31677
  • Loading branch information...
commit eb360361ac5381e506d7650406cac7147af7f98a 1 parent 1b3bf17
ph7 authored
View
4 build.xml
@@ -2,7 +2,7 @@
<target name="generate-sources">
<mkdir dir="target"/>
- <xslt in="target/iedoc.xml" out="lib/selenium/generated_driver.rb" style="iedoc2ruby.xml"/>
+ <xslt in="target/iedoc.xml" out="lib/selenium/client/generated_driver.rb" style="iedoc2ruby.xml"/>
</target>
<target name="doc">
@@ -14,7 +14,7 @@
<arg value="lib/selenium.rb"/>
<arg value="lib/selenium/command_error.rb"/>
<arg value="lib/selenium/driver.rb"/>
- <arg value="lib/selenium/generated_driver.rb"/>
+ <arg value="lib/selenium/client/generated_driver.rb"/>
<arg value="lib/selenium/selenium_helper.rb"/>
</exec>
</target>
View
9 iedoc2ruby.xml
@@ -15,8 +15,9 @@
<xsl:apply-templates select="//top" />
<xsl:apply-templates select="//function" />
<xsl:text disable-output-escaping="yes">
- end
-end
+ end # GeneratedDriver
+ end # Client
+end # Selenium
</xsl:text>
</xsl:template>
@@ -52,8 +53,8 @@ TOP
</xsl:apply-templates>
<xsl:text disable-output-escaping="yes"><![CDATA[
module Selenium
-
- class Driver
+ module Client
+ module GeneratedDriver
]]>
</xsl:text>
View
13 lib/selenium.rb
@@ -22,13 +22,14 @@
require 'uri'
require 'cgi'
require File.expand_path(File.dirname(__FILE__) + '/selenium/command_error')
-require File.expand_path(File.dirname(__FILE__) + '/selenium/selenese_client')
-require File.expand_path(File.dirname(__FILE__) + '/selenium/driver')
-require File.expand_path(File.dirname(__FILE__) + '/selenium/generated_driver')
-require File.expand_path(File.dirname(__FILE__) + '/selenium/selenium_helper')
+require File.expand_path(File.dirname(__FILE__) + '/selenium/client/selenese_client')
+require File.expand_path(File.dirname(__FILE__) + '/selenium/client/generated_driver')
+require File.expand_path(File.dirname(__FILE__) + '/selenium/client/base')
+require File.expand_path(File.dirname(__FILE__) + '/selenium/client/driver')
+require File.expand_path(File.dirname(__FILE__) + '/selenium/client/selenium_helper')
# Backward compatibility
-SeleniumHelper = Selenium::SeleniumHelper
+SeleniumHelper = Selenium::Client::SeleniumHelper
SeleniumCommandError = Selenium::CommandError
-Selenium::SeleniumDriver = Selenium::Driver
+Selenium::SeleniumDriver = Selenium::Client::Driver
View
52 lib/selenium/driver.rb → lib/selenium/client/base.rb
@@ -12,38 +12,36 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-
-# -----------------
+#
+#
# Original code by Aslak Hellesoy and Darren Hobbs
-# This file has been automatically generated via XSL
-# -----------------
-
+#
module Selenium
-
- class Driver
- include SeleneseClient
+ module Client
+
+ module Base
+ include Selenium::Client::SeleneseClient
+ include Selenium::Client::GeneratedDriver
- def initialize(server_host, server_port, browserStartCommand, browserURL, timeout=30000)
- @server_host = server_host
- @server_port = server_port
- @browserStartCommand = browserStartCommand
- @browserURL = browserURL
- @timeout = timeout
- end
+ def initialize(server_host, server_port, browserStartCommand, browserURL, timeout=30000)
+ @server_host = server_host
+ @server_port = server_port
+ @browserStartCommand = browserStartCommand
+ @browserURL = browserURL
+ @timeout = timeout
+ end
- def to_s
- "Selenium Driver"
- end
-
- def start()
- result = get_string("getNewBrowserSession", [@browserStartCommand, @browserURL])
- @session_id = result
- end
+ def start()
+ result = get_string("getNewBrowserSession", [@browserStartCommand, @browserURL])
+ @session_id = result
+ end
- def stop()
- do_command("testComplete", [])
- @session_id = nil
- end
+ def stop()
+ do_command("testComplete", [])
+ @session_id = nil
+ end
+ end
+
end
end
View
9 lib/selenium/client/driver.rb
@@ -0,0 +1,9 @@
+module Selenium
+ module Client
+
+ class Driver
+ include Selenium::Client::Base
+ end
+
+ end
+end
View
95 lib/selenium/client/selenese_client.rb
@@ -0,0 +1,95 @@
+module Selenium
+ module Client
+
+ module SeleneseClient
+
+ def do_command(verb, args)
+ timeout(@timeout) do
+ http = Net::HTTP.new(@server_host, @server_port)
+ command_string = '/selenium-server/driver/?cmd=' + CGI::escape(verb)
+ args.length.times do |i|
+ arg_num = (i+1).to_s
+ command_string = command_string + "&" + arg_num + "=" + CGI::escape(args[i].to_s)
+ end
+ if @session_id != nil
+ command_string = command_string + "&sessionId=" + @session_id.to_s
+ end
+ #print "Requesting --->" + command_string + "\n"
+ response = http.get(command_string)
+ #print "RESULT: " + response.body + "\n\n"
+ if (response.body[0..1] != "OK")
+ raise SeleniumCommandError, response.body
+ end
+ return response.body
+ end
+ end
+
+ def get_string(verb, args)
+ result = do_command(verb, args)
+ return result[3..result.length]
+ end
+
+ def get_string_array(verb, args)
+ csv = get_string(verb, args)
+ token = ""
+ tokens = []
+ escape = false
+ csv.split(//).each do |letter|
+ if escape
+ token = token + letter
+ escape = false
+ next
+ end
+ if (letter == '\\')
+ escape = true
+ elsif (letter == ',')
+ tokens.push(token)
+ token = ""
+ else
+ token = token + letter
+ end
+ end
+ tokens.push(token)
+ return tokens
+ end
+
+ def get_number(verb, args)
+ # Is there something I need to do here?
+ return get_string(verb, args)
+ end
+
+ def get_number_array(verb, args)
+ # Is there something I need to do here?
+ return get_string_array(verb, args)
+ end
+
+ def get_boolean(verb, args)
+ boolstr = get_string(verb, args)
+ if ("true" == boolstr)
+ return true
+ end
+ if ("false" == boolstr)
+ return false
+ end
+ raise ValueError, "result is neither 'true' nor 'false': " + boolstr
+ end
+
+ def get_boolean_array(verb, args)
+ boolarr = get_string_array(verb, args)
+ boolarr.length.times do |i|
+ if ("true" == boolstr)
+ boolarr[i] = true
+ next
+ end
+ if ("false" == boolstr)
+ boolarr[i] = false
+ next
+ end
+ raise ValueError, "result is neither 'true' nor 'false': " + boolarr[i]
+ end
+ return boolarr
+ end
+ end
+
+ end
+end
View
6 lib/selenium/selenium_helper.rb → lib/selenium/client/selenium_helper.rb
@@ -3,6 +3,8 @@
# call to a missing method will be automatically sent to the @selenium
# object.
module Selenium
+ module Client
+
module SeleniumHelper
# Overrides standard "open" method with @selenium.open
@@ -27,6 +29,8 @@ def method_missing(method_name, *args)
else
@selenium.send(method_name, *args)
end
- end
+ end
+ end
+
end
end
View
93 lib/selenium/selenese_client.rb
@@ -1,93 +0,0 @@
-module Selenium
-
- module SeleneseClient
-
- def do_command(verb, args)
- timeout(@timeout) do
- http = Net::HTTP.new(@server_host, @server_port)
- command_string = '/selenium-server/driver/?cmd=' + CGI::escape(verb)
- args.length.times do |i|
- arg_num = (i+1).to_s
- command_string = command_string + "&" + arg_num + "=" + CGI::escape(args[i].to_s)
- end
- if @session_id != nil
- command_string = command_string + "&sessionId=" + @session_id.to_s
- end
- #print "Requesting --->" + command_string + "\n"
- response = http.get(command_string)
- #print "RESULT: " + response.body + "\n\n"
- if (response.body[0..1] != "OK")
- raise SeleniumCommandError, response.body
- end
- return response.body
- end
- end
-
- def get_string(verb, args)
- result = do_command(verb, args)
- return result[3..result.length]
- end
-
- def get_string_array(verb, args)
- csv = get_string(verb, args)
- token = ""
- tokens = []
- escape = false
- csv.split(//).each do |letter|
- if escape
- token = token + letter
- escape = false
- next
- end
- if (letter == '\\')
- escape = true
- elsif (letter == ',')
- tokens.push(token)
- token = ""
- else
- token = token + letter
- end
- end
- tokens.push(token)
- return tokens
- end
-
- def get_number(verb, args)
- # Is there something I need to do here?
- return get_string(verb, args)
- end
-
- def get_number_array(verb, args)
- # Is there something I need to do here?
- return get_string_array(verb, args)
- end
-
- def get_boolean(verb, args)
- boolstr = get_string(verb, args)
- if ("true" == boolstr)
- return true
- end
- if ("false" == boolstr)
- return false
- end
- raise ValueError, "result is neither 'true' nor 'false': " + boolstr
- end
-
- def get_boolean_array(verb, args)
- boolarr = get_string_array(verb, args)
- boolarr.length.times do |i|
- if ("true" == boolstr)
- boolarr[i] = true
- next
- end
- if ("false" == boolstr)
- boolarr[i] = false
- next
- end
- raise ValueError, "result is neither 'true' nor 'false': " + boolarr[i]
- end
- return boolarr
- end
-
- end
-end
View
2  pom.xml
@@ -172,7 +172,7 @@
<fileset>
<directory>.</directory>
<includes>
- <include>lib/selenium/generated_driver.rb</include>
+ <include>lib/selenium/client/generated_driver.rb</include>
</includes>
</fileset>
<fileset>
Please sign in to comment.
Something went wrong with that request. Please try again.