jacobdam-selenium 1.1.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/README +17 -0
  2. data/lib/selenium.rb +17 -0
  3. data/lib/selenium/alert.rb +15 -0
  4. data/lib/selenium/auto_it.rb +6 -0
  5. data/lib/selenium/auto_it_driver.rb +45 -0
  6. data/lib/selenium/auto_it_window.rb +86 -0
  7. data/lib/selenium/autoit/AutoItX3.dll +0 -0
  8. data/lib/selenium/button.rb +7 -0
  9. data/lib/selenium/file_upload.rb +16 -0
  10. data/lib/selenium/html_element.rb +42 -0
  11. data/lib/selenium/key.rb +16 -0
  12. data/lib/selenium/link.rb +31 -0
  13. data/lib/selenium/openqa/selenium-server.jar.txt +0 -0
  14. data/lib/selenium/openqa/selenium.rb +1689 -0
  15. data/lib/selenium/openqa/sslSupport/cybervillainsCA.cer +0 -0
  16. data/lib/selenium/selenium_server.rb +86 -0
  17. data/lib/selenium/server.rb +124 -0
  18. data/lib/selenium/server_manager.rb +10 -0
  19. data/lib/selenium/text_area.rb +15 -0
  20. data/lib/selenium/text_field.rb +16 -0
  21. data/lib/selenium/web_page.rb +214 -0
  22. data/spec/selenium/examples/selenium_ruby.rb +9 -0
  23. data/spec/selenium/examples/selenium_ruby/directory_listing_page.rb +9 -0
  24. data/spec/selenium/examples/selenium_ruby/download_page.rb +11 -0
  25. data/spec/selenium/examples/selenium_ruby/home_page.rb +13 -0
  26. data/spec/selenium/examples/selenium_ruby/license_page.rb +11 -0
  27. data/spec/selenium/examples/selenium_ruby/menu.rb +29 -0
  28. data/spec/selenium/examples/selenium_ruby/selenium_ruby_page.rb +18 -0
  29. data/spec/selenium/manual_tc_file_upload.rb +53 -0
  30. data/spec/selenium/manual_tc_timout.rb +37 -0
  31. data/spec/selenium/selenium.rb +8 -0
  32. data/spec/selenium/tc_auto_it.rb +18 -0
  33. data/spec/selenium/tc_auto_it_window.rb +19 -0
  34. data/spec/selenium/tc_basic_operation.rb +37 -0
  35. data/spec/selenium/tc_domain_example.rb +58 -0
  36. data/spec/selenium/tc_html_element.rb +32 -0
  37. data/spec/selenium/tc_interaction_example.rb +30 -0
  38. data/spec/selenium/tc_server.rb +24 -0
  39. data/spec/selenium/tc_web_page.rb +113 -0
  40. data/spec/ts_selenium.rb +6 -0
  41. metadata +94 -0
