Selenium 1.1.11 → 1.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,10 +6,13 @@ require 'selenium_server'
6
6
  require 'web_page'
7
7
  require 'server'
8
8
 
9
+ require 'alert'
9
10
  require 'html_element'
10
11
  require 'button'
11
12
  require 'link'
12
13
  require 'locator'
13
14
  require 'text_field'
15
+ require 'text_area'
16
+ require 'key'
14
17
 
15
18
 
@@ -0,0 +1,15 @@
1
+ module Selenium
2
+ class Alert
3
+ def initialize(webpage)
4
+ @webpage = webpage
5
+ end
6
+
7
+ def present?
8
+ @webpage.alert_present?
9
+ end
10
+
11
+ def message
12
+ @webpage.alert_message
13
+ end
14
+ end
15
+ end
@@ -11,8 +11,12 @@ module Selenium
11
11
  webpage.browser
12
12
  end
13
13
 
14
+ def text
15
+ @webpage.text(@locator)
16
+ end
17
+
14
18
  def present?
15
- webpage.browser.is_element_present @locator
19
+ @webpage.element_present? @locator
16
20
  end
17
21
 
18
22
  # click the element
@@ -26,5 +30,13 @@ module Selenium
26
30
  @webpage.click_wait(@locator)
27
31
  end
28
32
 
33
+ def double_click
34
+ @webpage.double_click(@locator)
35
+ end
36
+
37
+ def key_press(key)
38
+ @webpage.key_press(@locator, key)
39
+ end
40
+
29
41
  end
30
42
  end
@@ -0,0 +1,16 @@
1
+ module Selenium
2
+ class Key
3
+ def initialize(webpage, key)
4
+ @webpage = webpage
5
+ @key = key
6
+ end
7
+
8
+ def up
9
+ @webpage.key_up(@key)
10
+ end
11
+
12
+ def down
13
+ @webpage.key_down(@key)
14
+ end
15
+ end
16
+ end
@@ -34,13 +34,15 @@ module Selenium
34
34
 
35
35
  public
36
36
  attr_reader :port_number, :request_timeout
37
+ # Turn off INFO level server logs, only WARN and above message will be printed
37
38
  attr_accessor :print_log
38
39
 
39
40
  # Initialize the server driver with an opitonal port number (default to 4444)
40
- def initialize(port_number_to_use = 4444)
41
+ # and request timeout (default to 30)
42
+ def initialize(port_number_to_use = 4444, request_timeout=30)
41
43
  port_number_to_use = 4444 unless port_number_to_use
42
44
  @port_number = port_number_to_use
43
- @request_timeout = 30
45
+ @request_timeout = request_timeout
44
46
  @print_log = false
45
47
  end
46
48
 
@@ -21,12 +21,21 @@ class Server
21
21
  # * error
22
22
  attr_reader :status
23
23
 
24
+ # The timeout setting for selenium in seconds
25
+ attr_reader :timeout
26
+
24
27
  def Server::on_port(port)
25
28
  Server.new(SeleniumServer.new(port))
26
29
  end
27
30
 
28
- def initialize(server = SeleniumServer.new)
29
- @server = server
31
+ # Create a selenium server that can be controlled directly
32
+ def initialize(port_number, timeout=60)
33
+ if port_number.is_a? SeleniumServer
34
+ # backward compatibility, to be removed in 2.0
35
+ @server = port_number
36
+ else
37
+ @server = SeleniumServer.new(port_number, timeout)
38
+ end
30
39
  @status = 'stopped'
31
40
  end
32
41
 
@@ -0,0 +1,15 @@
1
+ module Selenium
2
+ class TextArea < HtmlElement
3
+ def initialize(webpage, locator)
4
+ super(webpage, locator)
5
+ end
6
+
7
+ def enter(value)
8
+ @webpage.enter(@locator, value)
9
+ end
10
+
11
+ def value
12
+ @webpage.value(@locator)
13
+ end
14
+ end
15
+ end
@@ -1,6 +1,5 @@
1
1
  module Selenium
2
2
  class TextField < HtmlElement
3
- attr_reader :browser
4
3
 
5
4
  def initialize(webpage, locator)
6
5
  super(webpage, locator)
