-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathservice.rb
127 lines (107 loc) · 4.51 KB
/
service.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
require_relative 'navbar'
require 'site_prism'
class Service < SitePrism::Page
include ::RSpec::Matchers
set_url applicationURL("#/services?disable-animation=true&loglevel=debug")
set_url_matcher /services/
section :navbar, NavBarSection, ".navbar-collapse"
element :addPublicEndpoint_button, "[ng-click='modalAddPublicEndpoint()']"
element :publicEndpoints_table, "table[data-config='publicEndpointsTable']"
element :ipAssignments_table, "table[data-config='ipsTable']"
element :configFiles_table, "table[data-config='configTable']"
# add public endpoint dialog elements
element :addPublicEndpoint_dialog, ".modal-content"
element :addVHostApp_select, :xpath, "//select[@id='add_vhost_application']"
# type selector
element :buttonPortType, "div.btn-group", "//input[@value='port']"
element :buttonVHostType, "div.btn-group", "//input[@value='vhost']"
# type port
element :newHostName_input, :xpath, "//input[@name='new_host_name']"
element :newPort_input, :xpath, "//input[@id='add_public_endpoint_port']"
element :addProtocol_select, :xpath, "//select[@id='add_port_protocol']"
# type vhost
element :newVHost_input, :xpath, "//input[@id='add_vhost_vhost']"
# Look up the table data for the given port and remove it using
# the UI.
def remove_publicendpoint_port_json(name)
expect(remove_publicendpoint?("table://ports/#{name}/PortAddr")).to be(true)
end
# Look up the table data for the given vhost and remove it using
# the UI.
def remove_publicendpoint_vhost_json(name)
expect(remove_publicendpoint?("table://vhosts/#{name}/Name")).to be(true)
end
# Removes the public endpoint (vhost or port) by looking up the entry and
# clicking the delete button.
def remove_publicendpoint?(name)
name = getTableValue(name)
self.page.all(:xpath, "//table[@data-config='publicEndpointsTable']//tr").each do |tr|
if tr.text.include?(name)
btn = tr.find(:xpath, ".//button[@ng-click='clickRemovePublicEndpoint(publicEndpoint)']")
if btn
btn.click
# confirm the removal
cnf = find(:xpath, "//div[@class='modal-content']//button", :text => "Remove")
cnf.click
refreshPage()
return true
end
end
end
return false
end
def click_add_publicendpoint_button()
self.addPublicEndpoint_button.click
# wait till modal is done loading
expect(self).to have_no_css(".uilock", :visible => true)
find("#formWait") # wait until the angular binds are done. see add-public-endpoint.html
end
def check_endpoint_unique_column?(ctitle, cvalue)
found = 0
self.page.all(:xpath, "//table[@data-config='publicEndpointsTable']//tr//td[@data-title-text=#{ctitle}]").each do |td|
if td.text.include?(cvalue)
found += 1
end
end
return found == 1
end
def check_endpoint_find?(c1, c2)
delay = 3 # seconds
maxRetries = 2
begin
retries ||= 0
self.page.all(:xpath, "//table[@data-config='publicEndpointsTable']//tr").each do |tr|
line=tr.text.upcase()
if line.include?(c1) && line.include?(c2)
return true
end
end
# For whatever reason, this method sometimes fails with a 'stale element reference' error, which can mean
# that in between the time we find an element and try to reference, it's been deleted.
# So we use a retry here as a work around.
# For more information, google "selenium stale element reference".
rescue Selenium::WebDriver::Error::StaleElementReferenceError
sleep delay
retry if (retries += 1) < maxRetries
end
return false
end
def check_vhost_exists?(vhost)
vhostName = getTableValue(vhost)
searchStr = "https://#{vhostName}."
found = false
within(self.publicEndpoints_table) do
found = page.has_text?(searchStr)
end
return found
end
def check_public_port_exists?(port)
portName = getTableValue(port)
searchStr = ":#{portName}"
found = false
within(self.publicEndpoints_table) do
found = page.has_text?(searchStr)
end
return found
end
end