sandoz.bbmb.ch 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.
- checksums.yaml +7 -0
- data/.gitignore +7 -0
- data/.travis.yml +26 -0
- data/Gemfile +12 -0
- data/History.txt +6 -0
- data/LICENSE +339 -0
- data/Rakefile +21 -0
- data/doc/index.rbx +14 -0
- data/doc/resources/activex/BbmbBarcodeReader.CAB +0 -0
- data/doc/resources/activex/BbmbBarcodeReader2.CAB +0 -0
- data/doc/resources/bbmb.css +301 -0
- data/doc/resources/errors/appdown.html +14 -0
- data/doc/resources/javascript/bcreader.js +131 -0
- data/doc/resources/javascript/order.js +65 -0
- data/doc/resources/javascript/widget/ContentToggler.js +60 -0
- data/doc/resources/javascript/widget/__package__.js +2 -0
- data/doc/resources/javascript/widget/templates/ContentToggler.html +4 -0
- data/doc/resources/logo.png +0 -0
- data/lib/bbmb/html/util/lookandfeel.rb +202 -0
- data/lib/bbmb/sandoz.rb +4 -0
- data/lib/bbmb/sandoz/html/state/viral/customer.rb +25 -0
- data/lib/bbmb/sandoz/version.rb +5 -0
- data/lib/bbmb/util/csv_importer.rb +123 -0
- data/readme.md +28 -0
- data/sandoz.bbmb.ch.gemspec +45 -0
- data/test/rcov +2 -0
- data/test/selenium.rb +1687 -0
- data/test/selenium/selenium-server.jar +0 -0
- data/test/selenium/test_current_order.rb +336 -0
- data/test/selenium/test_customer.rb +363 -0
- data/test/selenium/test_customers.rb +92 -0
- data/test/selenium/test_favorites.rb +257 -0
- data/test/selenium/test_favorites_result.rb +81 -0
- data/test/selenium/test_history.rb +112 -0
- data/test/selenium/test_login.rb +112 -0
- data/test/selenium/test_orders.rb +111 -0
- data/test/selenium/test_result.rb +157 -0
- data/test/selenium/unit.rb +146 -0
- data/test/stub/http_server.rb +140 -0
- data/test/stub/persistence.rb +58 -0
- data/test/suite.rb +15 -0
- data/test/util/data/Artikel.TXT +50 -0
- data/test/util/data/Kunden.TXT +14 -0
- data/test/util/test_csv_importer.rb +136 -0
- metadata +414 -0
@@ -0,0 +1,112 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Selenium::TestLogin -- bbmb.ch -- 21.09.2006 -- hwyss@ywesee.com
|
3
|
+
|
4
|
+
$: << File.expand_path('..', File.dirname(__FILE__))
|
5
|
+
|
6
|
+
require "selenium/unit"
|
7
|
+
|
8
|
+
module BBMB
|
9
|
+
module Selenium
|
10
|
+
class TestLogin < Test::Unit::TestCase
|
11
|
+
include Selenium::TestCase
|
12
|
+
def test_login
|
13
|
+
open "/"
|
14
|
+
assert_equal "BBMB", get_title
|
15
|
+
assert is_text_present("Willkommen bei Sandoz")
|
16
|
+
assert_equal "Email", get_text("//label[@for='email']")
|
17
|
+
assert is_element_present("email")
|
18
|
+
assert_equal "Passwort", get_text("//label[@for='pass']")
|
19
|
+
assert is_element_present("pass")
|
20
|
+
assert_match Regexp.new(BBMB.config.http_server),
|
21
|
+
get_attribute("//form[@name='login']@action")
|
22
|
+
assert is_element_present("//input[@name='login']")
|
23
|
+
end
|
24
|
+
def test_login__fail_unknown_user
|
25
|
+
open "/"
|
26
|
+
assert_equal "BBMB", get_title
|
27
|
+
@auth.should_receive(:login).and_return { raise Yus::UnknownEntityError }
|
28
|
+
type "email", "unknown@bbmb.ch"
|
29
|
+
type "pass", "secret"
|
30
|
+
click "//input[@type='submit']"
|
31
|
+
wait_for_page_to_load "30000"
|
32
|
+
assert_equal "BBMB", get_title
|
33
|
+
assert_equal "error", get_attribute("//label[@for='email']@class")
|
34
|
+
end
|
35
|
+
def test_login__fail_wrong_password
|
36
|
+
open "/"
|
37
|
+
assert_equal "BBMB", get_title
|
38
|
+
@auth.should_receive(:login).and_return { raise Yus::AuthenticationError }
|
39
|
+
type "email", "unknown@bbmb.ch"
|
40
|
+
type "pass", "secret"
|
41
|
+
click "//input[@type='submit']"
|
42
|
+
wait_for_page_to_load "30000"
|
43
|
+
assert_equal "BBMB", get_title
|
44
|
+
assert_equal "error", get_attribute("//label[@for='pass']@class")
|
45
|
+
end
|
46
|
+
def test_login__force_home
|
47
|
+
open "/"
|
48
|
+
assert_equal "BBMB", get_title
|
49
|
+
open "/de/home"
|
50
|
+
assert is_text_present("Willkommen bei Sandoz")
|
51
|
+
assert is_element_present("email")
|
52
|
+
assert is_element_present("pass")
|
53
|
+
assert is_element_present("//input[@name='login']")
|
54
|
+
end
|
55
|
+
def test_logout__clean
|
56
|
+
@auth.should_ignore_missing
|
57
|
+
@persistence.should_receive(:all).and_return([])
|
58
|
+
user = login_admin
|
59
|
+
assert is_element_present("link=Abmelden")
|
60
|
+
assert_equal "Abmelden", get_text("link=Abmelden")
|
61
|
+
click "link=Abmelden"
|
62
|
+
wait_for_page_to_load "30000"
|
63
|
+
assert_equal "BBMB", get_title
|
64
|
+
assert_equal "Email", get_text("//label[@for='email']")
|
65
|
+
assert is_element_present("email")
|
66
|
+
assert_equal "Passwort", get_text("//label[@for='pass']")
|
67
|
+
assert is_element_present("pass")
|
68
|
+
open "/de/customers"
|
69
|
+
# session is now invalid, we stay in login-mask
|
70
|
+
assert_equal "BBMB", get_title
|
71
|
+
assert_equal "Email", get_text("//label[@for='email']")
|
72
|
+
assert is_element_present("email")
|
73
|
+
assert_equal "Passwort", get_text("//label[@for='pass']")
|
74
|
+
assert is_element_present("pass")
|
75
|
+
end
|
76
|
+
def test_logout__timeout
|
77
|
+
@auth.should_ignore_missing
|
78
|
+
@persistence.should_receive(:all).and_return([])
|
79
|
+
user = login_admin
|
80
|
+
user.should_receive(:expired?).and_return(true)
|
81
|
+
user.should_receive(:logout)
|
82
|
+
refresh
|
83
|
+
wait_for_page_to_load "30000"
|
84
|
+
assert_equal "BBMB", get_title
|
85
|
+
assert is_element_present("email")
|
86
|
+
assert is_element_present("pass")
|
87
|
+
end
|
88
|
+
def test_logout__disconnect
|
89
|
+
@auth.should_ignore_missing
|
90
|
+
@persistence.should_receive(:all).and_return([])
|
91
|
+
user = login_admin
|
92
|
+
user.should_receive(:expired?).and_return { raise DRb::DRbError }
|
93
|
+
refresh
|
94
|
+
wait_for_page_to_load "30000"
|
95
|
+
assert_equal "BBMB", get_title
|
96
|
+
assert is_element_present("email")
|
97
|
+
assert is_element_present("pass")
|
98
|
+
end
|
99
|
+
def test_new_customer_form
|
100
|
+
open "/"
|
101
|
+
assert_equal "BBMB", get_title
|
102
|
+
assert_equal "Neuer Kunde", get_text("//label[@for='new_customer']")
|
103
|
+
assert_equal <<-EOS.strip, get_text("//a[@name='new_customer']")
|
104
|
+
Bestellen Sie jetzt online. Wir richten für Sie den spezifisch auf Ihre Praxis zugeschnittenen, benutzerfreundlichen E-Shop ein!
|
105
|
+
Unser Kundenservice oder unsere Aussendienstmitarbeiter beraten Sie gerne!
|
106
|
+
EOS
|
107
|
+
assert_match Regexp.new("^mailto:"),
|
108
|
+
get_attribute("//a[@name='new_customer']@href")
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Selenium::TestOrders -- bbmb.ch -- 05.10.2006 -- hwyss@ywesee.com
|
3
|
+
|
4
|
+
$: << File.expand_path('..', File.dirname(__FILE__))
|
5
|
+
|
6
|
+
require 'selenium/unit'
|
7
|
+
|
8
|
+
module BBMB
|
9
|
+
module Selenium
|
10
|
+
class TestOrders < Test::Unit::TestCase
|
11
|
+
include Selenium::TestCase
|
12
|
+
def setup_customer
|
13
|
+
BBMB.persistence.should_ignore_missing
|
14
|
+
customer = BBMB::Model::Customer.new('007')
|
15
|
+
customer.organisation = 'Test-Customer'
|
16
|
+
customer.instance_variable_set('@email', 'test.customer@bbmb.ch')
|
17
|
+
customer.plz = '7777'
|
18
|
+
@persistence.should_receive(:all).and_return { |klass|
|
19
|
+
assert_equal(BBMB::Model::Customer, klass)
|
20
|
+
[customer]
|
21
|
+
}
|
22
|
+
product1 = BBMB::Model::Product.new('1')
|
23
|
+
product1.description.de = "Product 1"
|
24
|
+
product1.price = Util::Money.new(11.10)
|
25
|
+
product2 = BBMB::Model::Product.new('2')
|
26
|
+
product2.description.de = "Product 2"
|
27
|
+
product2.price = Util::Money.new(12.20)
|
28
|
+
product3 = BBMB::Model::Product.new('3')
|
29
|
+
product3.description.de = "Product 3"
|
30
|
+
product3.price = Util::Money.new(13.30)
|
31
|
+
order = customer.current_order
|
32
|
+
order.add(2, product1)
|
33
|
+
order.add(3, product2)
|
34
|
+
order.priority = 41
|
35
|
+
order.shipping = 50
|
36
|
+
order.reference = "Réf. N°"
|
37
|
+
order.comment = "Freetext"
|
38
|
+
customer.commit_order!
|
39
|
+
order = customer.current_order
|
40
|
+
order.add(5, product2)
|
41
|
+
order.add(7, product3)
|
42
|
+
customer.commit_order!
|
43
|
+
customer
|
44
|
+
end
|
45
|
+
def test_archive__admin
|
46
|
+
customer = setup_customer
|
47
|
+
user = login_admin
|
48
|
+
@selenium.click "link=Test-Customer"
|
49
|
+
@selenium.wait_for_page_to_load "30000"
|
50
|
+
assert_equal "BBMB | Kunde", @selenium.get_title
|
51
|
+
|
52
|
+
assert @selenium.is_element_present("link=Sfr. 262.90")
|
53
|
+
@selenium.click "link=Sfr. 262.90"
|
54
|
+
@selenium.wait_for_page_to_load "30000"
|
55
|
+
assert_equal "BBMB | Archiv", @selenium.get_title
|
56
|
+
assert @selenium.is_text_present(Date.today.strftime('%d.%m.%Y'))
|
57
|
+
assert @selenium.is_text_present("108.80")
|
58
|
+
assert @selenium.is_text_present("154.10")
|
59
|
+
|
60
|
+
## orders are ordered with newest on top - index 0 thus yields order2
|
61
|
+
@selenium.click "name=commit_time index=0"
|
62
|
+
@selenium.wait_for_page_to_load "30000"
|
63
|
+
assert_equal "BBMB | Archiv - Bestellung", @selenium.get_title
|
64
|
+
assert @selenium.is_text_present("Product 2")
|
65
|
+
assert @selenium.is_text_present("Product 3")
|
66
|
+
assert @selenium.is_text_present("Total Sfr. 154.10")
|
67
|
+
assert !@selenium.is_text_present("Interne Bestellnummer")
|
68
|
+
assert !@selenium.is_text_present("Bemerkungen")
|
69
|
+
assert !@selenium.is_text_present("Versandart")
|
70
|
+
|
71
|
+
## go directly to the next order without returning to orders
|
72
|
+
@selenium.open "/de/order/order_id/007-1"
|
73
|
+
@selenium.wait_for_page_to_load "30000"
|
74
|
+
assert_equal "BBMB | Archiv - Bestellung", @selenium.get_title
|
75
|
+
assert @selenium.is_text_present("Product 1")
|
76
|
+
assert @selenium.is_text_present("Product 2")
|
77
|
+
assert @selenium.is_text_present("Total Sfr. 108.80")
|
78
|
+
assert @selenium.is_text_present("Interne Bestellnummer")
|
79
|
+
assert @selenium.is_text_present("Réf. N°")
|
80
|
+
assert @selenium.is_text_present("Bemerkungen")
|
81
|
+
assert @selenium.is_text_present("Freetext")
|
82
|
+
assert @selenium.is_text_present("Versandart")
|
83
|
+
assert @selenium.is_text_present("Terminfracht")
|
84
|
+
end
|
85
|
+
def test_archive__customer
|
86
|
+
customer = setup_customer
|
87
|
+
user = login_customer customer
|
88
|
+
@selenium.click "link=Archiv"
|
89
|
+
@selenium.wait_for_page_to_load "30000"
|
90
|
+
assert_equal "BBMB | Archiv", @selenium.get_title
|
91
|
+
assert @selenium.is_text_present(Date.today.strftime('%d.%m.%Y'))
|
92
|
+
assert @selenium.is_text_present("108.80")
|
93
|
+
assert @selenium.is_text_present("154.10")
|
94
|
+
|
95
|
+
## orders are ordered with newest on top - index 1 thus yields order1
|
96
|
+
@selenium.click "name=commit_time index=1"
|
97
|
+
@selenium.wait_for_page_to_load "30000"
|
98
|
+
assert_equal "BBMB | Archiv - Bestellung", @selenium.get_title
|
99
|
+
assert @selenium.is_text_present("Product 1")
|
100
|
+
assert @selenium.is_text_present("Product 2")
|
101
|
+
assert @selenium.is_text_present("Total Sfr. 108.80")
|
102
|
+
assert @selenium.is_text_present("Interne Bestellnummer")
|
103
|
+
assert @selenium.is_text_present("Réf. N°")
|
104
|
+
assert @selenium.is_text_present("Bemerkungen")
|
105
|
+
assert @selenium.is_text_present("Freetext")
|
106
|
+
assert @selenium.is_text_present("Versandart")
|
107
|
+
assert @selenium.is_text_present("Terminfracht")
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,157 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Selenium::TestResult -- bbmb.ch -- 22.09.2006 -- hwyss@ywesee.com
|
3
|
+
|
4
|
+
$: << File.expand_path('..', File.dirname(__FILE__))
|
5
|
+
|
6
|
+
require 'selenium/unit'
|
7
|
+
|
8
|
+
module BBMB
|
9
|
+
module Selenium
|
10
|
+
class TestResult < Test::Unit::TestCase
|
11
|
+
include Selenium::TestCase
|
12
|
+
def test_result__empty
|
13
|
+
user = login_customer
|
14
|
+
flexstub(Model::Product).should_receive(:search_by_description).times(1).and_return {
|
15
|
+
|query|
|
16
|
+
assert_equal 'product', query
|
17
|
+
[]
|
18
|
+
}
|
19
|
+
@selenium.type "query", "product"
|
20
|
+
@selenium.click "document.search.search"
|
21
|
+
@selenium.wait_for_page_to_load "30000"
|
22
|
+
assert_equal "BBMB | Suchen", @selenium.get_title
|
23
|
+
assert @selenium.is_text_present("Suchresultat: 0 Produkte gefunden")
|
24
|
+
assert @selenium.is_element_present("//input[@type='text' and @name='query']")
|
25
|
+
assert !@selenium.is_element_present("//input[@type='submit' and @name='order_product']")
|
26
|
+
end
|
27
|
+
def test_result__1
|
28
|
+
user = login_customer
|
29
|
+
product = Model::Product.new('12345')
|
30
|
+
product.description.de = 'product - a description'
|
31
|
+
product.price = Util::Money.new(12.50)
|
32
|
+
flexstub(Model::Product).should_receive(:search_by_description).times(1).and_return {
|
33
|
+
|query|
|
34
|
+
assert_equal 'product', query
|
35
|
+
[product]
|
36
|
+
}
|
37
|
+
@selenium.type "query", "product"
|
38
|
+
@selenium.click "document.search.search"
|
39
|
+
@selenium.wait_for_page_to_load "30000"
|
40
|
+
assert_equal "BBMB | Suchen", @selenium.get_title
|
41
|
+
assert @selenium.is_text_present("Suchresultat: 1 Produkt gefunden")
|
42
|
+
assert @selenium.is_element_present("//input[@type='text' and @name='query']")
|
43
|
+
assert @selenium.is_element_present("//input[@type='submit' and @name='order_product']")
|
44
|
+
assert @selenium.is_element_present("//input[@name='quantity[12345]']")
|
45
|
+
assert_equal '0', @selenium.get_value("//input[@name='quantity[12345]']")
|
46
|
+
assert !@selenium.is_text_present("im Rückstand")
|
47
|
+
end
|
48
|
+
def test_result__order
|
49
|
+
BBMB.persistence.should_ignore_missing
|
50
|
+
user = login_customer
|
51
|
+
product = Model::Product.new('12345')
|
52
|
+
product.description.de = 'product - a description'
|
53
|
+
product.price = Util::Money.new(11.50)
|
54
|
+
flexstub(Model::Product).should_receive(:search_by_description).times(1).and_return {
|
55
|
+
|query|
|
56
|
+
assert_equal 'product', query
|
57
|
+
[product]
|
58
|
+
}
|
59
|
+
@selenium.type "query", "product"
|
60
|
+
@selenium.click "document.search.search"
|
61
|
+
@selenium.wait_for_page_to_load "30000"
|
62
|
+
assert_equal "BBMB | Suchen", @selenium.get_title
|
63
|
+
assert @selenium.is_element_present("//input[@name='quantity[12345]']")
|
64
|
+
assert_equal '0', @selenium.get_value("//input[@name='quantity[12345]']")
|
65
|
+
@selenium.type "quantity[12345]", "15"
|
66
|
+
@selenium.click "document.products.order_product"
|
67
|
+
@selenium.wait_for_page_to_load "30000"
|
68
|
+
assert_equal "BBMB | Home", @selenium.get_title
|
69
|
+
assert @selenium.is_element_present("link=product - a description")
|
70
|
+
assert @selenium.is_text_present("11.50")
|
71
|
+
assert @selenium.is_text_present("172.50")
|
72
|
+
end
|
73
|
+
def test_result__backorder
|
74
|
+
user = login_customer
|
75
|
+
product = Model::Product.new('12345')
|
76
|
+
product.description.de = 'product - a description'
|
77
|
+
product.price = Util::Money.new(12.50)
|
78
|
+
product.backorder = true
|
79
|
+
flexstub(Model::Product).should_receive(:search_by_description).times(1).and_return {
|
80
|
+
|query|
|
81
|
+
assert_equal 'product', query
|
82
|
+
[product]
|
83
|
+
}
|
84
|
+
@selenium.type "query", "product"
|
85
|
+
@selenium.click "document.search.search"
|
86
|
+
@selenium.wait_for_page_to_load "30000"
|
87
|
+
assert_equal "BBMB | Suchen", @selenium.get_title
|
88
|
+
assert @selenium.is_text_present("Suchresultat: 1 Produkt gefunden")
|
89
|
+
assert @selenium.is_text_present("im Rückstand")
|
90
|
+
end
|
91
|
+
def test_result__sort
|
92
|
+
user = login_customer
|
93
|
+
product1 = Model::Product.new('12345')
|
94
|
+
product1.description.de = 'product 1'
|
95
|
+
product1.price = Util::Money.new(12.50)
|
96
|
+
product2 = Model::Product.new('12345')
|
97
|
+
product2.description.de = 'product 2'
|
98
|
+
product2.price = Util::Money.new(10.50)
|
99
|
+
flexstub(Model::Product).should_receive(:search_by_description).times(1).and_return {
|
100
|
+
|query|
|
101
|
+
assert_equal 'product', query
|
102
|
+
[product1, product2]
|
103
|
+
}
|
104
|
+
@selenium.type "query", "product"
|
105
|
+
@selenium.click "document.search.search"
|
106
|
+
@selenium.wait_for_page_to_load "30000"
|
107
|
+
assert_equal "BBMB | Suchen", @selenium.get_title
|
108
|
+
assert @selenium.is_text_present("Suchresultat: 2 Produkte gefunden")
|
109
|
+
assert_equal 'product 1', @selenium.get_text("//tr[2]/td[2]")
|
110
|
+
assert_equal 'product 2', @selenium.get_text("//tr[4]/td[2]")
|
111
|
+
|
112
|
+
@selenium.click "link=Preis"
|
113
|
+
@selenium.wait_for_page_to_load "30000"
|
114
|
+
assert @selenium.is_text_present("Suchresultat: 2 Produkte gefunden")
|
115
|
+
assert_equal 'product 2', @selenium.get_text("//tr[2]/td[2]")
|
116
|
+
assert_equal 'product 1', @selenium.get_text("//tr[4]/td[2]")
|
117
|
+
|
118
|
+
@selenium.click "link=Preis"
|
119
|
+
@selenium.wait_for_page_to_load "30000"
|
120
|
+
assert @selenium.is_text_present("Suchresultat: 2 Produkte gefunden")
|
121
|
+
assert_equal 'product 1', @selenium.get_text("//tr[2]/td[2]")
|
122
|
+
assert_equal 'product 2', @selenium.get_text("//tr[4]/td[2]")
|
123
|
+
end
|
124
|
+
def test_result__has_ordered_products
|
125
|
+
BBMB.persistence.should_ignore_missing
|
126
|
+
user = login_customer
|
127
|
+
product = Model::Product.new('12345')
|
128
|
+
product.description.de = 'product - a description'
|
129
|
+
product.price = Util::Money.new(11.50)
|
130
|
+
@customer.current_order.add(5, product)
|
131
|
+
flexstub(Model::Product).should_receive(:search_by_description).times(1).and_return {
|
132
|
+
|query|
|
133
|
+
assert_equal 'product', query
|
134
|
+
[product]
|
135
|
+
}
|
136
|
+
@selenium.type "query", "product"
|
137
|
+
@selenium.click "document.search.search"
|
138
|
+
@selenium.wait_for_page_to_load "30000"
|
139
|
+
assert_equal "BBMB | Suchen", @selenium.get_title
|
140
|
+
assert @selenium.is_element_present("//input[@name='quantity[12345]']")
|
141
|
+
assert_equal '5', @selenium.get_value("//input[@name='quantity[12345]']")
|
142
|
+
@selenium.type "quantity[12345]", "trigger an error!"
|
143
|
+
@selenium.click "document.products.order_product"
|
144
|
+
@selenium.wait_for_page_to_load "30000"
|
145
|
+
assert_equal "BBMB | Suchen", @selenium.get_title
|
146
|
+
assert @selenium.is_text_present("'trigger an error!' ist keine gültige Zahl.")
|
147
|
+
assert @selenium.is_element_present("//input[@name='quantity[12345]']")
|
148
|
+
assert_equal '5', @selenium.get_value("//input[@name='quantity[12345]']")
|
149
|
+
@selenium.type "quantity[12345]", "10"
|
150
|
+
@selenium.click "document.products.order_product"
|
151
|
+
@selenium.wait_for_page_to_load "30000"
|
152
|
+
assert_equal "BBMB | Home", @selenium.get_title
|
153
|
+
assert_equal(10, @customer.current_order.quantity(product))
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Selenium::TestCase -- bbmb.ch -- 22.09.2006 -- hwyss@ywesee.com
|
3
|
+
|
4
|
+
$: << File.expand_path('../../lib', File.dirname(__FILE__))
|
5
|
+
|
6
|
+
ENV['LD_LIBRARY_PATH'] = '/usr/local/firefox'
|
7
|
+
if(pid = Kernel.fork)
|
8
|
+
at_exit {
|
9
|
+
Process.kill('HUP', pid)
|
10
|
+
$selenium.stop if($selenium.respond_to?(:stop))
|
11
|
+
}
|
12
|
+
else
|
13
|
+
path = File.expand_path('selenium-server.jar', File.dirname(__FILE__))
|
14
|
+
command = "java -jar #{path} &> /dev/null"
|
15
|
+
exec(command)
|
16
|
+
end
|
17
|
+
|
18
|
+
require "bbmb/config"
|
19
|
+
require 'delegate'
|
20
|
+
require 'selenium'
|
21
|
+
|
22
|
+
module BBMB
|
23
|
+
module Selenium
|
24
|
+
class SeleniumWrapper < SimpleDelegator
|
25
|
+
def initialize(host, port, browser, server, port2)
|
26
|
+
@server = server
|
27
|
+
@selenium = ::Selenium::SeleneseInterpreter.new(host, port, browser,
|
28
|
+
server, port2)
|
29
|
+
super @selenium
|
30
|
+
end
|
31
|
+
def open(path)
|
32
|
+
@selenium.open(@server + path)
|
33
|
+
end
|
34
|
+
def type(*args)
|
35
|
+
@selenium.type(*args)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
BBMB.config.http_server = 'http://localhost'
|
42
|
+
|
43
|
+
$selenium = BBMB::Selenium::SeleniumWrapper.new("localhost", 4444,
|
44
|
+
"*chrome", BBMB.config.http_server + ":10080", 10000)
|
45
|
+
|
46
|
+
start = Time.now
|
47
|
+
begin
|
48
|
+
$selenium.start
|
49
|
+
rescue Errno::ECONNREFUSED
|
50
|
+
sleep 1
|
51
|
+
if((Time.now - start) > 15)
|
52
|
+
raise
|
53
|
+
else
|
54
|
+
retry
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
require "bbmb/util/server"
|
59
|
+
require 'flexmock'
|
60
|
+
require 'logger'
|
61
|
+
require 'stub/http_server'
|
62
|
+
require 'stub/persistence'
|
63
|
+
require "test/unit"
|
64
|
+
|
65
|
+
module BBMB
|
66
|
+
module Selenium
|
67
|
+
module TestCase
|
68
|
+
include FlexMock::TestCase
|
69
|
+
include SeleniumHelper
|
70
|
+
def setup
|
71
|
+
Model::Customer.clear_instances
|
72
|
+
Model::Product.clear_instances
|
73
|
+
BBMB.logger = Logger.new($stdout)
|
74
|
+
BBMB.logger.level = Logger::FATAL #DEBUG
|
75
|
+
@auth = flexmock('authenticator')
|
76
|
+
BBMB.auth = @auth
|
77
|
+
@persistence = flexmock('persistence')
|
78
|
+
BBMB.persistence = @persistence
|
79
|
+
@server = Util::Server.new(@persistence)
|
80
|
+
@server.extend(DRbUndumped)
|
81
|
+
drb_url = "druby://localhost:10081"
|
82
|
+
@drb = Thread.new {
|
83
|
+
@drb_server = DRb.start_service(drb_url, @server)
|
84
|
+
}
|
85
|
+
@drb.abort_on_exception = true
|
86
|
+
@http_server = Stub.http_server(drb_url)
|
87
|
+
@webrick = Thread.new { @http_server.start }
|
88
|
+
@verification_errors = []
|
89
|
+
if $selenium
|
90
|
+
@selenium = $selenium
|
91
|
+
else
|
92
|
+
@selenium = SeleniumWrapper.new("localhost", 4444, "*chrome",
|
93
|
+
BBMB.config.http_server + ":10080", 10000)
|
94
|
+
@selenium.start
|
95
|
+
end
|
96
|
+
@selenium.set_context("TestBbmb")
|
97
|
+
end
|
98
|
+
def teardown
|
99
|
+
@selenium.stop unless $selenium
|
100
|
+
@http_server.shutdown
|
101
|
+
@drb_server.stop_service
|
102
|
+
assert_equal [], @verification_errors
|
103
|
+
super
|
104
|
+
end
|
105
|
+
def login(email, *permissions)
|
106
|
+
user = mock_user email, *permissions
|
107
|
+
@auth.should_receive(:login).and_return(user)
|
108
|
+
@selenium.open "/"
|
109
|
+
@selenium.type "email", email
|
110
|
+
@selenium.type "pass", "test"
|
111
|
+
@selenium.click "//input[@name='login']"
|
112
|
+
@selenium.wait_for_page_to_load "30000"
|
113
|
+
user
|
114
|
+
end
|
115
|
+
def login_admin
|
116
|
+
login "test.admin@bbmb.ch", ['login', 'ch.bbmb.Admin'],
|
117
|
+
['edit', 'yus.entities']
|
118
|
+
end
|
119
|
+
def login_customer(customer=nil)
|
120
|
+
email = "test.customer@bbmb.ch"
|
121
|
+
if(customer)
|
122
|
+
email = customer.email
|
123
|
+
@customer = customer
|
124
|
+
else
|
125
|
+
@customer = Model::Customer.new('007')
|
126
|
+
@customer.instance_variable_set('@email', email)
|
127
|
+
end
|
128
|
+
login email, ['login', 'ch.bbmb.Customer']
|
129
|
+
end
|
130
|
+
def mock_user(email, *permissions)
|
131
|
+
user = flexmock(email)
|
132
|
+
user.should_receive(:allowed?).and_return { |*pair|
|
133
|
+
permissions.include?(pair)
|
134
|
+
}
|
135
|
+
user.should_receive(:name).and_return(email)
|
136
|
+
user.should_receive(:get_preference)
|
137
|
+
user.should_receive(:find_entity).and_return { |email|
|
138
|
+
(@yus_entities ||= {})[email]
|
139
|
+
}
|
140
|
+
user.should_receive(:last_login)
|
141
|
+
user.should_ignore_missing
|
142
|
+
user
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|