@@ -1 +1 @@
1
- 1.1.11
1
+ 1.1.12
@@ -3,6 +3,13 @@ $:.unshift File.dirname(__FILE__)
3
3
  require 'timeout'
4
4
 
5
5
  module Selenium
6
+ # Error that is thrown when a key is not supported
7
+ class NoKeyError < NameError
8
+ def initialize(key)
9
+ super(key)
10
+ end
11
+ end
12
+
6
13
  # Class that models a web page with a title
7
14
  class WebPage
8
15
  attr_reader :browser
@@ -32,6 +39,14 @@ module Selenium
32
39
  @browser.get_html_source
33
40
  end
34
41
 
42
+ def speed=(value)
43
+ @browser.set_speed(value)
44
+ end
45
+
46
+ def speed
47
+ @browser.get_speed.to_i
48
+ end
49
+
35
50
  def wait_for_load
36
51
  @browser.wait_for_page_to_load
37
52
  end
@@ -44,6 +59,10 @@ module Selenium
44
59
  end
45
60
  end
46
61
 
62
+ def alert
63
+ Alert.new(self)
64
+ end
65
+
47
66
  def link(how, what=nil)
48
67
  if (how == :text)
49
68
  locator = "link=#{what}"
@@ -59,8 +78,12 @@ module Selenium
59
78
  TextField.new(self, element_locator(how, what))
60
79
  end
61
80
 
62
- def button(how, what=nil)
63
- Button.new(self, element_locator(how, what))
81
+ def text_area(how, what=nil)
82
+ TextArea.new(self, element_locator(how, what))
83
+ end
84
+
85
+ def element(how, what=nil)
86
+ HtmlElement.new(self, element_locator(how,what))
64
87
  end
65
88
 
66
89
  def element_locator(how, what=nil)
@@ -78,8 +101,9 @@ module Selenium
78
101
  FileUpload.new(self, element_locator(how, what))
79
102
  end
80
103
 
81
- def open(url)
104
+ def open_page(url)
82
105
  @browser.open(url)
106
+ wait_for_load
83
107
  end
84
108
 
85
109
  def close
@@ -90,6 +114,34 @@ module Selenium
90
114
  @browser.click(locator)
91
115
  end
92
116
 
117
+ def text(locator)
118
+ @browser.get_text(locator)
119
+ end
120
+
121
+ def button(how, what=nil)
122
+ Button.new(self, element_locator(how, what))
123
+ end
124
+
125
+ def key(key)
126
+ Key.new(self, key)
127
+ end
128
+
129
+ def element_present?(locator)
130
+ @browser.is_element_present(locator)
131
+ end
132
+
133
+ def alert_present?
134
+ @browser.is_alert_present
135
+ end
136
+
137
+ def text_present?(text)
138
+ @browser.is_text_present(text)
139
+ end
140
+
141
+ def double_click(locator)
142
+ @browser.double_click(locator)
143
+ end
144
+
93
145
  def click_wait(locator)
94
146
  click(locator)
95
147
  wait_for_load
@@ -104,6 +156,38 @@ module Selenium
104
156
  @browser.get_value(locator)
105
157
  end
106
158
 
159
+ def alert_message
160
+ @browser.get_alert
161
+ end
162
+
163
+ def context_menu(locator)
164
+ @browser.context_menu(locator)
165
+ end
166
+
167
+ def fire_event(locator, event)
168
+ @browser.fire_event(locator, event)
169
+ end
170
+
171
+ def key_down(key)
172
+ message = "#{key}_key_down"
173
+ raise NoKeyError.new(key.to_s) unless @browser.respond_to? message
174
+ @browser.send message
175
+ end
176
+
177
+ def key_up(key)
178
+ message = "#{key}_key_up"
179
+ raise NoKeyError.new(key.to_s) unless @browser.respond_to? message
180
+ @browser.send message
181
+ end
182
+
183
+ def key_press(locator, key)
184
+ @browser.key_press(locator, key)
185
+ end
186
+
187
+ def focus(locator)
188
+ @browser.focus(locator)
189
+ end
190
+
107
191
  def upload(locator, file)
108
192
  # @browser.attach_file(locator, file)
109
193
  @browser.click(locator)
