watir-or 0.0.4 → 1.0.0
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/lib/watir-or.rb +4 -8
- data/lib/watir-or/element.rb +33 -39
- data/lib/watir-or/readers/xls.rb +10 -16
- data/lib/watir-or/readers/xml.rb +13 -13
- data/lib/watir-or/repository.rb +29 -25
- data/spec/{browser_stub.rb → browser_mock.rb} +2 -3
- data/spec/custom_elements_spec.rb +4 -6
- data/spec/find_elements_spec.rb +5 -23
- data/spec/read_rb_spec.rb +18 -0
- data/spec/read_xls_spec.rb +18 -29
- data/spec/read_xml_spec.rb +7 -15
- data/spec/spec_helper.rb +2 -2
- data/spec/test.rb +9 -0
- data/spec/test.xls +0 -0
- data/spec/test.xml +7 -31
- data/spec/test_duplicating_id.xls +0 -0
- metadata +8 -8
- data/lib/watir-or/converters/element_converter.rb +0 -27
- data/spec/watir_builder_spec.rb +0 -36
data/lib/watir-or.rb
CHANGED
@@ -1,9 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
}
|
1
|
+
require File.join(File.dirname(__FILE__), 'watir-or/readers/xls')
|
2
|
+
require File.join(File.dirname(__FILE__), 'watir-or/readers/xml')
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
}
|
8
|
-
require 'watir-or/element'
|
9
|
-
require 'watir-or/repository'
|
4
|
+
require File.join(File.dirname(__FILE__), 'watir-or/element')
|
5
|
+
require File.join(File.dirname(__FILE__), 'watir-or/repository')
|
data/lib/watir-or/element.rb
CHANGED
@@ -1,71 +1,65 @@
|
|
1
1
|
module ObjectRepository
|
2
2
|
class RepositoryElement
|
3
|
-
attr_reader :
|
3
|
+
attr_reader :name
|
4
4
|
|
5
|
-
def initialize(
|
6
|
-
@
|
7
|
-
@description = description #.dup
|
8
|
-
@type = type.dup
|
9
|
-
@hows, @whats = hows.dup, whats.dup
|
5
|
+
def initialize(name, repository, &block)
|
6
|
+
@name = name
|
10
7
|
@repository = repository
|
8
|
+
instance_eval &block
|
11
9
|
end
|
12
10
|
|
13
11
|
def inspect
|
14
|
-
"Element #{@
|
12
|
+
"Element #{@name.inspect}"
|
15
13
|
end
|
16
14
|
|
17
15
|
def ==(other)
|
18
|
-
@
|
16
|
+
@name == other.name
|
19
17
|
end
|
20
18
|
end
|
21
19
|
|
22
20
|
class WatirElement < RepositoryElement
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
super(id, type, hows, whats, description, repository)
|
28
|
-
transform_whats!
|
29
|
-
@locator = Hash[*@hows.zip(@whats).flatten]
|
21
|
+
def locate(&block)
|
22
|
+
if block_given?
|
23
|
+
@locate_block = block
|
24
|
+
end
|
30
25
|
end
|
31
26
|
|
32
27
|
def method_missing(meth_name, *args, &block)
|
33
|
-
@
|
34
|
-
if @watir_obj.respond_to?(meth_name) || meth_name.to_s.include?("_no_wait")
|
35
|
-
@watir_obj.send(meth_name, *args, &block)
|
36
|
-
else
|
37
|
-
super
|
38
|
-
end
|
28
|
+
@locate_block.call(@repository).send(meth_name, *args, &block)
|
39
29
|
end
|
40
30
|
|
41
31
|
def present?
|
42
32
|
method_missing(:present?)
|
43
33
|
end
|
44
|
-
|
45
|
-
private
|
46
|
-
|
47
|
-
def transform_whats!
|
48
|
-
@hows.each_with_index do |how, index|
|
49
|
-
if how == :index
|
50
|
-
@whats[index] = @whats[index].to_i
|
51
|
-
elsif @whats[index] =~ /^\/(.*)\/$/ && how != :xpath
|
52
|
-
@whats[index] = Regexp.new($1)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
34
|
end
|
57
35
|
|
58
36
|
class CustomElement < RepositoryElement
|
59
37
|
def initialize(*args)
|
60
|
-
super(*args)
|
61
38
|
@attributes = {}
|
62
|
-
|
63
|
-
|
39
|
+
super(*args)
|
40
|
+
end
|
41
|
+
|
42
|
+
def field(name, field_name = nil, &block)
|
43
|
+
if block_given?
|
44
|
+
@attributes[name] = block
|
45
|
+
return
|
46
|
+
end
|
47
|
+
|
48
|
+
if field_name
|
49
|
+
@attributes[name] = field_name
|
50
|
+
else
|
51
|
+
get_field(name)
|
64
52
|
end
|
65
53
|
end
|
66
54
|
|
67
|
-
|
68
|
-
|
55
|
+
private
|
56
|
+
|
57
|
+
def get_field(name)
|
58
|
+
if @attributes[name].is_a?(String)
|
59
|
+
@repository.get(@attributes[name])
|
60
|
+
else
|
61
|
+
@attributes[name].call(@repository)
|
62
|
+
end
|
69
63
|
end
|
70
64
|
end
|
71
|
-
end
|
65
|
+
end
|
data/lib/watir-or/readers/xls.rb
CHANGED
@@ -19,27 +19,21 @@ module ObjectRepository
|
|
19
19
|
|
20
20
|
def self.read_worksheet(worksheet, &block)
|
21
21
|
rows_count = worksheet.row_count
|
22
|
-
hows = Array.new
|
23
|
-
whats = Array.new
|
24
|
-
rep_id = nil
|
25
|
-
description = nil
|
26
|
-
type = nil
|
27
22
|
worksheet.each(1) { |row| # each(1) exclude header
|
28
|
-
unless row[0].nil?
|
29
|
-
hows.clear
|
30
|
-
whats.clear
|
31
|
-
rep_id = row[0]
|
32
|
-
type = row[1]
|
33
|
-
description = row[4]
|
34
|
-
end
|
35
|
-
hows << row[2]
|
36
|
-
whats << row[3]
|
37
23
|
if (!worksheet.row(row.idx + 1)[0].nil? || row.idx + 1 >= rows_count )
|
38
|
-
|
24
|
+
name = row[0]
|
25
|
+
type = nil
|
26
|
+
locate_block = if row[2].nil?
|
27
|
+
Proc.new { locate { |repository| eval(row[1]) } }
|
28
|
+
else
|
29
|
+
type = eval(row[2])
|
30
|
+
Proc.new { |repository| eval(row[1]) }
|
31
|
+
end
|
32
|
+
yield name, type, locate_block
|
39
33
|
end
|
40
34
|
}
|
41
35
|
end
|
42
36
|
end
|
43
37
|
end
|
44
38
|
end
|
45
|
-
|
39
|
+
|
data/lib/watir-or/readers/xml.rb
CHANGED
@@ -5,19 +5,19 @@ module ObjectRepository
|
|
5
5
|
|
6
6
|
def self.read(file, options = nil, &block)
|
7
7
|
doc = Nokogiri::XML(File.read(file), nil, 'UTF-8', Nokogiri::XML::ParseOptions::NOBLANKS)
|
8
|
-
doc.root.xpath("//object").each
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
yield
|
19
|
-
|
8
|
+
doc.root.xpath("//object").each do |node|
|
9
|
+
name = node['name']
|
10
|
+
type = nil
|
11
|
+
locate = node.search('./locate').first.content
|
12
|
+
locate_block = if node['type'].nil?
|
13
|
+
Proc.new { locate { |repository| eval(locate) } }
|
14
|
+
else
|
15
|
+
type = eval(node['type'])
|
16
|
+
Proc.new { |repository| eval(locate) }
|
17
|
+
end
|
18
|
+
yield name, type, locate_block
|
19
|
+
end
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
23
|
-
end
|
23
|
+
end
|
data/lib/watir-or/repository.rb
CHANGED
@@ -5,7 +5,7 @@ module ObjectRepository
|
|
5
5
|
|
6
6
|
def initialize(file, browser, options = nil)
|
7
7
|
@file = file
|
8
|
-
@elements =
|
8
|
+
@elements = []
|
9
9
|
@browser = browser
|
10
10
|
@type = File.extname(@file).delete('.')
|
11
11
|
fill_elements(options)
|
@@ -15,19 +15,12 @@ module ObjectRepository
|
|
15
15
|
@elements.each { |el| yield el }
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
19
|
-
element =
|
20
|
-
|
21
|
-
find { |el| el.instance_variable_get("@#{$1.to_sym}") == what }
|
22
|
-
when "get"
|
23
|
-
find { |el| el.rep_id == what || el.description == what }
|
24
|
-
else
|
25
|
-
super
|
26
|
-
end
|
27
|
-
raise "Couldn't find repository element with #{what.inspect}" if element.nil?
|
18
|
+
def get(name)
|
19
|
+
element = find { |el| el.name == name }
|
20
|
+
raise "Couldn't find repository element with #{name.inspect}" if element.nil?
|
28
21
|
return element
|
29
22
|
end
|
30
|
-
|
23
|
+
|
31
24
|
def inspect
|
32
25
|
@elements.inspect
|
33
26
|
end
|
@@ -35,19 +28,30 @@ module ObjectRepository
|
|
35
28
|
private
|
36
29
|
|
37
30
|
def fill_elements(options)
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
31
|
+
reader_class = case @type.downcase
|
32
|
+
when 'xml'
|
33
|
+
ObjectRepository::Reader::XML
|
34
|
+
when 'xls'
|
35
|
+
ObjectRepository::Reader::XLS
|
36
|
+
when 'rb'
|
37
|
+
instance_eval(File.read(file), file)
|
38
|
+
return
|
39
|
+
else
|
40
|
+
raise "Unknown type #{@type.inspect} of repository"
|
41
|
+
end
|
42
|
+
|
43
|
+
reader_class.read(@file, options) do |name, type, block|
|
44
|
+
element(name, type, &block)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def element(name, type = nil, &block)
|
49
|
+
raise "Duplicating of name: #{name.inspect}" if @elements.find { |el| el.name == name }
|
50
|
+
@elements << unless type
|
51
|
+
WatirElement.new(name, self, &block)
|
52
|
+
else
|
53
|
+
type.new(name, self, &block)
|
48
54
|
end
|
49
|
-
rescue NameError
|
50
|
-
raise "Unknown type #{@type.inspect} of repository"
|
51
55
|
end
|
52
56
|
end
|
53
|
-
end
|
57
|
+
end
|
@@ -1,7 +1,6 @@
|
|
1
|
-
class
|
1
|
+
class BrowserMock
|
2
2
|
def method_missing(meth_name, *args, &block)
|
3
3
|
Control.new
|
4
|
-
# return "%s(%s)" % [meth_name, args.first.inspect.gsub(/(^\{|\}$)/, "")]
|
5
4
|
end
|
6
5
|
end
|
7
6
|
|
@@ -9,4 +8,4 @@ class Control
|
|
9
8
|
def method_missing(meth_name, *args, &block)
|
10
9
|
Control.new
|
11
10
|
end
|
12
|
-
end
|
11
|
+
end
|
@@ -1,21 +1,19 @@
|
|
1
1
|
require 'lib/watir-or'
|
2
|
-
require 'spec/browser_stub'
|
3
2
|
require 'spec/spec_helper'
|
4
3
|
TEST_FILE = "spec/test.xls"
|
5
4
|
|
6
5
|
describe "CustomElement" do
|
7
6
|
before(:all) do
|
8
|
-
@browser_stub =
|
7
|
+
@browser_stub = BrowserMock.new
|
9
8
|
@repository = ObjectRepository::Repository.new(TEST_FILE, @browser_stub)
|
10
9
|
end
|
11
10
|
|
12
11
|
it "should return MyCustomElement object" do
|
13
|
-
@repository.get("
|
12
|
+
@repository.get("Custom Element").should be_a(MyCustomElement)
|
14
13
|
end
|
15
14
|
|
16
15
|
it "should return field of MyCustomElement object" do
|
17
|
-
attr1 = ObjectRepository::
|
18
|
-
|
19
|
-
@repository.get("custom element").field(:attr1).should == attr1
|
16
|
+
attr1 = ObjectRepository::WatirElement.new("Element with one attribute", @repository) { |block| block }
|
17
|
+
@repository.get("Custom Element").field(:attr1).should == attr1
|
20
18
|
end
|
21
19
|
end
|
data/spec/find_elements_spec.rb
CHANGED
@@ -1,36 +1,18 @@
|
|
1
1
|
require 'lib/watir-or.rb'
|
2
|
-
require 'spec/browser_stub'
|
3
2
|
require 'spec/spec_helper'
|
4
3
|
|
5
4
|
describe "Search of elements" do
|
6
5
|
before(:all) do
|
7
|
-
@browser_stub =
|
6
|
+
@browser_stub = BrowserMock.new
|
8
7
|
@repository = ObjectRepository::Repository.new("spec/test.xls", @browser_stub)
|
9
|
-
@element = ObjectRepository::
|
10
|
-
["test text", 1], "Element with many attributes", @repository)
|
8
|
+
@element = ObjectRepository::WatirElement.new("Element with many attributes", @repository) { }
|
11
9
|
end
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
@repository.get("many attributes").should == @element
|
16
|
-
end
|
17
|
-
|
18
|
-
it "description" do
|
19
|
-
@repository.get("Element with many attributes").should == @element
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context "find by" do
|
24
|
-
it "id" do
|
25
|
-
@repository.get_by_rep_id("many attributes").should == @element
|
26
|
-
end
|
27
|
-
|
28
|
-
it "description" do
|
29
|
-
@repository.get_by_description("Element with many attributes").should == @element
|
30
|
-
end
|
11
|
+
it "find by name" do
|
12
|
+
@repository.get("Element with many attributes").should == @element
|
31
13
|
end
|
32
14
|
|
33
15
|
it "should raise exception when element wasn't found" do
|
34
16
|
lambda{@repository.get("fake element")}.should raise_error
|
35
17
|
end
|
36
|
-
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'lib/watir-or.rb'
|
2
|
+
require 'spec/spec_helper'
|
3
|
+
|
4
|
+
describe "Read xls-repository" do
|
5
|
+
before(:all) do
|
6
|
+
@repository = ObjectRepository::Repository.new("spec/test.rb", BrowserMock.new)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "get watir element" do
|
10
|
+
one = ObjectRepository::WatirElement.new("Watir Element", @repository) { }
|
11
|
+
@repository.get("Watir Element").should == one
|
12
|
+
end
|
13
|
+
|
14
|
+
it "get custom element" do
|
15
|
+
custom = MyCustomElement.new("Custom Element", @repository) { }
|
16
|
+
@repository.get("Custom Element").should == custom
|
17
|
+
end
|
18
|
+
end
|
data/spec/read_xls_spec.rb
CHANGED
@@ -2,58 +2,47 @@ require 'lib/watir-or.rb'
|
|
2
2
|
require 'spec/spec_helper'
|
3
3
|
|
4
4
|
describe "Read xls-repository" do
|
5
|
-
context "
|
5
|
+
context "On first worksheet" do
|
6
6
|
before(:all) do
|
7
|
-
@repository = ObjectRepository::Repository.new("spec/test.xls",
|
7
|
+
@repository = ObjectRepository::Repository.new("spec/test.xls", BrowserMock.new)
|
8
8
|
end
|
9
9
|
|
10
|
-
it "
|
11
|
-
one = ObjectRepository::
|
12
|
-
|
13
|
-
@repository.get("one attribute").should == one
|
10
|
+
it "get watir element" do
|
11
|
+
one = ObjectRepository::WatirElement.new("Element with many attributes", @repository) { }
|
12
|
+
@repository.get("Element with many attributes").should == one
|
14
13
|
end
|
15
14
|
|
16
|
-
it "
|
17
|
-
|
18
|
-
|
19
|
-
@repository.get("many attributes").should == many
|
20
|
-
end
|
21
|
-
|
22
|
-
it "last element with many attribute was readed" do
|
23
|
-
last_many = ObjectRepository::RepositoryElement.new("last element with many attributes", "image",
|
24
|
-
[:name, :src], ["xxx", "path"], "Last element with many attributes", @repository)
|
25
|
-
@repository.get("last element with many attributes").should == last_many
|
15
|
+
it "get custom element" do
|
16
|
+
custom = MyCustomElement.new("Custom Element", @repository) { }
|
17
|
+
@repository.get("Custom Element").should == custom
|
26
18
|
end
|
27
19
|
end
|
28
20
|
|
29
21
|
context "Read special worksheet" do
|
30
22
|
before(:all) do
|
31
|
-
@repository = ObjectRepository::Repository.new("spec/test.xls",
|
23
|
+
@repository = ObjectRepository::Repository.new("spec/test.xls", BrowserMock.new, :worksheet => "special worksheet")
|
32
24
|
end
|
33
25
|
|
34
26
|
it "should read element on special workheet" do
|
35
|
-
first = ObjectRepository::
|
36
|
-
|
37
|
-
@repository.get("first element").should == first
|
27
|
+
first = ObjectRepository::WatirElement.new("First element on special worksheet", @repository) { }
|
28
|
+
@repository.get("First element on special worksheet").should == first
|
38
29
|
end
|
39
30
|
end
|
40
31
|
|
41
32
|
context "Read all worksheets" do
|
42
33
|
before(:all) do
|
43
|
-
@repository = ObjectRepository::Repository.new("spec/test.xls",
|
34
|
+
@repository = ObjectRepository::Repository.new("spec/test.xls", BrowserMock.new, :worksheet => :all)
|
44
35
|
end
|
45
36
|
|
46
37
|
it "should read all elements on all workheets" do
|
47
|
-
on_first_worksheet = ObjectRepository::
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
@repository.get("one attribute").should == on_first_worksheet
|
52
|
-
@repository.get("first element").should == on_special_worksheet
|
38
|
+
on_first_worksheet = ObjectRepository::WatirElement.new("Element with one attribute", @repository) { }
|
39
|
+
on_special_worksheet = ObjectRepository::WatirElement.new("First element on special worksheet", @repository) { }
|
40
|
+
@repository.get("Element with one attribute").should == on_first_worksheet
|
41
|
+
@repository.get("First element on special worksheet").should == on_special_worksheet
|
53
42
|
end
|
54
43
|
end
|
55
44
|
|
56
45
|
it "duplicating of id" do
|
57
|
-
lambda { ObjectRepository::Repository.new("spec/test_duplicating_id.xls",
|
46
|
+
lambda { ObjectRepository::Repository.new("spec/test_duplicating_id.xls", BrowserMock.new) }.should raise_error
|
58
47
|
end
|
59
|
-
end
|
48
|
+
end
|
data/spec/read_xml_spec.rb
CHANGED
@@ -3,24 +3,16 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
describe "Read xml-repository" do
|
5
5
|
before(:all) do
|
6
|
-
@repository = ObjectRepository::Repository.new("spec/test.xml",
|
6
|
+
@repository = ObjectRepository::Repository.new("spec/test.xml", BrowserMock.new)
|
7
7
|
end
|
8
8
|
|
9
9
|
it "element with one attribute was readed" do
|
10
|
-
one = ObjectRepository::
|
11
|
-
|
12
|
-
@repository.get("one attribute").should == one
|
10
|
+
one = ObjectRepository::WatirElement.new("Element with one attribute", @repository) { }
|
11
|
+
@repository.get("Element with one attribute").should == one
|
13
12
|
end
|
14
13
|
|
15
|
-
it "element
|
16
|
-
|
17
|
-
|
18
|
-
@repository.get("many attributes").should == many
|
14
|
+
it "custom element" do
|
15
|
+
custom = MyCustomElement.new("Custom Element", @repository) { }
|
16
|
+
@repository.get("Custom Element").should == custom
|
19
17
|
end
|
20
|
-
|
21
|
-
it "child element was readed" do
|
22
|
-
child = ObjectRepository::RepositoryElement.new("with parent", "div", [:index, :parent],
|
23
|
-
[3, "parent element"], "Element with parent", @repository)
|
24
|
-
@repository.get("with parent").should == child
|
25
|
-
end
|
26
|
-
end
|
18
|
+
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/test.rb
ADDED
data/spec/test.xls
CHANGED
Binary file
|
data/spec/test.xml
CHANGED
@@ -1,35 +1,11 @@
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
2
2
|
<repository>
|
3
|
-
<object
|
4
|
-
|
5
|
-
<name>test</name>
|
6
|
-
</how>
|
7
|
-
<description>Element with one attribute</description>
|
3
|
+
<object name="Element with one attribute">
|
4
|
+
<locate>reposiroty.browser.text_field(:name => "name")</locate>
|
8
5
|
</object>
|
9
|
-
<object type="
|
10
|
-
<
|
11
|
-
|
12
|
-
|
13
|
-
</how>
|
14
|
-
<description>Element with many attributes</description>
|
6
|
+
<object type="MyCustomElement" name="Custom Element">
|
7
|
+
<locate>
|
8
|
+
field :attr1, "Element with one attribute"
|
9
|
+
</locate>
|
15
10
|
</object>
|
16
|
-
|
17
|
-
<how>
|
18
|
-
<index>1</index>
|
19
|
-
</how>
|
20
|
-
<description>Parent element</description>
|
21
|
-
<object type="div" id="with parent">
|
22
|
-
<how>
|
23
|
-
<index>3</index>
|
24
|
-
</how>
|
25
|
-
<description>Element with parent</description>
|
26
|
-
</object>
|
27
|
-
</object>
|
28
|
-
<object type="MyCustomElement" id="custom element">
|
29
|
-
<how>
|
30
|
-
<attr1>one attribute</attr1>
|
31
|
-
<attr2>many attributes</attr2>
|
32
|
-
</how>
|
33
|
-
<description>Custom Element</description>
|
34
|
-
</object>
|
35
|
-
</repository>
|
11
|
+
</repository>
|
Binary file
|
metadata
CHANGED
@@ -3,10 +3,10 @@ name: watir-or
|
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
|
+
- 1
|
6
7
|
- 0
|
7
8
|
- 0
|
8
|
-
|
9
|
-
version: 0.0.4
|
9
|
+
version: 1.0.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Ivan Kabluchkov
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-06-
|
17
|
+
date: 2011-06-29 00:00:00 +04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -59,25 +59,25 @@ extra_rdoc_files:
|
|
59
59
|
files:
|
60
60
|
- README
|
61
61
|
- Rakefile
|
62
|
-
- lib/watir-or/converters/element_converter.rb
|
63
62
|
- lib/watir-or/element.rb
|
64
63
|
- lib/watir-or/readers/xls.rb
|
65
64
|
- lib/watir-or/readers/xml.rb
|
66
65
|
- lib/watir-or/repository.rb
|
67
66
|
- lib/watir-or.rb
|
68
|
-
- spec/
|
67
|
+
- spec/browser_mock.rb
|
69
68
|
- spec/custom_elements_spec.rb
|
70
69
|
- spec/find_elements_spec.rb
|
70
|
+
- spec/read_rb_spec.rb
|
71
71
|
- spec/read_xls_spec.rb
|
72
72
|
- spec/read_xml_spec.rb
|
73
73
|
- spec/spec.opts
|
74
74
|
- spec/spec_helper.rb
|
75
|
+
- spec/test.rb
|
75
76
|
- spec/test.xls
|
76
77
|
- spec/test.xml
|
77
78
|
- spec/test_duplicating_id.xls
|
78
|
-
- spec/watir_builder_spec.rb
|
79
79
|
has_rdoc: true
|
80
|
-
homepage:
|
80
|
+
homepage: https://github.com/lfidnl/watir-or
|
81
81
|
licenses: []
|
82
82
|
|
83
83
|
post_install_message:
|
@@ -111,6 +111,6 @@ summary: Object Repository for Watir
|
|
111
111
|
test_files:
|
112
112
|
- spec/custom_elements_spec.rb
|
113
113
|
- spec/find_elements_spec.rb
|
114
|
+
- spec/read_rb_spec.rb
|
114
115
|
- spec/read_xls_spec.rb
|
115
116
|
- spec/read_xml_spec.rb
|
116
|
-
- spec/watir_builder_spec.rb
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module ObjectRepository
|
2
|
-
module WatirObjectBuilder
|
3
|
-
def self.build_watir_obj(repository, rep_element)
|
4
|
-
eval("repository.browser.#{build_element(rep_element, repository)}")
|
5
|
-
end
|
6
|
-
|
7
|
-
def self.build_element(rep_element, repository)
|
8
|
-
parent = ""
|
9
|
-
unless rep_element.locator[:parent].nil?
|
10
|
-
parent = build_element(repository.find { |el| el.rep_id == rep_element.locator[:parent] }, repository) + "."
|
11
|
-
end
|
12
|
-
locator = rep_element.locator.dup
|
13
|
-
locator.delete(:parent)
|
14
|
-
parent << "%s(%s)" % [rep_element.type, build_locator(locator)]
|
15
|
-
end
|
16
|
-
|
17
|
-
#Method need for separate frame(:name => "foo") and frame(:name, "foo").
|
18
|
-
#Because frame with multiply conditions doesn't work
|
19
|
-
def self.build_locator(locator)
|
20
|
-
if locator.length > 1
|
21
|
-
locator.inspect.gsub(/(^\{|\}$)/, "")
|
22
|
-
else
|
23
|
-
":%s,%s" % [locator.keys.first, locator[locator.keys.first].inspect]
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
data/spec/watir_builder_spec.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'lib/watir-or.rb'
|
2
|
-
require 'spec/browser_stub'
|
3
|
-
require 'spec/spec_helper'
|
4
|
-
|
5
|
-
describe "WatirObjectBuilder" do
|
6
|
-
before(:all) do
|
7
|
-
@browser_stub = BrowserStub.new
|
8
|
-
@repository = ObjectRepository::Repository.new("spec/test.xls", @browser_stub)
|
9
|
-
end
|
10
|
-
|
11
|
-
it "build watir object properly" do
|
12
|
-
element = @repository.get('many attributes')
|
13
|
-
built = ObjectRepository::WatirObjectBuilder.build_element(element, @repository)
|
14
|
-
built.should == 'select_list(:index=>1, :text=>"test text")'
|
15
|
-
end
|
16
|
-
|
17
|
-
it "build element with regexp" do
|
18
|
-
element = @repository.get('with regexp what')
|
19
|
-
built = ObjectRepository::WatirObjectBuilder.build_element(element, @repository)
|
20
|
-
built.should == 'text_field(:text,/regexp/)'
|
21
|
-
end
|
22
|
-
|
23
|
-
context "hierarchy" do
|
24
|
-
it "watir object which has one parent" do
|
25
|
-
element = @repository.get('with parent')
|
26
|
-
built = ObjectRepository::WatirObjectBuilder.build_element(element, @repository)
|
27
|
-
built.should == 'div(:index,1).div(:index,3)'
|
28
|
-
end
|
29
|
-
|
30
|
-
it "2 level" do
|
31
|
-
element = @repository.get('2 level hierarchy')
|
32
|
-
built = ObjectRepository::WatirObjectBuilder.build_element(element, @repository)
|
33
|
-
built.should == 'div(:index,1).div(:index,3).div(:index,5)'
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|