selenium_plus 0.0.1 → 0.0.2
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 +8 -8
- data/.gitignore +1 -0
- data/Rakefile +1 -1
- data/lib/selenium_plus/exception.rb +6 -0
- data/lib/selenium_plus/page_obj/container.rb +54 -46
- data/lib/selenium_plus/selenium/element.rb +35 -15
- data/lib/selenium_plus/version.rb +1 -1
- data/lib/selenium_plus.rb +46 -9
- data/selenium_plus.gemspec +1 -1
- data/test_project/test_project.rb +15 -10
- data/test_project/test_site/pages/home_page.rb +1 -1
- data/test_project/test_site/sections/info_section.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MmEyMDM1ZjgxNDg3ZmU4M2VlNTllZTIyMDk2NWFhZWEzYWM1YjhjZg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MmMzNjc3MjVlMjY4MDI2N2FkNDRiMGQ2Nzg2MTM4YTJkNmEzM2U2Ng==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MmMwNDA3OWZjNzRmN2ZlODI0NTUyMDUzYmI1NmJjNTg4MWIwMzUxOGE3MDI4
|
10
|
+
OTdkZTA3MjE3YjJlMTNjNDg4ZmU5YTdiYjU4YjAwMWQzNDA2YmQ3ZGFmYTA3
|
11
|
+
OWVkZGE3YjU0ZmRkYzY1ZjM4ZDM5YmNkY2EyZDhjOGMzNGU4MDg=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YjQxNWQ1OTk3NDk4MzgyMTYxOTI4NDZhZmE2NWZmOGRhNjk3ZTViMzI5MjUz
|
14
|
+
ZDRmZWE4M2ZmNWVhNDc5ZjI1OWY0YzE2YzE1OWFiNTZhYWU2OTI3OTcyNzMx
|
15
|
+
YWE4ODIxYjE0ODAyZTAzMDg0Mzc1OGExZjk3N2EzOGFhZWU5OGE=
|
data/.gitignore
CHANGED
data/Rakefile
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -1,73 +1,81 @@
|
|
1
1
|
module SeleniumPlus
|
2
2
|
module Container
|
3
3
|
|
4
|
-
#
|
5
|
-
# and highlight element
|
4
|
+
# Define a new method with the name of the symbol and return an element
|
6
5
|
#
|
7
|
-
#
|
8
|
-
#
|
6
|
+
# Examples:
|
7
|
+
# class DemoPage < SeleniumPlus::Page
|
8
|
+
# element(:username_tb, :id, 'username')
|
9
|
+
# end
|
9
10
|
#
|
10
|
-
#
|
11
|
-
|
12
|
-
|
11
|
+
#
|
12
|
+
# @param [Symbol] name The name of new element
|
13
|
+
# @param [Array] find_args
|
14
|
+
#
|
15
|
+
# @return [Selenium::WebDriver::Element]
|
16
|
+
def element(name, *find_args)
|
17
|
+
define_method(name) do
|
13
18
|
driver.find(*find_args)
|
14
19
|
end
|
15
|
-
add_existence_checker(
|
16
|
-
private
|
20
|
+
add_existence_checker(name, *find_args)
|
21
|
+
private name
|
17
22
|
end
|
18
23
|
|
19
|
-
#
|
24
|
+
# Define a new method with the name of the symbol and return elements
|
20
25
|
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
26
|
+
# Examples:
|
27
|
+
# class DemoPage < SeleniumPlus::Page
|
28
|
+
# elements(:results_list, :css, 'li.view')
|
29
|
+
# end
|
24
30
|
#
|
25
|
-
#
|
26
|
-
|
27
|
-
|
31
|
+
# @param [Symbol] name The name of new elements array
|
32
|
+
# @param [Array] find_args
|
33
|
+
#
|
34
|
+
# @return [Array<Selenium::WebDriver::Element>]
|
35
|
+
def elements(name, *find_args)
|
36
|
+
define_method(name) do
|
28
37
|
driver.all(*find_args)
|
29
38
|
end
|
30
|
-
private
|
39
|
+
private name
|
31
40
|
end
|
32
41
|
|
33
|
-
#
|
42
|
+
# Define partial section of the page
|
34
43
|
#
|
35
|
-
#
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
# Public: Add element name into list
|
44
|
+
# Examples:
|
45
|
+
# class DemoPage < SeleniumPlus::Page
|
46
|
+
# Section(:search_section, SearchSection, :id, 'div#search_me')
|
47
|
+
# end
|
43
48
|
#
|
44
|
-
#
|
45
|
-
|
46
|
-
@element_names ||= []
|
47
|
-
@element_names << element_name
|
48
|
-
end
|
49
|
-
|
50
|
-
# Public: Element names in the page object
|
49
|
+
# @param [Symbol] name The name of new section
|
50
|
+
# @param [Array] find_args
|
51
51
|
#
|
52
|
-
# return
|
53
|
-
def
|
54
|
-
|
52
|
+
# @return [SeleniumPlus::Section]
|
53
|
+
def section(name, section_class, *find_args)
|
54
|
+
define_method(name) do
|
55
|
+
section_class.new(driver, driver.find(*find_args))
|
56
|
+
end
|
55
57
|
end
|
56
58
|
|
57
59
|
private
|
58
60
|
# Define an existence check method
|
59
|
-
#
|
60
|
-
#
|
61
|
+
# This method tries to find element by given locator with no wait time
|
62
|
+
# please make sure your page/section is fully loaded before use this method
|
63
|
+
#
|
64
|
+
# Examples:
|
65
|
+
# class DemoPage < SeleniumPlus::Page
|
66
|
+
# element(:username_tb, :id, 'username')
|
67
|
+
# end
|
68
|
+
#
|
69
|
+
# demo_page = DemoPage.new(driver)
|
70
|
+
# demo_page.has_username_tb?
|
61
71
|
#
|
62
|
-
#
|
63
|
-
#
|
64
|
-
# # => true
|
72
|
+
# @param [Symbol] name The name of new section
|
73
|
+
# @param [Array] find_args
|
65
74
|
#
|
66
|
-
#
|
67
|
-
def add_existence_checker(
|
68
|
-
|
69
|
-
|
70
|
-
all(*find_args).size > 0
|
75
|
+
# @return [Boolean]
|
76
|
+
def add_existence_checker(name, *find_args)
|
77
|
+
define_method("has_#{name.to_s}?") do
|
78
|
+
driver.all(*find_args).size > 0
|
71
79
|
end
|
72
80
|
end
|
73
81
|
end
|
@@ -3,12 +3,28 @@
|
|
3
3
|
class Selenium::WebDriver::Element
|
4
4
|
include SeleniumPlus::Elements::Table
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
# Retrieve the given attribute
|
7
|
+
#
|
8
|
+
# Examples:
|
9
|
+
# element[:name] HTML name attribute
|
10
|
+
#
|
11
|
+
# @param [Symbol] attribute The attribute to retrieve
|
12
|
+
#
|
13
|
+
# @return [String] The value of the attribute
|
14
|
+
def [](attribute)
|
15
|
+
self.attribute(attribute.to_s)
|
8
16
|
rescue Selenium::WebDriver::Error::WebDriverError
|
9
17
|
nil
|
10
18
|
end
|
11
19
|
|
20
|
+
# Set the value of the element to the given value.
|
21
|
+
#
|
22
|
+
# Examples:
|
23
|
+
# element.set('Hello')
|
24
|
+
#
|
25
|
+
# @param [String] value The new value
|
26
|
+
#
|
27
|
+
# @return []
|
12
28
|
def set(value)
|
13
29
|
tag_name = self.tag_name
|
14
30
|
type = self[:type]
|
@@ -27,26 +43,30 @@ class Selenium::WebDriver::Element
|
|
27
43
|
end
|
28
44
|
end
|
29
45
|
|
30
|
-
#
|
46
|
+
# Type text into text field element
|
31
47
|
#
|
32
|
-
#
|
33
|
-
# element.
|
48
|
+
# Examples:
|
49
|
+
# element.type('hello world')
|
34
50
|
#
|
35
|
-
#
|
36
|
-
|
51
|
+
# @param [Symbol] text
|
52
|
+
#
|
53
|
+
# @return []
|
54
|
+
def type(text)
|
37
55
|
self.clear
|
38
|
-
self.set(
|
56
|
+
self.set(text)
|
39
57
|
end
|
40
58
|
|
41
|
-
#
|
59
|
+
# Append text into text field element
|
60
|
+
#
|
61
|
+
# Examples:
|
62
|
+
# element.append('hello world')
|
42
63
|
#
|
43
|
-
#
|
44
|
-
# element.append_text("hello")
|
64
|
+
# @param [Symbol] text
|
45
65
|
#
|
46
|
-
#
|
47
|
-
def append(
|
48
|
-
old = self.
|
49
|
-
self.set(old +
|
66
|
+
# @return []
|
67
|
+
def append(text)
|
68
|
+
old = self.text
|
69
|
+
self.set(old + text)
|
50
70
|
end
|
51
71
|
|
52
72
|
end
|
data/lib/selenium_plus.rb
CHANGED
@@ -1,25 +1,45 @@
|
|
1
1
|
require 'selenium-webdriver'
|
2
|
-
|
3
2
|
require 'selenium_plus/version'
|
3
|
+
require 'selenium_plus/exception'
|
4
4
|
require 'selenium_plus/driver'
|
5
|
-
require 'selenium_plus/page_obj/site'
|
6
5
|
require 'selenium_plus/page_obj/container'
|
6
|
+
require 'selenium_plus/page_obj/site'
|
7
7
|
require 'selenium_plus/page_obj/page'
|
8
8
|
require 'selenium_plus/page_obj/section'
|
9
9
|
require 'selenium_plus/selenium/table'
|
10
10
|
require 'selenium_plus/selenium/element'
|
11
11
|
|
12
12
|
module SeleniumPlus
|
13
|
-
class SeleniumPlusError < StandardError; end
|
14
|
-
class DriverNotFoundError < SeleniumPlusError; end
|
15
13
|
|
16
14
|
class << self
|
17
|
-
attr_accessor :default_driver, :current_driver, :default_wait_time, :
|
15
|
+
attr_accessor :driver, :default_driver, :current_driver, :default_wait_time, :enable_highlight
|
18
16
|
|
17
|
+
# Configure SeleniumPlus
|
18
|
+
#
|
19
|
+
# Examples:
|
20
|
+
# SeleniumPlus.configure do |config|
|
21
|
+
# config.default_wait_time = 10
|
22
|
+
# config.enable_highlight = true
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# [default_wait_time = Integer]
|
26
|
+
# [enable_highlight = Boolean]
|
27
|
+
#
|
19
28
|
def configure
|
20
29
|
yield self
|
21
30
|
end
|
22
31
|
|
32
|
+
# Register a new driver for SeleniumPlus
|
33
|
+
#
|
34
|
+
# Example:
|
35
|
+
# SeleniumPlus.register_driver :chrome_driver do
|
36
|
+
# SeleniumPlus::Driver.new(:browser => :chrome)
|
37
|
+
# end
|
38
|
+
#
|
39
|
+
# @param [Symbol] name The name of the new driver
|
40
|
+
# @yield A block executed in the context of the new {SeleniumPlus::Driver}
|
41
|
+
#
|
42
|
+
# @return [] nothing
|
23
43
|
def register_driver(name, &block)
|
24
44
|
drivers[name] = block
|
25
45
|
end
|
@@ -28,22 +48,39 @@ module SeleniumPlus
|
|
28
48
|
@drivers ||= {}
|
29
49
|
end
|
30
50
|
|
51
|
+
# @return [Symbol] The name of the driver to use by default
|
52
|
+
def default_driver
|
53
|
+
@default_driver || :firefox_driver
|
54
|
+
end
|
55
|
+
|
56
|
+
# @return [Symbol] The name of the driver currently in use
|
31
57
|
def current_driver
|
32
58
|
@current_driver || default_driver
|
33
59
|
end
|
34
60
|
|
61
|
+
# Yield a block using a specific driver
|
62
|
+
#
|
63
|
+
# Example:
|
64
|
+
# SeleniumPlus.using_driver
|
65
|
+
#
|
66
|
+
# @return [SeleniumPlus::Driver] A SeleniumPlus driver instance
|
35
67
|
def using_driver
|
36
|
-
|
68
|
+
@driver ||= begin
|
69
|
+
unless drivers.has_key?(@current_driver)
|
70
|
+
other_drivers = drivers.keys.map { |key| key.inspect }
|
71
|
+
raise SeleniumPlus::Exceptions::DriverNotFoundError, "Driver #{@current_driver} was not found. Available types: #{other_drivers.join(', ')}"
|
72
|
+
end
|
73
|
+
drivers[@current_driver].call
|
74
|
+
end
|
37
75
|
end
|
38
76
|
end
|
39
|
-
|
40
77
|
end
|
41
78
|
|
42
79
|
SeleniumPlus.configure do |config|
|
43
80
|
config.default_wait_time =10
|
44
|
-
config.
|
81
|
+
config.enable_highlight = true
|
45
82
|
end
|
46
83
|
|
47
|
-
SeleniumPlus.register_driver :
|
84
|
+
SeleniumPlus.register_driver :firefox_driver do
|
48
85
|
SeleniumPlus::Driver.new(:browser => :firefox)
|
49
86
|
end
|
data/selenium_plus.gemspec
CHANGED
@@ -6,7 +6,7 @@ require 'selenium_plus/version'
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
7
|
gem.name = 'selenium_plus'
|
8
8
|
gem.version = SeleniumPlus::VERSION
|
9
|
-
gem.authors = ['
|
9
|
+
gem.authors = ['SparkYao']
|
10
10
|
gem.email = %w(shipuyao@gmail.com)
|
11
11
|
gem.description = ''
|
12
12
|
gem.summary = ''
|
@@ -1,21 +1,26 @@
|
|
1
1
|
$:.unshift(File.dirname(__FILE__))
|
2
|
-
require 'selenium_plus'
|
2
|
+
require '../lib/selenium_plus'
|
3
3
|
require 'rspec'
|
4
4
|
require 'test_site/test_site'
|
5
5
|
|
6
|
-
|
6
|
+
|
7
|
+
SeleniumPlus.register_driver :firefox_driver do
|
7
8
|
SeleniumPlus::Driver.new(:browser => :chrome)
|
8
9
|
end
|
9
|
-
#
|
10
|
-
SeleniumPlus.current_driver = :chrome
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
SeleniumPlus.register_driver :chrome_driver do
|
12
|
+
SeleniumPlus::Driver.new(:browser => :chrome)
|
13
|
+
end
|
14
|
+
|
15
|
+
SeleniumPlus.current_driver = :chrome_driver
|
16
|
+
|
17
|
+
#driver = SeleniumPlus.using_driver
|
18
|
+
#driver.visit('http://www.google.com.hk')
|
19
|
+
#driver.find(:id,'lst-ib').type('Mozy')
|
20
|
+
#driver.find(:css,'input[name=btnK]').click
|
21
|
+
#sleep 5
|
17
22
|
|
18
23
|
@Test = TestSite.new
|
19
24
|
@Test.home_page.visit('file:///Users/shipuy/Github/selenium_plus/test_project/test_site/html/home.html')
|
20
25
|
@Test.home_page.show
|
21
|
-
@Test.home_page.info_section.
|
26
|
+
puts @Test.home_page.info_section.has_names_table?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: selenium_plus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- SparkYao
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-02-
|
11
|
+
date: 2013-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -80,6 +80,7 @@ files:
|
|
80
80
|
- Rakefile
|
81
81
|
- lib/selenium_plus.rb
|
82
82
|
- lib/selenium_plus/driver.rb
|
83
|
+
- lib/selenium_plus/exception.rb
|
83
84
|
- lib/selenium_plus/page_obj/container.rb
|
84
85
|
- lib/selenium_plus/page_obj/page.rb
|
85
86
|
- lib/selenium_plus/page_obj/section.rb
|