@@ -120,6 +204,10 @@ module Selenium
120
204
  def capture_screen(file)
121
205
  @browser.capture_screenshot(file)
122
206
  end
207
+
208
+ def to_s
209
+ "#{self.class}('#{@expected_title}') - #{browser.to_s}"
210
+ end
123
211
 
124
212
  end
125
213
  end
@@ -0,0 +1,9 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ require '../../../lib/selenium'
4
+ require 'selenium_ruby/selenium_ruby_page'
5
+ require 'selenium_ruby/home_page'
6
+ require 'selenium_ruby/directory_listing_page'
7
+ require 'selenium_ruby/download_page'
8
+ require 'selenium_ruby/license_page'
9
+ require 'selenium_ruby/menu'
@@ -0,0 +1,8 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..')
2
+
3
+ require 'spec'
4
+ require 'lib/selenium'
5
+
6
+ module Selenium
7
+ BROWSER = '*chrome D:\Program Files\Mozilla Firefox2\firefox.exe'
8
+ end
@@ -0,0 +1,32 @@
1
+ $:.unshift(File.dirname(__FILE__))
2
+
3
+ require 'selenium'
4
+
5
+ module Selenium
6
+ describe HtmlElement do
7
+ before(:all) do
8
+ @server = Server.new(4445)
9
+ @server.start
10
+ @webpage = @server.open(BROWSER, 'http://localhost:2000/test/index.html')
11
+ end
12
+
13
+ before do
14
+ @webpage.open_page('/test/index.html')
15
+ end
16
+
17
+ after(:all) do
18
+ @webpage.close if @webpage
19
+ @server.stop
20
+ end
21
+
22
+ it 'should support double click and key press' do
23
+ text_area = @webpage.text_area(:name, 'doubleclick')
24
+ text_area.enter 'html double click'
25
+ text_area.double_click
26
+ @webpage.alert.should be_present
27
+ @webpage.alert.message.should == 'double clicked with value html double click'
28
+ text_area.key_press('b')
29
+ text_area.value.should == 'html double clickb'
30
+ end
31
+ end
32
+ end
@@ -18,7 +18,7 @@ context 'Test goole search' do
18
18
  end
19
19
 
20
20
  specify'searh hello world with google using interaction based script' do
21
- @page.open("/")
21
+ @page.open_page("/")
22
22
  @page.title.should == 'Google'
23
23
  @page.enter("q", "hello world")
24
24
  @page.click("btnG")
@@ -6,6 +6,30 @@ require 'lib/selenium'
6
6
 
7
7
  module Selenium
8
8
  describe WebPage do
9
+ before(:all) do
10
+ @server = Server.new(2344)
11
+ @server.start
12
+ @@webpage = nil
13
+ end
14
+
15
+ before do
16
+ @@webpage.open_page('/') if @@webpage
17
+ end
18
+
19
+ after(:all) do
20
+ @server.stop
21
+ end
22
+
23
+ def webpage
24
+ @@webpage = @server.open('*chrome D:\Program Files\Mozilla Firefox2\firefox.exe', 'http://localhost:2000/') unless @@webpage
25
+ @@webpage
26
+ end
27
+
28
+ it 'should have meaningful to_s support' do
29
+ webpage = WebPage.new(SeleniumDriver.new('localhost', 2222, '*chrome', 'http://www.example.com', 60000), 'expected title')
30
+ webpage.to_s.should == 'Selenium::WebPage(\'expected title\') - SeleniumDriver'
31
+ end
32
+
9
33
  it 'should create link based on text' do
10
34
  webpage = WebPage.new('browser')
11
35
  webpage.link(:text, 'text').locator.should == 'link=text'
@@ -15,5 +39,55 @@ module Selenium
15
39
  webpage = WebPage.new('browser')
16
40
  webpage.link(:href, 'a.html').locator.should == "xpath=//a[@href='a.html']"
17
41
  end
