howitzer 0.0.3 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/.rspec +3 -0
- data/.travis.yml +4 -0
- data/CHANGELOG.md +32 -0
- data/GETTING_STARTED.md +529 -0
- data/Gemfile +4 -2
- data/LICENSE +2 -2
- data/README.md +57 -13
- data/Rakefile +9 -2
- data/bin/howitzer +79 -31
- data/generators/base_generator.rb +87 -0
- data/generators/config/config_generator.rb +16 -20
- data/generators/config/templates/default.yml +26 -7
- data/generators/cucumber/cucumber_generator.rb +20 -26
- data/generators/{tasks → cucumber}/templates/cucumber.rake +0 -0
- data/generators/{config → cucumber}/templates/cucumber.yml +0 -0
- data/generators/emails/emails_generator.rb +11 -18
- data/generators/emails/templates/example_email.rb +1 -0
- data/generators/pages/pages_generator.rb +16 -18
- data/generators/pages/templates/example_menu.rb +1 -0
- data/generators/pages/templates/example_page.rb +1 -1
- data/generators/root/root_generator.rb +18 -20
- data/generators/root/templates/.gitignore +2 -1
- data/generators/root/templates/Gemfile +3 -2
- data/generators/root/templates/Rakefile +10 -0
- data/generators/root/templates/boot.rb +3 -9
- data/generators/rspec/rspec_generator.rb +23 -0
- data/generators/rspec/templates/example_spec.rb +7 -0
- data/generators/rspec/templates/rspec.rake +34 -0
- data/generators/rspec/templates/spec_helper.rb +56 -0
- data/generators/tasks/tasks_generator.rb +11 -17
- data/generators/tasks/templates/common.rake +15 -0
- data/howitzer.gemspec +13 -2
- data/lib/howitzer.rb +1 -0
- data/lib/howitzer/helpers.rb +87 -2
- data/lib/howitzer/init.rb +0 -1
- data/lib/howitzer/patches/rawler_patched.rb +86 -0
- data/lib/howitzer/settings.rb +27 -0
- data/lib/howitzer/utils.rb +3 -12
- data/lib/howitzer/utils/capybara_patched.rb +3 -2
- data/lib/howitzer/utils/capybara_settings.rb +158 -24
- data/lib/howitzer/utils/data_generator/data_storage.rb +35 -1
- data/lib/howitzer/utils/data_generator/gen.rb +45 -3
- data/lib/howitzer/utils/email/email.rb +44 -5
- data/lib/howitzer/utils/email/mail_client.rb +28 -22
- data/lib/howitzer/utils/email/mailgun_helper.rb +30 -4
- data/lib/howitzer/utils/locator_store.rb +111 -19
- data/lib/howitzer/utils/log.rb +137 -0
- data/lib/howitzer/utils/page_validator.rb +86 -0
- data/lib/howitzer/vendor/firebug-1.12.1-fx.xpi +0 -0
- data/lib/howitzer/vendor/firepath-0.9.7-fx.xpi +0 -0
- data/lib/howitzer/version.rb +2 -2
- data/lib/howitzer/web_page.rb +159 -19
- data/spec/active_resource.rb +0 -0
- data/spec/config/custom.yml +1 -0
- data/spec/config/default.yml +28 -0
- data/spec/spec_helper.rb +46 -1
- data/spec/support/boot_helper.rb +15 -0
- data/spec/support/generator_helper.rb +13 -0
- data/spec/support/logger_helper.rb +12 -0
- data/spec/unit/bin/howitzer_spec.rb +175 -0
- data/spec/unit/generators/generators_spec.rb +175 -0
- data/spec/unit/lib/capybara_settings_spec.rb +170 -0
- data/spec/unit/lib/helpers_spec.rb +619 -0
- data/spec/unit/lib/init_spec.rb +14 -0
- data/spec/unit/lib/settings_spec.rb +17 -0
- data/spec/unit/lib/utils/data_generator/data_storage_spec.rb +62 -0
- data/spec/unit/lib/utils/data_generator/gen_spec.rb +151 -0
- data/spec/unit/lib/utils/email/email_spec.rb +75 -0
- data/spec/unit/lib/utils/email/mail_client_spec.rb +115 -0
- data/spec/unit/lib/utils/email/mailgun_helper_spec.rb +95 -0
- data/spec/unit/lib/utils/locator_store_spec.rb +122 -0
- data/spec/unit/lib/utils/log_spec.rb +107 -0
- data/spec/unit/lib/utils/page_validator_spec.rb +142 -0
- data/spec/unit/lib/web_page_spec.rb +250 -0
- data/spec/unit/version_spec.rb +8 -0
- metadata +215 -15
- data/Gemfile.lock +0 -103
- data/History.md +0 -20
- data/lib/howitzer/utils/logger.rb +0 -108
- data/spec/howitzer/version_spec.rb +0 -8
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require "#{lib_path}/howitzer/utils/locator_store"
|
3
|
+
|
4
|
+
describe "Locator store" do
|
5
|
+
let(:bad_name) { 'name' }
|
6
|
+
let(:error) { LocatorStore::LocatorNotDefinedError }
|
7
|
+
|
8
|
+
shared_examples "locator methods" do |prefix, web_page|
|
9
|
+
describe "#{prefix}locator" do
|
10
|
+
context "when bad locator given" do
|
11
|
+
subject { web_page.locator(bad_name) }
|
12
|
+
it { expect {subject}.to raise_error(error) }
|
13
|
+
end
|
14
|
+
context "when CSS locator given" do
|
15
|
+
before { web_page.add_locator :base_locator, 'base_locator' }
|
16
|
+
subject { web_page.locator(:base_locator) }
|
17
|
+
it { expect(subject).to eq('base_locator') }
|
18
|
+
end
|
19
|
+
context "when XPATH locator given" do
|
20
|
+
before { web_page.add_locator :test_xpath, xpath: "//select[@id='modelOptions']/option[@value='m6']" }
|
21
|
+
subject { web_page.locator(:test_xpath) }
|
22
|
+
it { expect(subject).to eq([:xpath, "//select[@id='modelOptions']/option[@value='m6']"]) }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#{prefix}link_locator" do
|
27
|
+
context "when bad locator given" do
|
28
|
+
subject { web_page.link_locator(bad_name) }
|
29
|
+
it { expect {subject}. to raise_error(error) }
|
30
|
+
end
|
31
|
+
context "when correct locator given" do
|
32
|
+
before { web_page.add_link_locator :link_locator, 'link_locator' }
|
33
|
+
subject { web_page.link_locator(:link_locator) }
|
34
|
+
it { expect(subject).to eq('link_locator') }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#{prefix}field_locator" do
|
39
|
+
context "when bad locator given" do
|
40
|
+
subject { web_page.field_locator(bad_name) }
|
41
|
+
it { expect {subject}. to raise_error(error) }
|
42
|
+
end
|
43
|
+
context "when correct locator given" do
|
44
|
+
before { web_page.add_field_locator :field_locator, 'field_locator' }
|
45
|
+
subject { web_page.field_locator(:field_locator) }
|
46
|
+
it { expect(subject).to eq('field_locator') }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#{prefix}button_locator" do
|
51
|
+
context "when bad locator given" do
|
52
|
+
subject { web_page.button_locator(bad_name) }
|
53
|
+
it { expect {subject}. to raise_error(error) }
|
54
|
+
end
|
55
|
+
context "when correct locator given" do
|
56
|
+
before { web_page.add_button_locator :button_locator, 'button_locator' }
|
57
|
+
subject { web_page.button_locator(:button_locator) }
|
58
|
+
it { expect(subject).to eq('button_locator') }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "#{prefix}find_element" do
|
63
|
+
context "when existing locator name given" do
|
64
|
+
context "of base type" do
|
65
|
+
before { web_page.add_locator :test_locator, '.foo' }
|
66
|
+
subject { web_page.find_element(name) }
|
67
|
+
context "as string" do
|
68
|
+
let(:name) { "test_locator" }
|
69
|
+
it do
|
70
|
+
expect(web_page.is_a?(Class) ? web_page : web_page.class).to receive(:find).with('.foo')
|
71
|
+
subject
|
72
|
+
end
|
73
|
+
end
|
74
|
+
context "as symbol" do
|
75
|
+
let(:name) { :test_locator }
|
76
|
+
it do
|
77
|
+
expect(web_page.is_a?(Class) ? web_page : web_page.class).to receive(:find).with('.foo')
|
78
|
+
subject
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
context "when link locator or other" do
|
83
|
+
before { web_page.add_link_locator :test_link_locator, 'foo' }
|
84
|
+
subject { web_page.find_element(:test_link_locator) }
|
85
|
+
it do
|
86
|
+
expect(web_page.is_a?(Class) ? web_page : web_page.class).to receive(:find_link).with('foo')
|
87
|
+
subject
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
context "when not existing locator name" do
|
92
|
+
subject { web_page.find_element(:unknown_locator) }
|
93
|
+
it { expect{ subject }.to raise_error(LocatorStore::LocatorNotDefinedError, "unknown_locator") }
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "#{prefix}apply" do
|
98
|
+
context "when bad locator given" do
|
99
|
+
before { web_page.add_locator :test_locator, lambda{|test| test} }
|
100
|
+
let(:locator) { lambda{|test| test} }
|
101
|
+
subject { web_page.apply(locator, 'test') }
|
102
|
+
it { expect {subject}.to raise_error(NoMethodError) }
|
103
|
+
|
104
|
+
end
|
105
|
+
context "when correct locator given" do
|
106
|
+
before { web_page.add_locator :test_locator, lambda{|location_name| {xpath: ".//a[contains(.,'#{location_name}')]"}} }
|
107
|
+
let(:locator) { lambda{|location_name| {xpath: ".//a[contains(.,'#{location_name}')]"}} }
|
108
|
+
subject { web_page.apply(locator, 'Kiev') }
|
109
|
+
it { expect(subject).to eq([:xpath, ".//a[contains(.,'Kiev')]"]) }
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
context "Class methods" do
|
115
|
+
it_behaves_like "locator methods", '.', Class.new{ include LocatorStore }
|
116
|
+
end
|
117
|
+
|
118
|
+
context "Instance methods" do
|
119
|
+
it_behaves_like "locator methods", '#', Class.new{ include LocatorStore }.new
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require "#{lib_path}/howitzer/utils/log"
|
3
|
+
include LoggerHelper
|
4
|
+
|
5
|
+
describe "Logger" do
|
6
|
+
let(:path) { File.join(log_path,'log.txt') }
|
7
|
+
context "#log" do
|
8
|
+
subject { log }
|
9
|
+
let(:other_log) { Howitzer::Log.instance }
|
10
|
+
it { expect(subject).to be_a_kind_of(Howitzer::Log) }
|
11
|
+
it { expect(subject).to equal(other_log) }
|
12
|
+
end
|
13
|
+
|
14
|
+
context ".print_feature_name" do
|
15
|
+
let(:feature) { 'Some feature' }
|
16
|
+
let(:expected_result) { "*** Feature: SOME FEATURE ***\n"}
|
17
|
+
subject { read_file(path) }
|
18
|
+
before { log.print_feature_name(feature) }
|
19
|
+
after { clear_file(path) }
|
20
|
+
it { expect(subject).to include(expected_result) }
|
21
|
+
end
|
22
|
+
|
23
|
+
context ".settings_as_formatted_text" do
|
24
|
+
let(:formatted_text) { Faker::Lorem.sentence }
|
25
|
+
let(:as_formatted_text) { double() }
|
26
|
+
let(:expected_result) { formatted_text }
|
27
|
+
subject { read_file(path) }
|
28
|
+
before do
|
29
|
+
expect(settings).to receive(:as_formatted_text).and_return(formatted_text)
|
30
|
+
log.settings_as_formatted_text
|
31
|
+
end
|
32
|
+
after { clear_file(path) }
|
33
|
+
it { expect(subject).to include(expected_result) }
|
34
|
+
end
|
35
|
+
|
36
|
+
context ".print_scenario_name" do
|
37
|
+
let(:expected_result) { " => Scenario: Some scenario\n" }
|
38
|
+
let(:scenario) { 'Some scenario' }
|
39
|
+
subject { read_file(path) }
|
40
|
+
before { log.print_scenario_name(scenario) }
|
41
|
+
after { clear_file(path) }
|
42
|
+
it { expect(subject).to include(expected_result) }
|
43
|
+
end
|
44
|
+
|
45
|
+
context ".error" do
|
46
|
+
context "when one argument given" do
|
47
|
+
subject { log.error(*args) }
|
48
|
+
context "when exception given as argument" do
|
49
|
+
let(:args) { [StandardError.new("Exception_error_message")] }
|
50
|
+
it { expect {subject}.to raise_error(StandardError, "Exception_error_message") }
|
51
|
+
end
|
52
|
+
context "when message given as argument" do
|
53
|
+
let(:args) { ["Runtime_error_message"] }
|
54
|
+
it { expect {subject}.to raise_error(RuntimeError, "Runtime_error_message") }
|
55
|
+
end
|
56
|
+
context "when error object given as arg " do
|
57
|
+
let(:error_object) { ErrorObject = StandardError.new }
|
58
|
+
let(:args) { error_object }
|
59
|
+
it { expect {subject}.to raise_error(StandardError) }
|
60
|
+
it { expect(read_file(path)).to include("[ERROR] [StandardError] StandardError") }
|
61
|
+
end
|
62
|
+
context "when number given as arg" do
|
63
|
+
let(:args) { 123 }
|
64
|
+
it { expect {subject}.to raise_error(RuntimeError) }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
context "when two arguments given" do
|
68
|
+
subject { log.error(*args) }
|
69
|
+
context "when given text as first arg and caller as second" do
|
70
|
+
let(:args) { ["Some_text","two_args_caller"] }
|
71
|
+
it { expect {subject}.to raise_error(RuntimeError) }
|
72
|
+
it { expect(read_file(path)).to include("[ERROR] [RuntimeError] Some_text") }
|
73
|
+
it { expect(read_file(path)).to include("two_args_caller") }
|
74
|
+
end
|
75
|
+
context "when given class inherited from Exception as first arg and message as second" do
|
76
|
+
let(:error_class) {SomeError = Class.new(Exception) }
|
77
|
+
let(:args) { [error_class,"some text"] }
|
78
|
+
it { expect { subject }.to raise_error(error_class,"some text") }
|
79
|
+
it { expect(read_file(path)).to include("[ERROR] [SomeError] some text") }
|
80
|
+
end
|
81
|
+
context "when given some class as first arg and (message) as second" do
|
82
|
+
let(:some_class) { SomeClass = Class.new() }
|
83
|
+
let(:args) { [some_class, "some text" ] }
|
84
|
+
it { expect{subject}.to raise_error(RuntimeError) }
|
85
|
+
it { expect(read_file(path)).to include("[ERROR] [RuntimeError] SomeClass\n\tsome text") }
|
86
|
+
end
|
87
|
+
context "when number given as first arg and message as second" do
|
88
|
+
let(:args) { [123, 'some text' ] }
|
89
|
+
it { expect{subject}.to raise_error(RuntimeError) }
|
90
|
+
it { expect(read_file(path)).to include("[ERROR] [RuntimeError] 123\n\tsome text") }
|
91
|
+
end
|
92
|
+
context "when nubmers given as args" do
|
93
|
+
let(:args) { [123,123] }
|
94
|
+
it { expect{subject}.to raise_error(TypeError) }
|
95
|
+
end
|
96
|
+
end
|
97
|
+
context "when three arguments given" do
|
98
|
+
subject { log.error(*args) }
|
99
|
+
context "when NameError given as first arg, message as second and caller as third" do
|
100
|
+
let(:args) { [NameError, "Name_error_text","three_args_caller"] }
|
101
|
+
it { expect {subject}.to raise_error(NameError) }
|
102
|
+
it { expect(read_file(path)).to include("[ERROR] [NameError] Name_error_text") }
|
103
|
+
it { expect(read_file(path)).to include("three_args_caller") }
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require "#{lib_path}/howitzer/utils/page_validator"
|
3
|
+
|
4
|
+
describe Howitzer::Utils::PageValidator do
|
5
|
+
describe ".validations" do
|
6
|
+
it { expect(subject.validations).to eql({}) }
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "PageValidator" do
|
11
|
+
let(:web_page) { Class.new { include Howitzer::Utils::PageValidator }.new }
|
12
|
+
describe "#check_correct_page_loaded" do
|
13
|
+
subject { web_page.check_correct_page_loaded }
|
14
|
+
context "when no validation specified" do
|
15
|
+
it { expect{subject}.to raise_error(Howitzer::Utils::PageValidator::NoValidationError, "No any page validation was found") }
|
16
|
+
end
|
17
|
+
context "when all validation are specified" do
|
18
|
+
before do
|
19
|
+
web_page.class.validates :title, pattern: /Foo/
|
20
|
+
web_page.class.validates :url, pattern: /Foo/
|
21
|
+
web_page.class.validates :element_presence, locator: :test_locator
|
22
|
+
end
|
23
|
+
it do
|
24
|
+
expect(web_page).to receive(:wait_for_url).with(/Foo/).once
|
25
|
+
expect(web_page).to receive(:wait_for_title).with(/Foo/).once
|
26
|
+
expect(web_page).to receive(:find_element).with(:test_locator)
|
27
|
+
subject
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe ".validates" do
|
33
|
+
subject { web_page.class.validates(name, options)}
|
34
|
+
context "when name = :url" do
|
35
|
+
context "as string" do
|
36
|
+
let(:name) { "url" }
|
37
|
+
context "when options is correct" do
|
38
|
+
context "(as string)" do
|
39
|
+
let(:options) { {"pattern" => /foo/} }
|
40
|
+
it do
|
41
|
+
expect(subject).to be_a(Proc)
|
42
|
+
expect(Howitzer::Utils::PageValidator.validations[web_page.class.name][:url]).to eql(subject)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
context "(as symbol)" do
|
46
|
+
let(:options) { {pattern: /foo/} }
|
47
|
+
it do
|
48
|
+
expect(subject).to be_a(Proc)
|
49
|
+
expect(Howitzer::Utils::PageValidator.validations[web_page.class.name][:url]).to eql(subject)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
context "when options is incorrect" do
|
54
|
+
context "(missing pattern)" do
|
55
|
+
let(:options) { {} }
|
56
|
+
it { expect{subject}.to raise_error(Howitzer::Utils::PageValidator::WrongOptionError, "Please specify ':pattern' option as Regexp object") }
|
57
|
+
end
|
58
|
+
context "(string pattern)" do
|
59
|
+
let(:options) { {pattern: "foo"} }
|
60
|
+
it { expect{subject}.to raise_error(Howitzer::Utils::PageValidator::WrongOptionError, "Please specify ':pattern' option as Regexp object") }
|
61
|
+
end
|
62
|
+
context "(not hash)" do
|
63
|
+
let(:options) { "foo" }
|
64
|
+
it { expect{subject}.to raise_error(TypeError, "Expected options to be Hash, actual is 'String'") }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
context "as symbol" do
|
69
|
+
let(:name) { :url }
|
70
|
+
let(:options) { {pattern: /foo/} }
|
71
|
+
it do
|
72
|
+
expect(subject).to be_a(Proc)
|
73
|
+
expect(Howitzer::Utils::PageValidator.validations[web_page.class.name][:url]).to eql(subject)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
context "when name = :element_presence" do
|
78
|
+
let(:name) { :element_presence }
|
79
|
+
context "when options is correct" do
|
80
|
+
context "(as string)" do
|
81
|
+
let(:options) { {"locator" => 'test_locator'} }
|
82
|
+
it do
|
83
|
+
expect(subject).to be_a(Proc)
|
84
|
+
expect(Howitzer::Utils::PageValidator.validations[web_page.class.name][:element_presence]).to eql(subject)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
context "(as symbol)" do
|
88
|
+
let(:options) { {locator: :test_locator} }
|
89
|
+
it do
|
90
|
+
expect(subject).to be_a(Proc)
|
91
|
+
expect(Howitzer::Utils::PageValidator.validations[web_page.class.name][:element_presence]).to eql(subject)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
context "when options is incorrect" do
|
96
|
+
context "(missing locator)" do
|
97
|
+
let(:options) { {} }
|
98
|
+
it { expect{subject}.to raise_error(Howitzer::Utils::PageValidator::WrongOptionError, "Please specify ':locator' option as one of page locator names") }
|
99
|
+
end
|
100
|
+
context "(blank locator name)" do
|
101
|
+
let(:options) { {locator: ""} }
|
102
|
+
it { expect{subject}.to raise_error(Howitzer::Utils::PageValidator::WrongOptionError, "Please specify ':locator' option as one of page locator names") }
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
context "when name = :title" do
|
107
|
+
let(:name) { :title }
|
108
|
+
context "when options is correct" do
|
109
|
+
context "(as string)" do
|
110
|
+
let(:options) { {"pattern" => /foo/} }
|
111
|
+
it do
|
112
|
+
expect(subject).to be_a(Proc)
|
113
|
+
expect(Howitzer::Utils::PageValidator.validations[web_page.class.name][:title]).to eql(subject)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
context "(as symbol)" do
|
117
|
+
let(:options) { {pattern: /foo/} }
|
118
|
+
it do
|
119
|
+
expect(subject).to be_a(Proc)
|
120
|
+
expect(Howitzer::Utils::PageValidator.validations[web_page.class.name][:title]).to eql(subject)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
context "when options is incorrect" do
|
125
|
+
context "(missing pattern)" do
|
126
|
+
let(:options) { {} }
|
127
|
+
it { expect{subject}.to raise_error(Howitzer::Utils::PageValidator::WrongOptionError, "Please specify ':pattern' option as Regexp object") }
|
128
|
+
end
|
129
|
+
context "(string pattern)" do
|
130
|
+
let(:options) { {pattern: "foo"} }
|
131
|
+
it { expect{subject}.to raise_error(Howitzer::Utils::PageValidator::WrongOptionError, "Please specify ':pattern' option as Regexp object") }
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
context "when other name" do
|
136
|
+
let(:name) { :unknown }
|
137
|
+
let(:options) { {} }
|
138
|
+
it { expect{subject}.to raise_error(Howitzer::Utils::PageValidator::UnknownValidationName, "unknown 'unknown' validation name") }
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
@@ -0,0 +1,250 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require "#{lib_path}/howitzer/web_page"
|
3
|
+
require "#{lib_path}/howitzer/utils/capybara_settings"
|
4
|
+
|
5
|
+
|
6
|
+
describe "WebPage" do
|
7
|
+
describe ".open" do
|
8
|
+
let(:url_value) { "google.com" }
|
9
|
+
let(:retryable) { double }
|
10
|
+
let(:check_correct_page_loaded) { double }
|
11
|
+
let(:other_instance) { WebPage.instance }
|
12
|
+
subject { WebPage.open(url_value) }
|
13
|
+
before do
|
14
|
+
stub_const("WebPage::URL_PATTERN", 'pattern')
|
15
|
+
allow(WebPage.instance).to receive(:check_correct_page_loaded) { true }
|
16
|
+
end
|
17
|
+
it do
|
18
|
+
expect(log).to receive(:info).with("Open WebPage page by 'google.com' url")
|
19
|
+
expect(WebPage).to receive(:retryable) { retryable }
|
20
|
+
expect(subject).to eq(other_instance)
|
21
|
+
subject
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe ".given" do
|
26
|
+
let(:wait_for_url) { double }
|
27
|
+
before do
|
28
|
+
stub_const("WebPage::URL_PATTERN",'pattern')
|
29
|
+
allow(WebPage.instance).to receive(:check_correct_page_loaded) { true }
|
30
|
+
end
|
31
|
+
it do
|
32
|
+
expect(WebPage.given).to be_a_kind_of(WebPage)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#tinymce_fill_in" do
|
37
|
+
subject { WebPage.instance.tinymce_fill_in(name,options) }
|
38
|
+
let(:name) { 'name' }
|
39
|
+
let(:options) { {with: "some content"} }
|
40
|
+
before do
|
41
|
+
allow(WebPage.instance).to receive(:current_url) { "google.com" }
|
42
|
+
allow(settings).to receive(:driver) { driver_name }
|
43
|
+
end
|
44
|
+
context "when correct driver specified" do
|
45
|
+
let(:driver_name) { 'selenium' }
|
46
|
+
let(:page) { double }
|
47
|
+
let(:driver) { double }
|
48
|
+
let(:browser) { double }
|
49
|
+
let(:switch_to) { double }
|
50
|
+
let(:find) { double }
|
51
|
+
let(:native) { double }
|
52
|
+
it do
|
53
|
+
expect(WebPage.instance).to receive(:page).exactly(3).times { page }
|
54
|
+
expect(page).to receive(:driver).ordered { driver }
|
55
|
+
expect(driver).to receive(:browser).ordered { browser }
|
56
|
+
expect(browser).to receive(:switch_to).ordered { switch_to }
|
57
|
+
expect(switch_to).to receive(:frame).with("name_ifr").once
|
58
|
+
|
59
|
+
expect(page).to receive(:find).with(:css, '#tinymce').ordered { find }
|
60
|
+
expect(find).to receive(:native).ordered { native }
|
61
|
+
expect(native).to receive(:send_keys).with("some content").once
|
62
|
+
|
63
|
+
expect(page).to receive(:driver) { driver }
|
64
|
+
expect(driver).to receive(:browser) { browser }
|
65
|
+
expect(browser).to receive(:switch_to) { switch_to }
|
66
|
+
expect(switch_to).to receive(:default_content)
|
67
|
+
|
68
|
+
subject
|
69
|
+
end
|
70
|
+
end
|
71
|
+
context "when incorrect driver specified" do
|
72
|
+
let(:driver_name) { 'ff' }
|
73
|
+
let(:page) { double }
|
74
|
+
it do
|
75
|
+
expect(WebPage.instance).to receive(:page) { page }
|
76
|
+
expect(page).to receive(:execute_script).with("tinyMCE.get('name').setContent('some content')")
|
77
|
+
subject
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
describe "#click_alert_box" do
|
82
|
+
subject { WebPage.instance.click_alert_box(flag_value) }
|
83
|
+
before do
|
84
|
+
allow(settings).to receive(:driver) { driver_name }
|
85
|
+
allow(settings).to receive(:timeout_tiny) { 0 }
|
86
|
+
allow(WebPage.instance).to receive(:current_url) { "google.com" }
|
87
|
+
end
|
88
|
+
context "when flag true and correct driver specified" do
|
89
|
+
let(:flag_value) { true }
|
90
|
+
let(:page) { double }
|
91
|
+
let(:alert) { double }
|
92
|
+
let(:driver) { double }
|
93
|
+
let(:browser) { double }
|
94
|
+
let(:switch_to) { double }
|
95
|
+
let(:driver_name) { 'selenium' }
|
96
|
+
it do
|
97
|
+
expect(WebPage.instance).to receive(:page) { page }
|
98
|
+
expect(page).to receive(:driver).ordered { driver }
|
99
|
+
expect(driver).to receive(:browser).ordered { browser }
|
100
|
+
expect(browser).to receive(:switch_to).ordered { switch_to }
|
101
|
+
expect(switch_to).to receive(:alert).ordered { alert }
|
102
|
+
expect(alert).to receive(:accept).once
|
103
|
+
subject
|
104
|
+
end
|
105
|
+
end
|
106
|
+
context "when flag false and correct driver specified" do
|
107
|
+
let(:flag_value) { false }
|
108
|
+
let(:page) { double }
|
109
|
+
let(:alert) { double }
|
110
|
+
let(:driver) { double }
|
111
|
+
let(:browser) { double }
|
112
|
+
let(:switch_to) { double }
|
113
|
+
let(:driver_name) { 'selenium' }
|
114
|
+
it do
|
115
|
+
expect(WebPage.instance).to receive(:page) { page }
|
116
|
+
expect(page).to receive(:driver).ordered { driver }
|
117
|
+
expect(driver).to receive(:browser).ordered { browser }
|
118
|
+
expect(browser).to receive(:switch_to).ordered { switch_to }
|
119
|
+
expect(switch_to).to receive(:alert).ordered { alert }
|
120
|
+
expect(alert).to receive(:dismiss).once
|
121
|
+
subject
|
122
|
+
end
|
123
|
+
end
|
124
|
+
context "when flag true and wrong driver specified" do
|
125
|
+
let(:flag_value) { true }
|
126
|
+
let(:page) { double }
|
127
|
+
let(:driver_name) { 'ff' }
|
128
|
+
it do
|
129
|
+
expect(WebPage.instance).to receive(:page) { page }
|
130
|
+
expect(page).to receive(:evaluate_script).with('window.confirm = function() { return true; }')
|
131
|
+
subject
|
132
|
+
end
|
133
|
+
end
|
134
|
+
context "when flag false and wrong driver specified" do
|
135
|
+
let(:driver_name) { 'ff' }
|
136
|
+
let(:flag_value) { false }
|
137
|
+
let(:page) { double }
|
138
|
+
it do
|
139
|
+
expect(WebPage.instance).to receive(:page) { page }
|
140
|
+
expect(page).to receive(:evaluate_script).with('window.confirm = function() { return false; }')
|
141
|
+
subject
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe "#js_click" do
|
147
|
+
subject { WebPage.instance.js_click(".some_class") }
|
148
|
+
before do
|
149
|
+
allow(settings).to receive(:timeout_tiny) { 0.1 }
|
150
|
+
allow(WebPage.instance).to receive(:current_url) { "google.com" }
|
151
|
+
end
|
152
|
+
let(:page) { double }
|
153
|
+
it do
|
154
|
+
expect(WebPage.instance).to receive(:page) { page }
|
155
|
+
expect(page).to receive(:execute_script).with("$('.some_class').trigger('click')")
|
156
|
+
subject
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
160
|
+
|
161
|
+
describe "#wait_for_title" do
|
162
|
+
subject { WebPage.instance.wait_for_title(expected_title) }
|
163
|
+
before do
|
164
|
+
allow(settings).to receive(:timeout_small) { 0.1 }
|
165
|
+
allow(WebPage.instance).to receive(:title) { "title" }
|
166
|
+
end
|
167
|
+
context "when title equals expected title" do
|
168
|
+
let(:expected_title) { "title" }
|
169
|
+
it do
|
170
|
+
expect(subject).to be_true
|
171
|
+
end
|
172
|
+
end
|
173
|
+
context "when title not equals expected title" do
|
174
|
+
let(:expected_title) { "bad title" }
|
175
|
+
let(:error) { WebPage::IncorrectPageError }
|
176
|
+
let(:error_message) { "Current title: title, expected: bad title" }
|
177
|
+
it { expect{subject}.to raise_error(error,error_message) }
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
describe "#wait_for_url" do
|
182
|
+
subject { WebPage.instance.wait_for_url(expected_url) }
|
183
|
+
before do
|
184
|
+
allow(settings).to receive(:timeout_small) { 0.1 }
|
185
|
+
allow(WebPage.instance).to receive(:current_url) { "google.com" }
|
186
|
+
end
|
187
|
+
context "when current_url equals expected_url" do
|
188
|
+
let(:expected_url) { "google.com" }
|
189
|
+
it { expect(subject).to be_true }
|
190
|
+
end
|
191
|
+
context "when current_url not equals expected_url" do
|
192
|
+
let(:expected_url) { "bad_url" }
|
193
|
+
let(:error) { WebPage::IncorrectPageError }
|
194
|
+
let(:error_message) { "Current url: google.com, expected: #{expected_url}" }
|
195
|
+
it { expect{subject}.to raise_error(error, error_message) }
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
describe "#reload" do
|
200
|
+
let(:wait_for_url) { double }
|
201
|
+
subject { WebPage.instance.reload }
|
202
|
+
let(:visit) { double }
|
203
|
+
let(:webpage) { double }
|
204
|
+
before do
|
205
|
+
allow(WebPage.instance).to receive(:current_url) { "google.com" }
|
206
|
+
stub_const("WebPage::URL_PATTERN",'pattern')
|
207
|
+
allow(wait_for_url).to receive('pattern').and_return { true }
|
208
|
+
end
|
209
|
+
it do
|
210
|
+
expect(log).to receive(:info) { "Reload 'google.com' " }
|
211
|
+
expect(WebPage.instance).to receive(:visit).with("google.com")
|
212
|
+
subject
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
describe ".title" do
|
217
|
+
let(:page) { double }
|
218
|
+
subject { WebPage.instance.title }
|
219
|
+
before do
|
220
|
+
allow(WebPage.instance).to receive(:current_url) { "google.com" }
|
221
|
+
end
|
222
|
+
it do
|
223
|
+
expect(WebPage.instance).to receive(:page) { page }
|
224
|
+
expect(page).to receive(:title)
|
225
|
+
subject
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
describe ".current_url" do
|
230
|
+
let(:page) { double }
|
231
|
+
subject { WebPage.current_url }
|
232
|
+
it do
|
233
|
+
expect(WebPage).to receive(:page) { page }
|
234
|
+
expect(page).to receive(:current_url) { "google.com" }
|
235
|
+
expect(subject).to eq("google.com")
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
describe ".text" do
|
240
|
+
let(:page) { double }
|
241
|
+
let(:find) { double }
|
242
|
+
subject { WebPage.text }
|
243
|
+
it do
|
244
|
+
expect(WebPage).to receive(:page) { page }
|
245
|
+
expect(page).to receive(:find).with('body') { find }
|
246
|
+
expect(find).to receive(:text) { "some body text" }
|
247
|
+
expect(subject).to eq("some body text")
|
248
|
+
end
|
249
|
+
end
|
250
|
+
end
|