easy-automation 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 +5 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +26 -0
- data/README.markdown +151 -0
- data/Rakefile +14 -0
- data/easy-automation.gemspec +24 -0
- data/lib/easy-automation.rb +11 -0
- data/lib/easy_automation/config.rb +43 -0
- data/lib/easy_automation/data_elements.rb +41 -0
- data/lib/easy_automation/load_data.rb +31 -0
- data/lib/easy_automation/page.rb +65 -0
- data/lib/easy_automation/runner.rb +47 -0
- data/lib/easy_automation/server.rb +8 -0
- data/lib/easy_automation/suite.rb +15 -0
- data/lib/easy_automation/test.rb +40 -0
- data/lib/easy_automation/version.rb +3 -0
- data/spec/lib/easy-automation/config_spec.rb +24 -0
- data/spec/lib/easy-automation/page_spec.rb +20 -0
- data/spec/lib/easy-automation/runner_spec.rb +64 -0
- data/spec/lib/easy-automation/suite_spec.rb +33 -0
- data/spec/lib/easy-automation/test_spec.rb +37 -0
- data/spec/spec_helper.rb +20 -0
- data/spec/support/browser.rb +3 -0
- data/spec/support/data/hometest.yml +4 -0
- data/spec/support/elements/homepage.yml +4 -0
- data/spec/support/home_page.rb +18 -0
- data/spec/support/home_test.rb +12 -0
- metadata +133 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
easy-automation (0.0.1)
|
5
|
+
Selenium
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
Selenium (1.1.14)
|
11
|
+
diff-lcs (1.1.2)
|
12
|
+
rspec (2.5.0)
|
13
|
+
rspec-core (~> 2.5.0)
|
14
|
+
rspec-expectations (~> 2.5.0)
|
15
|
+
rspec-mocks (~> 2.5.0)
|
16
|
+
rspec-core (2.5.1)
|
17
|
+
rspec-expectations (2.5.0)
|
18
|
+
diff-lcs (~> 1.1.2)
|
19
|
+
rspec-mocks (2.5.0)
|
20
|
+
|
21
|
+
PLATFORMS
|
22
|
+
ruby
|
23
|
+
|
24
|
+
DEPENDENCIES
|
25
|
+
easy-automation!
|
26
|
+
rspec (>= 2.3.0)
|
data/README.markdown
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
Easy Automation
|
2
|
+
===============
|
3
|
+
|
4
|
+
Friendly Automation Testing Framework, tired of update every single test when developers change an XPath, id, class, etc? This is for you.
|
5
|
+
|
6
|
+
Design
|
7
|
+
------
|
8
|
+
|
9
|
+
This framework uses common patterns to make maintainability easy and scalable tests. It's divided in:
|
10
|
+
|
11
|
+
* Pages
|
12
|
+
* Page Elements
|
13
|
+
* Test
|
14
|
+
* Data for Tests
|
15
|
+
* Runner
|
16
|
+
|
17
|
+
Challenges when developing automated tests
|
18
|
+
------
|
19
|
+
|
20
|
+
* FrontEnd is always changing, and it's hard to get tests up to date, any small change, id renamed, nested table, etc, breaks all the tests
|
21
|
+
* Separate components in order to allow easy patching for new changes.
|
22
|
+
* Some tests depend in other
|
23
|
+
* If you need to update data used by test, you touch test code
|
24
|
+
|
25
|
+
Design
|
26
|
+
------
|
27
|
+
|
28
|
+
We will implement kind of MVC pattern for automation testing, separating xpath's information, data for tests and the runner.
|
29
|
+
|
30
|
+
+---------+ +----------------------+
|
31
|
+
| Pages |<------| EasyAutomation::Page |
|
32
|
+
+---------+ +----------------------+
|
33
|
+
| \ +----------+
|
34
|
+
| \| Elements |
|
35
|
+
v +----------+
|
36
|
+
+---------+ +----------+ +-------------+
|
37
|
+
| Suite |<----->| Runner |<----->| Selenium RC |
|
38
|
+
+---------+ +----------+ +-------------+
|
39
|
+
^ +--------+
|
40
|
+
| /| Data |
|
41
|
+
| / +--------+
|
42
|
+
+---------+ +----------------------+
|
43
|
+
| Tests |<------| EasyAutomation::Test |
|
44
|
+
+---------+ +----------------------+
|
45
|
+
|
46
|
+
Instead of work with actions => elements, we can use element => actions
|
47
|
+
Normally:
|
48
|
+
Selenium.click('id:btn')
|
49
|
+
Selenium.enter('id:input_text', 'Text')
|
50
|
+
|
51
|
+
With this framework:
|
52
|
+
page.btn.click
|
53
|
+
page.input_text.enter('Text')
|
54
|
+
|
55
|
+
You have a lot of [actions](http://selenium.rubyforge.org/rdoc/classes/Selenium/WebPage.html) to use with your page elements, click, text, enter, etc.
|
56
|
+
|
57
|
+
More Reference: http://selenium.rubyforge.org/rdoc/classes/Selenium/
|
58
|
+
|
59
|
+
Example
|
60
|
+
-------
|
61
|
+
Structure:
|
62
|
+
|
63
|
+
/runner_demo.rb
|
64
|
+
test/
|
65
|
+
main_page_test.rb
|
66
|
+
data/
|
67
|
+
mainpagetest.yml
|
68
|
+
pages/
|
69
|
+
main_page.rb
|
70
|
+
elements/
|
71
|
+
mainpage.yml
|
72
|
+
|
73
|
+
main_page.rb
|
74
|
+
class MainPage < EasyAutomation::Page
|
75
|
+
def login_field
|
76
|
+
@browser.text_field(:id, @elements.login)
|
77
|
+
end
|
78
|
+
def password_field
|
79
|
+
@browser.text_field(:id, @elements.password)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
mainpage.yml
|
84
|
+
login: xpath=id('login')
|
85
|
+
password: xpath=id('password')
|
86
|
+
|
87
|
+
main_page_test.rb
|
88
|
+
class MainPageTest < EasyAutomation::Test
|
89
|
+
def initialize test_name, path = 'data'
|
90
|
+
super(test_name, path)
|
91
|
+
end
|
92
|
+
|
93
|
+
def login_failed_test
|
94
|
+
main_page = MainPage.new(@browser, 'elements')
|
95
|
+
main_page.login_field.type @data.email
|
96
|
+
main_page.password_field.type @data.password
|
97
|
+
assert_true main_page.include?"wrong email/password combination with: #{@data.email}"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
mainpagetest.yml
|
102
|
+
login_failed_test:
|
103
|
+
email: wrong@email.com
|
104
|
+
password: pasguord
|
105
|
+
|
106
|
+
runner_demo.rb
|
107
|
+
require 'rubygems'
|
108
|
+
require 'easy-automation'
|
109
|
+
Dir["#{File.dirname(__FILE__)}/*/*.rb"].each { |f| require f }
|
110
|
+
|
111
|
+
EasyAutomation::Runner.configure do |config|
|
112
|
+
config.url = "http://www.google.com"
|
113
|
+
config.browser = "*safari"
|
114
|
+
config.before :all do
|
115
|
+
puts 'Starting Tests'
|
116
|
+
end
|
117
|
+
config.after :all do
|
118
|
+
puts 'Tests finished, halting'
|
119
|
+
end
|
120
|
+
end
|
121
|
+
demo_suite = EasyAutomation::Suite.new('Demo')
|
122
|
+
demo_suite.add(MainPageTest)
|
123
|
+
EasyAutomation::Runner.run demo_suite
|
124
|
+
|
125
|
+
Find some working code under examples folder, to see it search exmple on action, execute:
|
126
|
+
cd examples/search
|
127
|
+
bundle exec ruby example.rb
|
128
|
+
|
129
|
+
Roadmap
|
130
|
+
-------
|
131
|
+
* More hooks [before|after] [:all|:each] [:test|:suite]
|
132
|
+
* Wait for element to be loaded event
|
133
|
+
* Rake integration
|
134
|
+
* Retry on failed tests
|
135
|
+
* Parallel tests
|
136
|
+
* Nice test results
|
137
|
+
* Remote Selenium RC/Grid
|
138
|
+
* History graphs
|
139
|
+
* Performance analysis graphs
|
140
|
+
|
141
|
+
Order may matter
|
142
|
+
|
143
|
+
Contributing
|
144
|
+
------------
|
145
|
+
|
146
|
+
1. Fork it.
|
147
|
+
2. Create a branch (`git checkout -b my_branch`)
|
148
|
+
3. Commit your changes (`git commit -am "Fixing your bugs"`)
|
149
|
+
4. Push to the branch (`git push origin my_branch`)
|
150
|
+
5. Create an [Issue][1] with a link to your branch
|
151
|
+
6. Enjoy a refreshing Beer and wait
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'rspec/core'
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
7
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
8
|
+
end
|
9
|
+
|
10
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
11
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
12
|
+
end
|
13
|
+
|
14
|
+
task :default => :spec
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "easy_automation/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "easy-automation"
|
7
|
+
s.version = EasyAutomation::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Edwin Cruz"]
|
10
|
+
s.email = ["edwin@crowdint.com"]
|
11
|
+
s.homepage = "http://rubygems.org/gems/easy-automation"
|
12
|
+
s.summary = %q{Friendly Automation Testing Framework}
|
13
|
+
s.description = %q{Friendly Automation Testing Framework, tired of update every single test when developers change an XPath, id, class, etc? This is for you.}
|
14
|
+
|
15
|
+
s.rubyforge_project = "easy-automation"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n").reject {|item| item.include?('examples/')}
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency('Selenium')
|
23
|
+
s.add_development_dependency("rspec", ">= 2.3.0")
|
24
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'selenium'
|
2
|
+
require 'test/unit/ui/console/testrunner'
|
3
|
+
require 'easy_automation/config'
|
4
|
+
require 'easy_automation/data_elements'
|
5
|
+
require 'easy_automation/load_data'
|
6
|
+
require 'easy_automation/page'
|
7
|
+
require 'easy_automation/runner'
|
8
|
+
require 'easy_automation/server'
|
9
|
+
require 'easy_automation/suite'
|
10
|
+
require 'easy_automation/test'
|
11
|
+
require 'easy_automation/version'
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# Crowd Interactive Copyright 2011
|
2
|
+
|
3
|
+
#
|
4
|
+
# Config class used by Runner.configure it controls selenium behaviour
|
5
|
+
# @author: Edwin Cruz (edwin.cruz@crowdint.com)
|
6
|
+
#
|
7
|
+
module EasyAutomation
|
8
|
+
class Config
|
9
|
+
attr_accessor :selenium_port
|
10
|
+
attr_accessor :selenium_timeout
|
11
|
+
attr_accessor :browser
|
12
|
+
attr_accessor :url
|
13
|
+
attr_reader :hooks
|
14
|
+
|
15
|
+
#
|
16
|
+
# Default settings for selenium RC
|
17
|
+
#
|
18
|
+
def initialize
|
19
|
+
@selenium_port = 4444
|
20
|
+
@selenium_timeout = 1000
|
21
|
+
@browser = "Firefox"
|
22
|
+
@url = "http://www.google.com"
|
23
|
+
@hooks = {:before => {}, :after =>{}}
|
24
|
+
end
|
25
|
+
|
26
|
+
def before hook, &block
|
27
|
+
@hooks[:before].merge!({hook.to_sym => block}) if block_given?
|
28
|
+
end
|
29
|
+
|
30
|
+
def after hook, &block
|
31
|
+
@hooks[:after].merge!({hook.to_sym => block}) if block_given?
|
32
|
+
end
|
33
|
+
|
34
|
+
def execute type, hook_name
|
35
|
+
@hooks[type.to_sym][hook_name.to_sym].call if @hooks[type.to_sym][hook_name.to_sym]
|
36
|
+
end
|
37
|
+
|
38
|
+
def load_files pattern
|
39
|
+
puts '888888888888 ENTRE!!!'
|
40
|
+
Dir[pattern].each { |f| require f }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# Crowd Interactive Copyright 2011
|
2
|
+
|
3
|
+
#
|
4
|
+
# Class to map keys to attributes
|
5
|
+
# @author: Edwin Cruz (edwin.cruz@crowdint.com)
|
6
|
+
#
|
7
|
+
module EasyAutomation
|
8
|
+
class DataElements
|
9
|
+
@elements = {}
|
10
|
+
|
11
|
+
#
|
12
|
+
# Builds magic functions to handle elements
|
13
|
+
# @params hash key => value
|
14
|
+
#
|
15
|
+
def initialize(elements)
|
16
|
+
@elements = elements
|
17
|
+
elements.each do |key, value|
|
18
|
+
if (value.class.to_s == "Array" || value.class.to_s == "Hash")
|
19
|
+
eval (%{
|
20
|
+
def #{key}
|
21
|
+
return @elements[:#{key}]
|
22
|
+
|
23
|
+
end
|
24
|
+
})
|
25
|
+
elsif value.class.to_s == 'Fixnum'
|
26
|
+
eval(%{
|
27
|
+
def #{key}
|
28
|
+
return #{value}
|
29
|
+
end
|
30
|
+
})
|
31
|
+
else
|
32
|
+
eval(%{
|
33
|
+
def #{key}
|
34
|
+
return #{value.dump}
|
35
|
+
end
|
36
|
+
})
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# Crowd Interactive Copyright 2011
|
2
|
+
|
3
|
+
#
|
4
|
+
# Loads Test Data or Elements XPaths
|
5
|
+
# @author Edwin Cruz (edwin@crowdint.com)
|
6
|
+
#
|
7
|
+
module EasyAutomation
|
8
|
+
class LoadData
|
9
|
+
|
10
|
+
#
|
11
|
+
# Loads test data based on test name.
|
12
|
+
# @params name string filename to load data
|
13
|
+
# @params path base path to find '/data/' folder
|
14
|
+
# @returns associative array containing at method level its test data
|
15
|
+
#
|
16
|
+
def self.load_test_data(name, test_name, path)
|
17
|
+
data = YAML::load(File.read(File.join(path, 'data', "#{name}.yml")))
|
18
|
+
DataElements.new(data[test_name])
|
19
|
+
end
|
20
|
+
|
21
|
+
#
|
22
|
+
# Loads xpath elements based on page name.
|
23
|
+
# @params name string filename to load data
|
24
|
+
# @params path base path to find '/elements/' folder
|
25
|
+
# @returns associative array containing element's xpath
|
26
|
+
#
|
27
|
+
def self.load_xpath_elements(name, path)
|
28
|
+
DataElements.new(YAML::load(File.read(File.join(path, 'elements', "#{name.downcase}.yml"))))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
#Crowd Interactive Copyright 2011
|
2
|
+
|
3
|
+
# Common page actions for this framework
|
4
|
+
# @author Edwin Cruz (edwin.cruz@crowdint.com)
|
5
|
+
module EasyAutomation
|
6
|
+
class Page < ::Selenium::WebPage
|
7
|
+
|
8
|
+
attr_reader :elements
|
9
|
+
@elements
|
10
|
+
@browser
|
11
|
+
|
12
|
+
# Default constructor
|
13
|
+
def initialize(browser, path)
|
14
|
+
@elements = LoadData.load_xpath_elements(self.class.to_s, path)
|
15
|
+
super(browser, @elements.title)
|
16
|
+
@browser = browser
|
17
|
+
end
|
18
|
+
|
19
|
+
## Common page actions
|
20
|
+
|
21
|
+
#
|
22
|
+
# Gets body text
|
23
|
+
#
|
24
|
+
def html
|
25
|
+
browser.html()
|
26
|
+
end
|
27
|
+
|
28
|
+
#
|
29
|
+
# Returns page title
|
30
|
+
#
|
31
|
+
def title
|
32
|
+
browser.title
|
33
|
+
end
|
34
|
+
|
35
|
+
#
|
36
|
+
# Waits for page to load
|
37
|
+
#
|
38
|
+
def wait_page_load
|
39
|
+
browser.wait_for_load
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# it goes back one place in history
|
44
|
+
#
|
45
|
+
def go_back
|
46
|
+
browser.browser.go_back()
|
47
|
+
self.wait_page_load
|
48
|
+
end
|
49
|
+
|
50
|
+
#
|
51
|
+
# Refresh current page and waits to be loaded
|
52
|
+
#
|
53
|
+
def refresh
|
54
|
+
browser.browser.refresh
|
55
|
+
self.wait_page_load
|
56
|
+
end
|
57
|
+
|
58
|
+
#
|
59
|
+
# Returns all elements for current page
|
60
|
+
#
|
61
|
+
def elements
|
62
|
+
@elements
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# Crowd Interactive Copyright 2011
|
2
|
+
|
3
|
+
#
|
4
|
+
# Framework Runner
|
5
|
+
# EasyAutomation::Runner.configure do |config|
|
6
|
+
# config.selenium_port = 44444
|
7
|
+
# config.selenium_timeout = 1000
|
8
|
+
# config.browser = "firefox"
|
9
|
+
# config.url = "http://my_site:80"
|
10
|
+
# end
|
11
|
+
#
|
12
|
+
# my_suite = EasyAutomation::Suite.new
|
13
|
+
# my_suite.add(MyTest)
|
14
|
+
# EasyAutomation::Runner.run(my_suite)
|
15
|
+
#
|
16
|
+
# @author: Edwin Cruz (edwin.cruz@crowdint.com)
|
17
|
+
#
|
18
|
+
module EasyAutomation
|
19
|
+
class RunnerSuiteException < Exception; end
|
20
|
+
class Runner
|
21
|
+
class << self
|
22
|
+
def configuration
|
23
|
+
unless @configuration
|
24
|
+
@configuration = Config.new
|
25
|
+
end
|
26
|
+
@configuration
|
27
|
+
end
|
28
|
+
|
29
|
+
def server
|
30
|
+
@selenium_server ||= Server.new
|
31
|
+
end
|
32
|
+
|
33
|
+
def configure
|
34
|
+
yield configuration
|
35
|
+
end
|
36
|
+
|
37
|
+
def run test_suite
|
38
|
+
raise RunnerSuiteException.new('Wrong test suite class') unless test_suite.is_a?(Suite)
|
39
|
+
Server.rc.start
|
40
|
+
configuration.execute :before, :all
|
41
|
+
::Test::Unit::UI::Console::TestRunner.run test_suite
|
42
|
+
configuration.execute :after, :all
|
43
|
+
Server.rc.stop
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module EasyAutomation
|
2
|
+
class SuiteException < Exception; end
|
3
|
+
class Suite
|
4
|
+
attr_reader :suite
|
5
|
+
|
6
|
+
def initialize name = "Test Suite"
|
7
|
+
@suite = ::Test::Unit::TestSuite.new(name)
|
8
|
+
end
|
9
|
+
|
10
|
+
def add test_name
|
11
|
+
raise SuiteException.new('Wrong test class, please extend it from EasyAutomation::Test') unless test_name < EasyAutomation::Test
|
12
|
+
@suite << test_name.suite
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# Crowd Interactive Copyright 2011
|
2
|
+
|
3
|
+
#
|
4
|
+
# Base Test Class for Easy Automation Testing Framework
|
5
|
+
# Extend your test case from this class to get everything needed
|
6
|
+
# @author: Edwin Cruz (edwin.cruz@crowdint.com)
|
7
|
+
#
|
8
|
+
require 'test/unit'
|
9
|
+
module EasyAutomation
|
10
|
+
class Test < Test::Unit::TestCase
|
11
|
+
|
12
|
+
attr_accessor :data
|
13
|
+
@path = nil
|
14
|
+
|
15
|
+
#TODO figure out why we need to pass the path from a child class
|
16
|
+
def initialize(test_methodname, path = ".")
|
17
|
+
@path = path
|
18
|
+
super(test_methodname)
|
19
|
+
end
|
20
|
+
|
21
|
+
@data = {}
|
22
|
+
|
23
|
+
#
|
24
|
+
# Sets up the environment to run tests, decides whether build a new selenium client
|
25
|
+
# or use a global one.
|
26
|
+
#
|
27
|
+
def setup
|
28
|
+
@webpage = Server.rc.open(Runner.configuration.browser,
|
29
|
+
Runner.configuration.url)
|
30
|
+
@data = LoadData::load_test_data(self.class.to_s, @method_name, @path)
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# Executed after all tests, normally to stop selenium client.
|
35
|
+
#
|
36
|
+
def teardown
|
37
|
+
@webpage.close
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
|
4
|
+
describe EasyAutomation::Config do
|
5
|
+
subject {Config}
|
6
|
+
|
7
|
+
context "before hooks" do
|
8
|
+
context "when specifying any hook" do
|
9
|
+
before :each do
|
10
|
+
@config = EasyAutomation::Config.new
|
11
|
+
@config.before(:each) do
|
12
|
+
TestBlockClass.return_the_true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
it "should save it" do
|
16
|
+
@config.hooks[:before][:each].should be_is_a(Proc)
|
17
|
+
end
|
18
|
+
it "should execute it when called" do
|
19
|
+
TestBlockClass.should_receive(:return_the_true)
|
20
|
+
@config.execute(:before, :each)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
|
4
|
+
describe EasyAutomation::Page do
|
5
|
+
|
6
|
+
subject {Page}
|
7
|
+
|
8
|
+
context "#Loading elements info" do
|
9
|
+
before :each do
|
10
|
+
@browser = Browser.new
|
11
|
+
end
|
12
|
+
it "should load elements/filename.yml" do
|
13
|
+
home_page = HomePage.new(@browser)
|
14
|
+
home_page.elements.login_link.should == "Log In"
|
15
|
+
home_page.elements.query_field.should == "q"
|
16
|
+
home_page.elements.submit.should == "xpath=id('submit')"
|
17
|
+
home_page.elements.title.should == "Home Page"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe EasyAutomation::Runner do
|
4
|
+
|
5
|
+
subject { Runner }
|
6
|
+
|
7
|
+
context "when configuring runner" do
|
8
|
+
context "selenium params" do
|
9
|
+
it "should default params" do
|
10
|
+
EasyAutomation::Runner.configuration.selenium_port.should be(4444)
|
11
|
+
EasyAutomation::Runner.configuration.selenium_timeout.should be(1000)
|
12
|
+
EasyAutomation::Runner.configuration.browser.should == "Firefox"
|
13
|
+
EasyAutomation::Runner.configuration.url.should == "http://www.google.com"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should set correct params" do
|
17
|
+
EasyAutomation::Runner.configure do |config|
|
18
|
+
config.selenium_port = 44444
|
19
|
+
config.selenium_timeout = 40000
|
20
|
+
config.browser = "Chrome"
|
21
|
+
config.url = "http://www.yahoo.com"
|
22
|
+
end
|
23
|
+
EasyAutomation::Runner.configuration.selenium_port.should be(44444)
|
24
|
+
EasyAutomation::Runner.configuration.selenium_timeout.should be(40000)
|
25
|
+
EasyAutomation::Runner.configuration.browser.should == "Chrome"
|
26
|
+
EasyAutomation::Runner.configuration.url.should == "http://www.yahoo.com"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "when running tests" do
|
32
|
+
before :each do
|
33
|
+
@rc = mock(EasyAutomation::Server)
|
34
|
+
EasyAutomation::Server.stub(:rc).and_return(@rc)
|
35
|
+
Test::Unit::UI::Console::TestRunner.stub(:run).and_return(true)
|
36
|
+
@rc.should_receive(:start)
|
37
|
+
@rc.should_receive(:stop)
|
38
|
+
end
|
39
|
+
it "should accept EasyAutomation::Suite classes" do
|
40
|
+
suite = EasyAutomation::Suite.new
|
41
|
+
lambda { EasyAutomation::Runner.run suite }.should_not raise_error(EasyAutomation::RunnerSuiteException)
|
42
|
+
end
|
43
|
+
context "before and after all hooks" do
|
44
|
+
it "should call before all hook when running suites" do
|
45
|
+
TestBlockClass.should_receive(:return_the_true)
|
46
|
+
EasyAutomation::Runner.configure do |config|
|
47
|
+
config.before :all do
|
48
|
+
TestBlockClass.return_the_true
|
49
|
+
end
|
50
|
+
end
|
51
|
+
EasyAutomation::Runner.run EasyAutomation::Suite.new('test')
|
52
|
+
end
|
53
|
+
it "should call after all hook when running suites" do
|
54
|
+
TestBlockClass.should_receive(:return_the_true).at_least(2).times()
|
55
|
+
EasyAutomation::Runner.configure do |config|
|
56
|
+
config.after :all do
|
57
|
+
TestBlockClass.return_the_true
|
58
|
+
end
|
59
|
+
end
|
60
|
+
EasyAutomation::Runner.run EasyAutomation::Suite.new('test')
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
|
4
|
+
describe EasyAutomation::Suite do
|
5
|
+
|
6
|
+
subject { Suite }
|
7
|
+
|
8
|
+
context "When adding new test suites to the main" do
|
9
|
+
it "should raise an error if they dont extend from EasyAutomation::Test" do
|
10
|
+
class WrongTest
|
11
|
+
def suite
|
12
|
+
true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
my_suite = EasyAutomation::Suite.new
|
16
|
+
lambda{my_suite.add(WrongTest)}.should raise_error(EasyAutomation::SuiteException)
|
17
|
+
end
|
18
|
+
it "should accept suites if they extend from EasyAutomation::Test" do
|
19
|
+
class TestClass < EasyAutomation::Test
|
20
|
+
def suite
|
21
|
+
true
|
22
|
+
end
|
23
|
+
def method_name
|
24
|
+
true
|
25
|
+
end
|
26
|
+
end
|
27
|
+
my_suite = EasyAutomation::Suite.new
|
28
|
+
my_suite.add(TestClass)
|
29
|
+
my_suite.suite.size.should be(1)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
|
4
|
+
describe EasyAutomation::Test do
|
5
|
+
|
6
|
+
subject { Test }
|
7
|
+
|
8
|
+
before :each do
|
9
|
+
fake_server = mock(Selenium::Server)
|
10
|
+
fake_driver = mock(Selenium::SeleniumDriver)
|
11
|
+
fake_server.stub(:open).and_return(fake_driver)
|
12
|
+
fake_driver.stub(:close).and_return(true)
|
13
|
+
Selenium::Server.stub!(:new).and_return(fake_server)
|
14
|
+
EasyAutomation::Server.stub(:rc).and_return(fake_server)
|
15
|
+
end
|
16
|
+
|
17
|
+
context "#Loading data info" do
|
18
|
+
it "should load data/filename.yml with @current_test one" do
|
19
|
+
home_test = HomeTest.new('one')
|
20
|
+
home_test.setup
|
21
|
+
home_test.data.title.should == 'First block'
|
22
|
+
end
|
23
|
+
it "should load data/filename.yml with @current_test two" do
|
24
|
+
home_test = HomeTest.new('one')
|
25
|
+
home_test.setup
|
26
|
+
home_test.data.title.should == 'First block'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "when opening web pages" do
|
31
|
+
it "should initialize it's selenium rc if it's not been initalized" do
|
32
|
+
test_spec = HomeTest.new('one')
|
33
|
+
test_spec.setup
|
34
|
+
test_spec.teardown
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
|
4
|
+
require File.join(File.dirname(__FILE__), '..', 'lib/easy-automation')
|
5
|
+
|
6
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
7
|
+
|
8
|
+
begin
|
9
|
+
Bundler.setup(:default, :development)
|
10
|
+
rescue Bundler::BundlerError => e
|
11
|
+
$stderr.puts e.message
|
12
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
13
|
+
exit e.status_code
|
14
|
+
end
|
15
|
+
|
16
|
+
class TestBlockClass
|
17
|
+
def self.return_the_true
|
18
|
+
true
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class HomePage < EasyAutomation::Page
|
2
|
+
|
3
|
+
def initialize(browser, extra = nil)
|
4
|
+
super(browser, File.expand_path(File.dirname(__FILE__)))
|
5
|
+
end
|
6
|
+
|
7
|
+
def login_link
|
8
|
+
browser.link(:text, @elements.login_link)
|
9
|
+
end
|
10
|
+
|
11
|
+
def query_field
|
12
|
+
browser.text_field(:id, @elements.query_field)
|
13
|
+
end
|
14
|
+
|
15
|
+
def submit_query
|
16
|
+
browser.button(:xpath, @elements.submit)
|
17
|
+
end
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: easy-automation
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Edwin Cruz
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-03-14 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: Selenium
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rspec
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 2
|
46
|
+
- 3
|
47
|
+
- 0
|
48
|
+
version: 2.3.0
|
49
|
+
type: :development
|
50
|
+
version_requirements: *id002
|
51
|
+
description: Friendly Automation Testing Framework, tired of update every single test when developers change an XPath, id, class, etc? This is for you.
|
52
|
+
email:
|
53
|
+
- edwin@crowdint.com
|
54
|
+
executables: []
|
55
|
+
|
56
|
+
extensions: []
|
57
|
+
|
58
|
+
extra_rdoc_files: []
|
59
|
+
|
60
|
+
files:
|
61
|
+
- .gitignore
|
62
|
+
- Gemfile
|
63
|
+
- Gemfile.lock
|
64
|
+
- README.markdown
|
65
|
+
- Rakefile
|
66
|
+
- easy-automation.gemspec
|
67
|
+
- lib/easy-automation.rb
|
68
|
+
- lib/easy_automation/config.rb
|
69
|
+
- lib/easy_automation/data_elements.rb
|
70
|
+
- lib/easy_automation/load_data.rb
|
71
|
+
- lib/easy_automation/page.rb
|
72
|
+
- lib/easy_automation/runner.rb
|
73
|
+
- lib/easy_automation/server.rb
|
74
|
+
- lib/easy_automation/suite.rb
|
75
|
+
- lib/easy_automation/test.rb
|
76
|
+
- lib/easy_automation/version.rb
|
77
|
+
- spec/lib/easy-automation/config_spec.rb
|
78
|
+
- spec/lib/easy-automation/page_spec.rb
|
79
|
+
- spec/lib/easy-automation/runner_spec.rb
|
80
|
+
- spec/lib/easy-automation/suite_spec.rb
|
81
|
+
- spec/lib/easy-automation/test_spec.rb
|
82
|
+
- spec/spec_helper.rb
|
83
|
+
- spec/support/browser.rb
|
84
|
+
- spec/support/data/hometest.yml
|
85
|
+
- spec/support/elements/homepage.yml
|
86
|
+
- spec/support/home_page.rb
|
87
|
+
- spec/support/home_test.rb
|
88
|
+
has_rdoc: true
|
89
|
+
homepage: http://rubygems.org/gems/easy-automation
|
90
|
+
licenses: []
|
91
|
+
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
hash: 3
|
103
|
+
segments:
|
104
|
+
- 0
|
105
|
+
version: "0"
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
hash: 3
|
112
|
+
segments:
|
113
|
+
- 0
|
114
|
+
version: "0"
|
115
|
+
requirements: []
|
116
|
+
|
117
|
+
rubyforge_project: easy-automation
|
118
|
+
rubygems_version: 1.5.3
|
119
|
+
signing_key:
|
120
|
+
specification_version: 3
|
121
|
+
summary: Friendly Automation Testing Framework
|
122
|
+
test_files:
|
123
|
+
- spec/lib/easy-automation/config_spec.rb
|
124
|
+
- spec/lib/easy-automation/page_spec.rb
|
125
|
+
- spec/lib/easy-automation/runner_spec.rb
|
126
|
+
- spec/lib/easy-automation/suite_spec.rb
|
127
|
+
- spec/lib/easy-automation/test_spec.rb
|
128
|
+
- spec/spec_helper.rb
|
129
|
+
- spec/support/browser.rb
|
130
|
+
- spec/support/data/hometest.yml
|
131
|
+
- spec/support/elements/homepage.yml
|
132
|
+
- spec/support/home_page.rb
|
133
|
+
- spec/support/home_test.rb
|