watir-jquery 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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +63 -0
- data/Rakefile +12 -0
- data/lib/watir-jquery.rb +55 -0
- data/lib/watir-jquery/version.rb +3 -0
- data/test/fixtures/no-jquery.html +20 -0
- data/test/fixtures/test.html +24 -0
- data/test/lib/watir-jquery_test.rb +59 -0
- data/watir-jquery.gemspec +22 -0
- metadata +91 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Brian Olore
|
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,63 @@
|
|
1
|
+
# jQuery selectors for your Watir tests
|
2
|
+
|
3
|
+
watir-jquery allows you to use the jQuery selectors you already know and love from with your Watir tests.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'watir-jquery'
|
10
|
+
or
|
11
|
+
gem 'watir-jquery', :git => 'git://github.com/olore/watir-jquery.git'
|
12
|
+
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install watir-jquery
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
```
|
24
|
+
require 'test/unit'
|
25
|
+
require 'watir-webdriver'
|
26
|
+
require 'watir-jquery'
|
27
|
+
|
28
|
+
class MyTest < Test::Unit::TestCase
|
29
|
+
|
30
|
+
def teardown
|
31
|
+
@browser.close
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_one
|
35
|
+
@browser = Watir::Browser.new
|
36
|
+
@browser.goto "http://yahoo.com"
|
37
|
+
|
38
|
+
via_watir = @browser.div(:id => 'masthead') #OLD WAY
|
39
|
+
via_jquery = @browser.jq('#masthead') #COOL WAY
|
40
|
+
|
41
|
+
p via_watir
|
42
|
+
p via_jquery
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
```
|
47
|
+
|
48
|
+
Outputs:
|
49
|
+
```
|
50
|
+
# Running tests:
|
51
|
+
|
52
|
+
#<Watir::Div:0x..fe36c3523ec07067c located=false selector={:id=>"masthead", :tag_name=>"div"}>
|
53
|
+
#<Watir::Div:0x..fc84751a76dcd874c located=false selector={:id=>"masthead", :class=>"main-col cf", :tag_name=>"div"}>
|
54
|
+
.
|
55
|
+
```
|
56
|
+
|
57
|
+
## Contributing
|
58
|
+
|
59
|
+
1. Fork it
|
60
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
61
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
62
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
63
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/watir-jquery.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require "watir-jquery/version"
|
2
|
+
|
3
|
+
module WatirJquery
|
4
|
+
PATH_TO_JQUERY = 'http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js'
|
5
|
+
|
6
|
+
def jquery(selector)
|
7
|
+
define_jquery unless jquery_defined?
|
8
|
+
|
9
|
+
script = "var a=jQuery('#{selector}'); var b=[];for(var i =0; i< a.length; i++){b[i] = a[i]}return b;"
|
10
|
+
elements = browser.execute_script(script)
|
11
|
+
return elements[0] unless elements.count > 1
|
12
|
+
|
13
|
+
# This would be nice, but can't figure out how to instantiate
|
14
|
+
# see watir-webdriver/element_collection.rb
|
15
|
+
# Watir::DivCollection.new(elements)
|
16
|
+
|
17
|
+
elements
|
18
|
+
end
|
19
|
+
|
20
|
+
alias jq jquery
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def jquery_defined?
|
25
|
+
browser.execute_script("return typeof jQuery;") != "undefined"
|
26
|
+
end
|
27
|
+
|
28
|
+
def define_jquery
|
29
|
+
script = "var scr = document.createElement('script'); scr.src='#{PATH_TO_JQUERY}'; document.getElementsByTagName('body')[0].appendChild(scr);"
|
30
|
+
browser.execute_script(script)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
module Watir
|
36
|
+
class Browser
|
37
|
+
include WatirJquery
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
# override Watir::Browser#wrap_element
|
42
|
+
def wrap_element(element)
|
43
|
+
# if (element.tag_name == "input" && element.attribute("type") == "submit")
|
44
|
+
# Watir.element_class_for("button").new(self, :element => element)
|
45
|
+
# else
|
46
|
+
attrs = {}
|
47
|
+
attrs[:id] = element.attribute(:id) unless element.attribute(:id) == ""
|
48
|
+
attrs[:class] = element.attribute(:class) unless element.attribute(:class) == ""
|
49
|
+
attrs[:tag_name] = element.tag_name
|
50
|
+
Watir.element_class_for(element.tag_name.downcase).new(self, attrs)
|
51
|
+
# end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<head>
|
2
|
+
<meta charset="utf-8">
|
3
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
4
|
+
<title></title>
|
5
|
+
<meta name="description" content="">
|
6
|
+
<meta name="viewport" content="width=device-width">
|
7
|
+
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
<div id="div1">Hello world!</div>
|
11
|
+
|
12
|
+
<div class="one"></div>
|
13
|
+
|
14
|
+
<div id="four1" class="four"></div>
|
15
|
+
<div id="four2" class="four"></div>
|
16
|
+
<div id="four3" class="four"></div>
|
17
|
+
<div id="four4" class="four"></div>
|
18
|
+
|
19
|
+
</body>
|
20
|
+
</html>
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<head>
|
3
|
+
<meta charset="utf-8">
|
4
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
5
|
+
<title></title>
|
6
|
+
<meta name="description" content="">
|
7
|
+
<meta name="viewport" content="width=device-width">
|
8
|
+
|
9
|
+
</head>
|
10
|
+
<body>
|
11
|
+
<div id="div1">Hello world!</div>
|
12
|
+
|
13
|
+
<div class="one"></div>
|
14
|
+
|
15
|
+
<div id="four1" class="four 1"></div>
|
16
|
+
<div id="four2" class="four 2"></div>
|
17
|
+
<div id="four3" class="four 3"></div>
|
18
|
+
<div id="four4" class="four 4"></div>
|
19
|
+
|
20
|
+
|
21
|
+
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
|
22
|
+
|
23
|
+
</body>
|
24
|
+
</html>
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'watir-webdriver'
|
3
|
+
require File.expand_path('../../../lib/watir-jquery.rb', __FILE__)
|
4
|
+
|
5
|
+
class WatirJqueryTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
FIXTURES_DIR = "#{File.expand_path(File.dirname(__FILE__))}/../fixtures"
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
@browser.close
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_selecting_by_jquery_returns_same_selector_info_as_by_div
|
14
|
+
open_test_file
|
15
|
+
by_div = @browser.div(:id => 'div1')
|
16
|
+
by_jquery = @browser.jq('#div1')
|
17
|
+
|
18
|
+
assert_equal by_div.instance_variable_get(:@selector), by_jquery.instance_variable_get(:@selector)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_matching_element_by_class
|
22
|
+
open_test_file
|
23
|
+
by_div = @browser.div(:class => 'one')
|
24
|
+
by_jquery = @browser.jq('.one')
|
25
|
+
|
26
|
+
assert_equal by_div.instance_variable_get(:@selector), by_jquery.instance_variable_get(:@selector)
|
27
|
+
end
|
28
|
+
|
29
|
+
# multiples works differently in that instead of returning
|
30
|
+
# a DivCollection, it returns a Div[]
|
31
|
+
def test_matching_multiple_elements_by_class
|
32
|
+
open_test_file
|
33
|
+
by_div = @browser.divs(:class => 'four')
|
34
|
+
by_jquery = @browser.jq('.four')
|
35
|
+
|
36
|
+
assert_equal by_div.count, by_jquery.count, "Didn't get the same counts!"
|
37
|
+
assert_equal by_div.map{|d| d.class_name}, by_jquery.map{|d| d.class_name}, "Class names of selected elements are different!"
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_jquery_defined
|
41
|
+
open_test_file
|
42
|
+
assert_equal true, @browser.send(:jquery_defined?)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_jquery_is_not_defined
|
46
|
+
open_test_file("no-jquery.html")
|
47
|
+
assert_equal false, @browser.send(:jquery_defined?)
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def open_test_file(file = "test.html")
|
53
|
+
@browser = Watir::Browser.new
|
54
|
+
#@browser.goto "file://#{File.expand_path(File.dirname(__FILE__))}/#{file}"
|
55
|
+
@browser.goto "file://#{FIXTURES_DIR}/#{file}"
|
56
|
+
@browser.wait
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'watir-jquery/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "watir-jquery"
|
8
|
+
gem.version = WatirJquery::VERSION
|
9
|
+
gem.authors = ["Brian Olore"]
|
10
|
+
gem.email = ["brian@olore.net"]
|
11
|
+
gem.description = %q{Provides abilty to use jQuery selectors in Watir tests}
|
12
|
+
gem.summary = %q{Provides abilty to use jQuery selectors in Watir tests}
|
13
|
+
gem.homepage = "https://github.com/olore/errational"
|
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 = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency 'rake'
|
21
|
+
gem.add_development_dependency 'watir-webdriver'
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: watir-jquery
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Brian Olore
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: watir-webdriver
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Provides abilty to use jQuery selectors in Watir tests
|
47
|
+
email:
|
48
|
+
- brian@olore.net
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- lib/watir-jquery.rb
|
59
|
+
- lib/watir-jquery/version.rb
|
60
|
+
- test/fixtures/no-jquery.html
|
61
|
+
- test/fixtures/test.html
|
62
|
+
- test/lib/watir-jquery_test.rb
|
63
|
+
- watir-jquery.gemspec
|
64
|
+
homepage: https://github.com/olore/errational
|
65
|
+
licenses: []
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 1.8.24
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: Provides abilty to use jQuery selectors in Watir tests
|
88
|
+
test_files:
|
89
|
+
- test/fixtures/no-jquery.html
|
90
|
+
- test/fixtures/test.html
|
91
|
+
- test/lib/watir-jquery_test.rb
|