selenium_plus 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YjE1MThkNTIwYzVlOGM4YTA4NzAwZWM0NGU5ZGQxODEyNDMxNmFjMw==
5
+ data.tar.gz: !binary |-
6
+ YWVkZjU0ODMxNmY4MjBhYjExNjExNjQ2ZDJlMGJlOWNmMTM1MjgyMA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ Y2JmNmVkYjAwM2Q1NTBmOGMyYTk3ZGFkZTAzMTAxMDQ0NWZlOGU5YmM0NjAy
10
+ ZDY4OWFiNWYwZWUyZTFjMjkzYjBkNzZmMzYzYmM4YjU3Nzc0M2E3ODI5NGRl
11
+ M2U4NTU5OWVjY2E4NTRjMjdiZjg2YjRlMzIyZDkyMjlmMjhhYjQ=
12
+ data.tar.gz: !binary |-
13
+ NDc4N2Q0NGQ2ZDVlYTI3MTQzZjdjZDIwMmU1MzQ2MDFlMjg5ZjUyYmNkZWZm
14
+ ZTM0ZTBmYjU1YjBjZjk2YTkyZDA3OWQ4MTliMjUyNDhiZGMxNjU5ZmE4YWQy
15
+ NzBiMmU5NGRmMjBlZWFiNzlkYzM2ZWQ5N2E2MzJiYWEwZjkwYWE=
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ .DS_Store
2
+ Gemfile.lock
3
+ .idea/
4
+ .yardoc/
5
+ .rvmrc
6
+ chromedriver.log
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'bundler', '>= 1.2.0'
4
+
5
+ # Specify your gem's dependencies in selenium_plus.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Shipu Yao
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # SeleniumPlus
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'selenium_plus'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install selenium_plus
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,71 @@
1
+ module SeleniumPlus
2
+ class Driver
3
+
4
+ DEFAULT_OPTIONS = { :browser => :firefox }
5
+
6
+ attr_reader :browser, :options
7
+
8
+ def initialize(options={})
9
+ @browser = nil
10
+ @exit_status = nil
11
+ @options = DEFAULT_OPTIONS.merge(options)
12
+ end
13
+
14
+ def browser
15
+ unless @browser
16
+ @browser = Selenium::WebDriver.for(options[:browser])
17
+ main = Process.pid
18
+ at_exit do
19
+ # Store the exit status of the test run since it goes away after calling the at_exit proc...
20
+ @exit_status = $!.status if $!.is_a?(SystemExit)
21
+ quit if Process.pid == main
22
+ exit @exit_status if @exit_status # Force exit with stored status
23
+ end
24
+ end
25
+ @browser
26
+ end
27
+
28
+ def visit(url)
29
+ browser.navigate.to(url)
30
+ end
31
+
32
+ def find(*args)
33
+ browser.find_element(*args)
34
+ end
35
+
36
+ def all(*args)
37
+ browser.find_elements(*args)
38
+ end
39
+
40
+ def execute_script(script)
41
+ browser.execute_script script
42
+ end
43
+
44
+ def evaluate_script(script)
45
+ browser.execute_script "return #{script}"
46
+ end
47
+
48
+ def save_screenshot(path, options={})
49
+ browser.save_screenshot(path)
50
+ end
51
+
52
+ def reset!
53
+ # Use instance variable directly so we avoid starting the browser just to reset the session
54
+ if @browser
55
+ begin @browser.manage.delete_all_cookies
56
+ rescue Selenium::WebDriver::Error::UnhandledError
57
+ # delete_all_cookies fails when we've previously gone
58
+ # to about:blank, so we rescue this error and do nothing
59
+ # instead.
60
+ end
61
+ @browser.navigate.to('about:blank')
62
+ end
63
+ end
64
+
65
+ def quit
66
+ @browser.quit
67
+ rescue Errno::ECONNREFUSED
68
+ # Browser must have already gone
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,75 @@
1
+ module SeleniumPlus
2
+ module Container
3
+
4
+ # Public: Define a new method with the name of the symbol after locator returns element
5
+ # and highlight element
6
+ #
7
+ # Example
8
+ # element(:username_tb, 'username')
9
+ #
10
+ # Returns element
11
+ def element(element_name, *find_args)
12
+ define_method(element_name.to_sym) do
13
+ driver.find(*find_args)
14
+ end
15
+ add_existence_checker(element_name, *find_args)
16
+ private element_name
17
+ end
18
+
19
+ # Public: Define a new method with the name of the symbol after locator returns elements
20
+ #
21
+ # Example
22
+ # elements(:aria_message_div, xpath: "//div[@id='ariaErrors']//li")
23
+ # # => <Capybara::Elements>
24
+ #
25
+ # Returns elements
26
+ def elements(element_name, *find_args)
27
+ define_method(:define_method, element_name) do
28
+ driver.all(*find_args)
29
+ end
30
+ private element_name
31
+ end
32
+
33
+ # Public: Define Partial section of the page
34
+ #
35
+ # Returns page object
36
+ def section(section_name, section_class, *find_args)
37
+ send(:define_method, section_name) do
38
+ section_class.new(driver, driver.find(*find_args))
39
+ end
40
+ end
41
+
42
+ # Public: Add element name into list
43
+ #
44
+ # Returns nothing
45
+ def add_element_name(element_name)
46
+ @element_names ||= []
47
+ @element_names << element_name
48
+ end
49
+
50
+ # Public: Element names in the page object
51
+ #
52
+ # return element names array
53
+ def element_names
54
+ @element_names
55
+ end
56
+
57
+ private
58
+ # Define an existence check method
59
+ # This method tries to find all elements by given locator with no wait time
60
+ # please make sure your page/section is fully loaded before use this method
61
+ #
62
+ # Example
63
+ # login_page.has_username_tb?
64
+ # # => true
65
+ #
66
+ # Returns
67
+ def add_existence_checker(element_name, *find_args)
68
+ method_name = "has_#{element_name}?"
69
+ define_method(method_name.to_sym) do
70
+ all(*find_args).size > 0
71
+ end
72
+ end
73
+ end
74
+ end
75
+
@@ -0,0 +1,15 @@
1
+ module SeleniumPlus
2
+ class Page
3
+ extend Container
4
+
5
+ attr_reader :driver
6
+
7
+ def initialize(driver)
8
+ @driver = driver
9
+ end
10
+
11
+ def visit(url)
12
+ driver.visit(url)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,21 @@
1
+ module SeleniumPlus
2
+ class Section
3
+ extend Container
4
+
5
+ attr_reader :driver, :root_element
6
+
7
+ def initialize(driver, root_element)
8
+ @driver = driver
9
+ @root_element = root_element
10
+ end
11
+
12
+ private
13
+ def find(*args)
14
+ root_element.find(*args)
15
+ end
16
+
17
+ def all(*args)
18
+ root_element.all(*args)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ module SeleniumPlus
2
+ class Site
3
+ attr_reader :driver
4
+
5
+ def initialize
6
+ @driver = SeleniumPlus.using_driver
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,52 @@
1
+ # Public: Add extension method to Element class
2
+ #
3
+ class Selenium::WebDriver::Element
4
+ include SeleniumPlus::Elements::Table
5
+
6
+ def [](name)
7
+ self.attribute(name.to_s)
8
+ rescue Selenium::WebDriver::Error::WebDriverError
9
+ nil
10
+ end
11
+
12
+ def set(value)
13
+ tag_name = self.tag_name
14
+ type = self[:type]
15
+ if (Array === value) && !self[:multiple]
16
+ raise ArgumentError.new "Value cannot be an Array when 'multiple' attribute is not present. Not a #{value.class}"
17
+ end
18
+ if tag_name == 'input' and type == 'radio'
19
+ click
20
+ elsif tag_name == 'input' and type == 'checkbox'
21
+ click if value ^ native.attribute('checked').to_s.eql?("true")
22
+ elsif tag_name == 'input' and type == 'file'
23
+ path_names = value.to_s.empty? ? [] : value
24
+ self.send_keys(*path_names)
25
+ elsif tag_name == 'textarea' or tag_name == 'input'
26
+ self.send_keys(value.to_s)
27
+ end
28
+ end
29
+
30
+ # Public: type text into text field
31
+ #
32
+ # Example
33
+ # element.type_text("hello")
34
+ #
35
+ # Returns nothing
36
+ def type(value)
37
+ self.clear
38
+ self.set(value)
39
+ end
40
+
41
+ # Public: append text into text field
42
+ #
43
+ # Example
44
+ # element.append_text("hello")
45
+ #
46
+ # Returns nothing
47
+ def append(value)
48
+ old = self.value
49
+ self.set(old + value)
50
+ end
51
+
52
+ end
@@ -0,0 +1,10 @@
1
+ module SeleniumPlus
2
+ module Elements
3
+ module Table
4
+ def raw
5
+ # ToDO
6
+ end
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module SeleniumPlus
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,49 @@
1
+ require 'selenium-webdriver'
2
+
3
+ require 'selenium_plus/version'
4
+ require 'selenium_plus/driver'
5
+ require 'selenium_plus/page_obj/site'
6
+ require 'selenium_plus/page_obj/container'
7
+ require 'selenium_plus/page_obj/page'
8
+ require 'selenium_plus/page_obj/section'
9
+ require 'selenium_plus/selenium/table'
10
+ require 'selenium_plus/selenium/element'
11
+
12
+ module SeleniumPlus
13
+ class SeleniumPlusError < StandardError; end
14
+ class DriverNotFoundError < SeleniumPlusError; end
15
+
16
+ class << self
17
+ attr_accessor :default_driver, :current_driver, :default_wait_time, :driver
18
+
19
+ def configure
20
+ yield self
21
+ end
22
+
23
+ def register_driver(name, &block)
24
+ drivers[name] = block
25
+ end
26
+
27
+ def drivers
28
+ @drivers ||= {}
29
+ end
30
+
31
+ def current_driver
32
+ @current_driver || default_driver
33
+ end
34
+
35
+ def using_driver
36
+ drivers[current_driver].call
37
+ end
38
+ end
39
+
40
+ end
41
+
42
+ SeleniumPlus.configure do |config|
43
+ config.default_wait_time =10
44
+ config.default_driver = :firefox
45
+ end
46
+
47
+ SeleniumPlus.register_driver :firefox do
48
+ SeleniumPlus::Driver.new(:browser => :firefox)
49
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'selenium_plus/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = 'selenium_plus'
8
+ gem.version = SeleniumPlus::VERSION
9
+ gem.authors = ['Spark Yao']
10
+ gem.email = %w(shipuyao@gmail.com)
11
+ gem.description = ''
12
+ gem.summary = ''
13
+ gem.homepage = ''
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = %w(lib)
19
+
20
+ gem.add_dependency('rake')
21
+ gem.add_dependency('selenium-webdriver', ['>= 2.25.0'])
22
+ gem.add_dependency('rspec', ['>= 2.1.0'])
23
+ gem.add_development_dependency('cucumber', ['>= 1.2.1'])
24
+ end
File without changes
@@ -0,0 +1,21 @@
1
+ $:.unshift(File.dirname(__FILE__))
2
+ require 'selenium_plus'
3
+ require 'rspec'
4
+ require 'test_site/test_site'
5
+
6
+ SeleniumPlus.register_driver :chrome do
7
+ SeleniumPlus::Driver.new(:browser => :chrome)
8
+ end
9
+ #
10
+ SeleniumPlus.current_driver = :chrome
11
+
12
+ driver = SeleniumPlus.using_driver
13
+ driver.visit('http://www.google.com.hk')
14
+ driver.find(:id,'lst-ib').type('hello')
15
+ driver.find(:css,'input[name=btnK]').click
16
+ driver.browser.title.should == 'Google'
17
+
18
+ @Test = TestSite.new
19
+ @Test.home_page.visit('file:///Users/shipuy/Github/selenium_plus/test_project/test_site/html/home.html')
20
+ @Test.home_page.show
21
+ @Test.home_page.info_section.names_table_rows
@@ -0,0 +1,46 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title></title>
5
+ <script type="text/javascript">
6
+ function load() {
7
+
8
+ }
9
+ window.onload = load;
10
+ </script>
11
+ </head>
12
+ <body>
13
+ <input type='text' id='keywords' value=''/>
14
+ <input type='submit' name='Submit' value='Show'/>
15
+ <div id='info'>
16
+ <table class='view'>
17
+ <tr>
18
+ <th>ID</th>
19
+ <th>Name</th>
20
+ </tr>
21
+ <tr>
22
+ <td>1</td>
23
+ <td>Alex</td>
24
+ </tr>
25
+ <tr>
26
+ <td>2</td>
27
+ <td>James</td>
28
+ </tr>
29
+ </table>
30
+ <table class='view'>
31
+ <tr>
32
+ <th>ID</th>
33
+ <th>Company</th>
34
+ </tr>
35
+ <tr>
36
+ <td>1</td>
37
+ <td>EMC</td>
38
+ </tr>
39
+ <tr>
40
+ <td>2</td>
41
+ <td>VMware</td>
42
+ </tr>
43
+ </table>
44
+ </div>
45
+ </body>
46
+ </html>
@@ -0,0 +1,18 @@
1
+ module Test
2
+ # This class provides actions for google search page
3
+ class HomePage < SeleniumPlus::Page
4
+
5
+ section(:info_section, InfoSection, :id, 'info')
6
+
7
+ # Private elements
8
+ #
9
+ element(:search_input, :id, 'keyword')
10
+ element(:submit_btn, :css, 'input[name=Submit]')
11
+
12
+ def show
13
+ search_input.type('hello world')
14
+ submit_btn.click
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,13 @@
1
+ module Test
2
+ # This class provides actions for add new admin section
3
+ class InfoSection < SeleniumPlus::Section
4
+
5
+ # Private elements
6
+ #
7
+ element(:names_table, :css, 'table.view:first-child')
8
+
9
+ def names_table_rows
10
+ # Not implemented
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ $:.unshift(File.dirname(__FILE__))
2
+
3
+ require 'sections/info_section'
4
+ require 'pages/home_page'
5
+
6
+ class TestSite < SeleniumPlus::Site
7
+
8
+ def home_page
9
+ Test::HomePage.new(driver)
10
+ end
11
+
12
+ end
13
+
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: selenium_plus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Spark Yao
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-02-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: selenium-webdriver
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 2.25.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 2.25.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 2.1.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 2.1.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: cucumber
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.2.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: 1.2.1
69
+ description: ''
70
+ email:
71
+ - shipuyao@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/selenium_plus.rb
82
+ - lib/selenium_plus/driver.rb
83
+ - lib/selenium_plus/page_obj/container.rb
84
+ - lib/selenium_plus/page_obj/page.rb
85
+ - lib/selenium_plus/page_obj/section.rb
86
+ - lib/selenium_plus/page_obj/site.rb
87
+ - lib/selenium_plus/selenium/element.rb
88
+ - lib/selenium_plus/selenium/table.rb
89
+ - lib/selenium_plus/version.rb
90
+ - selenium_plus.gemspec
91
+ - test_project/features/search.feature
92
+ - test_project/features/step_definitions/search_steps.rb
93
+ - test_project/test_project.rb
94
+ - test_project/test_site/html/home.html
95
+ - test_project/test_site/pages/home_page.rb
96
+ - test_project/test_site/sections/info_section.rb
97
+ - test_project/test_site/test_site.rb
98
+ homepage: ''
99
+ licenses: []
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.0.0
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: ''
121
+ test_files: []