42
+
43
+ it 'should support double click and key press' do
44
+ webpage.open_page('/test/index.html')
45
+ webpage.enter('doubleclick', 'webpage')
46
+ webpage.double_click('doubleclick')
47
+ webpage.should be_alert_present
48
+ webpage.alert_message.should == 'double clicked with value webpage'
49
+ webpage.key_press('doubleclick', 'a')
50
+ webpage.value('doubleclick').should == 'webpagea'
51
+ end
52
+
53
+ it 'should support context menu' do
54
+ webpage.open_page('/test/index.html')
55
+ webpage.context_menu('link=License')
56
+ webpage.capture_screen(File.join(File.dirname(__FILE__), 'screenshot.png'))
57
+ end
58
+
59
+ it 'should support focus event and fire blur event' do
60
+ webpage.open_page('/test/index.html')
61
+ webpage.focus('events')
62
+ webpage.enter('events', 'value')
63
+ webpage.value('events').should == 'value'
64
+ webpage.fire_event('events', 'blur')
65
+ webpage.should be_alert_present
66
+ webpage.alert_message.should == 'blurred with value value'
67
+ webpage.fire_event('events', 'focus')
68
+ # webpage.focus('events')
69
+ webpage.value('events').should == 'default'
70
+ end
71
+
72
+ it 'should support key event and check if it is supported' do
73
+ webpage.open_page('/test/index.httml')
74
+ webpage.key_down(:shift)
75
+ webpage.key_up(:shift)
76
+ [:shift, :meta, :alt, :control].each do |key|
77
+ key = webpage.key(key)
78
+ key.down
79
+ key.up
80
+ end
81
+ webpage.key(:alt).down
82
+
83
+ Proc.new {webpage.key_up(:command)}.should raise_error(NoKeyError)
84
+ Proc.new {webpage.key_down(:command)}.should raise_error(NoKeyError)
85
+ end
86
+
87
+ it 'should have speed as attribute' do
88
+ webpage.speed = 500
89
+ webpage.speed.should == 500
90
+ end
91
+
18
92
  end
19
93
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Selenium
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.11
4
+ version: 1.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane Duan
@@ -9,7 +9,7 @@ autorequire: selenium
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-07-12 00:00:00 -07:00
12
+ date: 2008-07-13 00:00:00 -07:00
13
13
  default_executable: selenium
14
14
  dependencies: []
15
15
 
@@ -24,6 +24,7 @@ extra_rdoc_files:
24
24
  files:
25
25
  - bin/selenium
26
26
  - lib/selenium
27
+ - lib/selenium/alert.rb
27
28
  - lib/selenium/autoit
28
29
  - lib/selenium/autoit/AutoItX3.dll
29
30
  - lib/selenium/autoit/README
@@ -33,6 +34,7 @@ files:
33
34
  - lib/selenium/button.rb
34
35
  - lib/selenium/file_upload.rb
35
36
  - lib/selenium/html_element.rb
37
+ - lib/selenium/key.rb
36
38
  - lib/selenium/link.rb
37
39
  - lib/selenium/locator.rb
38
40
  - lib/selenium/openqa
@@ -44,6 +46,7 @@ files:
44
46
  - lib/selenium/selenium_server.rb
45
47
  - lib/selenium/server.rb
46
48
  - lib/selenium/server_manager.rb
49
+ - lib/selenium/text_area.rb
47
50
  - lib/selenium/text_field.rb
48
51
  - lib/selenium/version
49
52
  - lib/selenium/web_page.rb
@@ -57,12 +60,16 @@ files:
57
60
  - spec/selenium/examples/selenium_ruby/license_page.rb
58
61
  - spec/selenium/examples/selenium_ruby/menu.rb
59
62
  - spec/selenium/examples/selenium_ruby/selenium_ruby_page.rb
63
+ - spec/selenium/examples/selenium_ruby.rb
60
64
  - spec/selenium/manual_tc_file_upload.rb
61
65
  - spec/selenium/manual_tc_timout.rb
66
+ - spec/selenium/screenshot.png
67
+ - spec/selenium/selenium.rb
62
68
  - spec/selenium/tc_auto_it.rb
63
69
  - spec/selenium/tc_auto_it_window.rb
64
70
  - spec/selenium/tc_basic_operation.rb
65
71
  - spec/selenium/tc_domain_example.rb
72
+ - spec/selenium/tc_html_element.rb
66
73
  - spec/selenium/tc_interaction_example.rb
67
74
  - spec/selenium/tc_server.rb
68
75
  - spec/selenium/tc_web_page.rb