@@ -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,9 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ module Selenium
4
+ class DirectoryListingPage < WebPage
5
+ def initialize(browser)
6
+ super(browser, 'Index of /')
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+ require 'menu'
3
+ require 'web_page'
4
+
5
+ module Selenium
6
+ class DownloadPage < SeleniumRubyPage
7
+ def initialize(browser)
8
+ super(browser, 'Selenium Ruby - Download')
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+ require 'menu'
3
+ require 'selenium_ruby_page'
4
+
5
+ module Selenium
6
+ class HomePage < SeleniumRubyPage
7
+
8
+ def initialize(browser)
9
+ super(browser, 'Selenium Ruby - Home')
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ $:.unshift File.join(File.dirname(__FILE__))
2
+
3
+ require 'menu'
4
+
5
+ module Selenium
6
+ class LicensePage < SeleniumRubyPage
7
+ def initialize(browser)
8
+ super(browser, 'Selenium Ruby - License')
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,29 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ require 'home_page'
4
+ require 'directory_listing_page'
5
+ require 'license_page'
6
+
7
+ module Selenium
8
+ class Menu
9
+ attr_reader :webpage
10
+ def initialize(webpage)
11
+ @webpage = webpage
12
+ end
13
+
14
+ def home_link
15
+ # todo there should be a way to alter this instance so that the click returns the directory listing page
16
+ webpage.link(:id, 'home').with_target(DirectoryListingPage)
17
+ end
18
+
19
+ #MENU START
20
+ def download_link
21
+ webpage.link(:text, 'Download')
22
+ end
23
+
24
+ def license_link
25
+ webpage.link(:text, 'License').with_target(LicensePage)
26
+ end
27
+ #MENU END
28
+ end
29
+ end
@@ -0,0 +1,18 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ #require '../../../../lib/selenium'
4
+ require 'menu'
5
+
6
+ module Selenium
7
+ class SeleniumRubyPage < WebPage
8
+ attr_reader :menu
9
+
10
+ def initialize(browser, expected_title)
11
+ super(browser, expected_title)
12
+ end
13
+
14
+ def menu
15
+ Menu.new(self)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,53 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..')
2
+
3
+ require 'lib/selenium/auto_it'
4
+ require 'lib/selenium'
5
+ require 'spec'
6
+
7
+ module Selenium
8
+ describe FileUpload do
9
+ before(:all) do
10
+ @server = Server.on_port(4440)
11
+ # @server.print_log = true
12
+ @server.start
13
+ end
14
+
15
+ after(:all) do
16
+ @server.stop
17
+ end
18
+
19
+ before do
20
+ # @page = @server.open('*iexplore', 'http://www.rubyforge.org/projects/selenium')
21
+ @page = @server.open('*chrome D:\Program Files\Mozilla Firefox2\firefox.exe', 'http://www.rubyforge.org/projects/selenium')
22
+ end
23
+
24
+ after do
25
+ file = File.join(File.dirname(__FILE__), 'screenshot.png')
26
+ puts "image at #{file}"
27
+ @page.capture_screen(file)
28
+ @page.close
29
+ end
30
+
31
+ # this requires the user to manually enter the login information on rubyforge, and can only be run by selenium admin
32
+ it 'should handle firefox' do
33
+ login_link = @page.link(:text, 'Log In')
34
+ autoit = AutoIt.load
35
+ login_link.click if login_link.present?
36
+ AutoItWindow.wait_for(autoit, 'Website Certified by an Unknown Authority').send_keys(' ')
37
+ @page.wait_for_load
38
+ @page.wait_until('manual login for test') do |message|
39
+ puts message
40
+ not login_link.present?
41
+ end
42
+ @page.wait_for_load
43
+ selenium_project_link = @page.link(:text, 'Selenium')
44
+ selenium_project_link.should be_present
45
+ selenium_project_link.click_wait
46
+ @page.link(:text, 'Files').click_wait
47
+ @page.link(:href, '/frs/admin/?group_id=2789').click_wait
48
+ @page.link(:xpath, "//a[@href='qrs.php?package_id=3298&group_id=2789']").click_wait
49
+ @page.file_upload(:name, 'userfile').enter("file:///#{__FILE__}")
50
+ # @page.file_upload('userfile').enter("file:///#{__FILE__}")
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,37 @@
1
+ require "spec"
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
4
+
5
+ require 'selenium'
6
+
7
+ describe 'Time Out Control' do
8
+
9
+ before(:each) do
10
+ end
11
+
12
+ after(:each) do
13
+ end
14
+
15
+
16
+ it "should honor the time out argument" do
17
+ link_list=["http://www.myantel.net.mm",
18
+ "http://www.khitlunge.net.mm",
19
+ "http://www.mrtv4.net.mm",
20
+ "http://www.mpt.net.mm",
21
+ "http://www.yatanarponteleport.net.mm",
22
+ "http://www.net.mm",
23
+ "http://www.mwdtv.net.mm",
24
+ "http://ns1.net.mm",
25
+ "http://www.isy.net.mm",
26
+ "http://www.mptmail.net.mm",
27
+ "http://www.mrtv3.net.mm"
28
+
29
+ ]
30
+
31
+ selenium=Selenium::SeleniumDriver.new("localhost",4444,"*chrome", link_list.first, 600000)
32
+ selenium.start
33
+ selenium.set_timeout(600000)
34
+ link_list.each {|url| selenium.open(url) }
35
+ end
36
+
37
+ end
@@ -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,18 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..')
2
+
3
+ require 'lib/selenium/auto_it'
4
+ require 'spec'
5
+
6
+ module Selenium
7
+ describe AutoIt do
8
+ it 'should control notepad' do
9
+ autoit = AutoIt.load
10
+ autoit.Run('Notepad.exe')
11
+ autoit.WinWaitActive('Untitled - Notepad')
12
+ autoit.Send('some text')
13
+ autoit.WinClose('Untitled - Notepad')
14
+ autoit.WinWaitActive('Notepad', 'Do you want to save')
15
+ autoit.Send('!n')
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,19 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..')
2
+
3
+ require 'lib/selenium/auto_it'
4
+ require 'spec'
5
+
6
+ module Selenium
7
+ describe AutoItWindow do
8
+ it 'should control notepad' do
9
+ autoit = AutoIt.load
10
+ autoit.Run('Notepad.exe')
11
+ window = AutoItWindow.new(autoit, 'Untitled - Notepad')
12
+ window.wait_for_activation
13
+ window.send_keys('some text')
14
+ window.close
15
+ confirm = AutoItWindow.wait_for(autoit, 'Notepad', 'Do you want to save')
16
+ confirm.send_keys('!n')
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec'
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..')
4
+
5
+ require 'lib/selenium'
6
+ require 'spec/selenium/examples/selenium_ruby/home_page'
7
+ require 'spec/selenium/examples/selenium_ruby/download_page'
8
+
9
+ module Selenium
10
+ describe 'basic operation with selenium' do
11
+ before do
12
+ port = 4567
13
+ @server = Selenium::Server.on_port(port)
14
+ @server.start
15
+ @webpage = @server.open("*iexplore", 'http://localhost:2000/index.html')
16
+ @browser = @webpage.browser
17
+ end
18
+
19
+ after do
20
+ @webpage.close
21
+ @server.stop
22
+ end
23
+
24
+ it 'should click through menus' do
25
+ #TEST START
26
+ page = HomePage.new(@browser)
27
+ page.menu.download_link.click_wait
28
+ page = DownloadPage.new(@browser)
29
+ page.should be_present
30
+ page = page.menu.home_link.go
31
+ page.link(:text, 'index.txt').click_wait
32
+ page = HomePage.new(@browser)
33
+ page.menu.license_link.go
34
+ #TEST END
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,58 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..')
2
+
3
+ require 'spec'
4
+ require 'lib/selenium'
5
+
6
+ #START GOOGLEHOME
7
+ class GoogleHomPage < Selenium::WebPage
8
+ def initialize(browser)
9
+ super(browser, 'Google')
10
+ end
11
+
12
+ def title
13
+ browser.get_title
14
+ end
15
+
16
+ def search_field
17
+ text_field(:name, 'q')
18
+ end
19
+
20
+ def search_button
21
+ button(:name, 'btnG')
22
+ end
23
+
24
+ end
25
+ #END GOOGLEHOME
26
+
27
+ context 'Test goole search' do
28
+ before(:all) do
29
+ port = 4567
30
+ @server = Selenium::Server.on_port(port)
31
+ @server.start
32
+ end
33
+
34
+ before(:each) do
35
+ @webpage = @server.open('*chrome D:\Program Files\Mozilla Firefox2\firefox.exe', 'http://www.google.com/webhp')
36
+ end
37
+
38
+ after(:each) do
39
+ @webpage.close if @webpage
40
+ end
41
+
42
+ after(:all) do
43
+ puts "stopping server"
44
+ @server.stop
45
+ end
46
+
47
+ #START DOMAIN
48
+ specify'searh hello world with google using docmain based script' do
49
+ page = GoogleHomPage.new(@webpage.browser)
50
+ page.should be_present
51
+ page.search_field.enter('hello world')
52
+ page.search_button.click_wait
53
+ page.title.should == 'hello world - Google Search'
54
+ page.search_field.value.should == 'hello world'
55
+ end
56
+ #END DOMAIN
57
+
58
+ 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
@@ -0,0 +1,30 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
2
+
3
+ #START INTERACTION
4
+ require 'spec'
5
+ require 'selenium'
6
+
7
+ context 'Test goole search' do
8
+ before do
9
+ port = 4567
10
+ @server = Selenium::Server.on_port(port)
11
+ @server.start
12
+ @page = @server.open('*chrome D:\Program Files\Mozilla Firefox2\firefox.exe', 'http://www.google.com')
13
+ end
14
+
15
+ after do
16
+ @page.close
17
+ @server.stop
18
+ end
19
+
20
+ specify'searh hello world with google using interaction based script' do
21
+ @page.open_page("/")
22
+ @page.title.should == 'Google'
23
+ @page.enter("q", "hello world")
24
+ @page.click("btnG")
25
+ @page.wait_for_load
26
+ @page.title.should == 'hello world - Google Search'
27
+ end
28
+
29
+ end
30
+ #END INTERACTION
@@ -0,0 +1,24 @@
1
+ require 'spec'
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
4
+
5
+ require 'selenium'
6
+
7
+ module Selenium
8
+ describe 'server manager' do
9
+ it 'supports starting and stopping server on specified port' do
10
+ server = Server.on_port(4321)
11
+ server.start
12
+ server.status.should == "started"
13
+ server.stop
14
+ server.status.should == "stopped"
15
+ end
16
+
17
+ it 'should support arguments through start method' do
18
+ server = Server.on_port(3333)
19
+ server.start('-timeout 800')
20
+ server.stop
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,113 @@
1
+ require 'spec'
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..')
4
+
5
+ require 'lib/selenium'
6
+
7
+ module Selenium
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
+
33
+ it 'should create link based on text' do
34
+ webpage = WebPage.new('browser')
35
+ webpage.link(:text, 'text').locator.should == 'link=text'
36
+ end
37
+
38
+ it 'should create link based on href' do
39
+ webpage = WebPage.new('browser')
40
+ webpage.link(:href, 'a.html').locator.should == "xpath=//a[@href='a.html']"
41
+ end
42
+
43
+ it 'should convert how and what to locator for selenium driver' do
44
+ webpage.element_locator('name').should == 'name'
45
+ webpage.element_locator(:id, 'id').should == 'id=id'
46
+ webpage.element_locator(:name, 'name').should == 'name=name'
47
+ webpage.element_locator(:xpath, '//a').should == 'xpath=//a'
48
+ end
49
+
50
+ it 'should support elements by passing in name directly' do
51
+ webpage.open_page('/test/index.html')
52
+ text_field = webpage.text_field('doubleclick')
53
+ text_field.locator.should == 'doubleclick'
54
+ text_field.enter('webpage')
55
+ webpage.text_area('doubleclick').enter('webpage')
56
+ webpage.text_area('doubleclick').double_click
57
+ webpage.should be_alert_present
58
+ webpage.alert_message.should == 'double clicked with value webpage'
59
+ webpage.text_area('doubleclick').key_press('a')
60
+ webpage.text_area('doubleclick').value.should == 'webpagea'
61
+ end
62
+
63
+ it 'should support double click and key press' do
64
+ webpage.open_page('/test/index.html')
65
+ webpage.enter('doubleclick', 'webpage')
66
+ webpage.double_click('doubleclick')
67
+ webpage.should be_alert_present
68
+ webpage.alert_message.should == 'double clicked with value webpage'
69
+ webpage.key_press('doubleclick', 'a')
70
+ webpage.value('doubleclick').should == 'webpagea'
71
+ end
72
+
73
+ it 'should support context menu' do
74
+ webpage.open_page('/test/index.html')
75
+ webpage.context_menu('link=License')
76
+ webpage.capture_screen(File.join(File.dirname(__FILE__), 'screenshot.png'))
77
+ end
78
+
79
+ it 'should support focus event and fire blur event' do
80
+ webpage.open_page('/test/index.html')
81
+ webpage.focus('events')
82
+ webpage.enter('events', 'value')
83
+ webpage.value('events').should == 'value'
84
+ webpage.fire_event('events', 'blur')
85
+ webpage.should be_alert_present
86
+ webpage.alert_message.should == 'blurred with value value'
87
+ webpage.fire_event('events', 'focus')
88
+ # webpage.focus('events')
89
+ webpage.value('events').should == 'default'
90
+ end
91
+
92
+ it 'should support key event and check if it is supported' do
93
+ webpage.open_page('/test/index.httml')
94
+ webpage.key_down(:shift)
95
+ webpage.key_up(:shift)
96
+ [:shift, :meta, :alt, :control].each do |key|
97
+ key = webpage.key(key)
98
+ key.down
99
+ key.up
100
+ end
101
+ webpage.key(:alt).down
102
+
103
+ Proc.new {webpage.key_up(:command)}.should raise_error(NoKeyError)
104
+ Proc.new {webpage.key_down(:command)}.should raise_error(NoKeyError)
105
+ end
106
+
107
+ it 'should have speed as attribute' do
108
+ webpage.speed = 500
109
+ webpage.speed.should == 500
110
+ end
111
+
112
+ end
113
+ end