I wrote a Ruby script to check if the layer found in DOM in Firebug for
the page www.jira.com is matching with the hash values declared in my
script. Below is the Ruby script I have written:
browser.goto('www.jira.com')
JIRA_DATA_LAYER = {
'one' => {
'event' => 'gtm.js',
'gtm.start' => 1468393184212,
},
'two' => {
'event' => 'gtm.start',
'gtm.start' => 1468332746325,
},
'three' => {
'event' => 'gtm.load',
'gtm.load' => 1468483543548,
},
}
def read_data_layer(browser)
data_layer = browser.execute_script("return dataLayer")
return data_layer
end
def compare_jira_data_layer(browser)
result = []
compare_data_layer = read_data_layer(browser)
compare_data_layer[0].each do |key,value|
result.push(key)
end
return result.join("\n")
end
Following part of the code is not working:
-------------------------------------------------------------------------
def jira_data_layer(browser, layer)
message = []
result_compare = compare_jira_data_layer(browser)
message.push('Checking Jira Data Layer')
JIRA_DATA_LAYER.each do |key, value|
value.each do |data_layer_key, data_layer_value|
if data_layer_value == result_compare
result = 'matches - PASS'
else
result = 'does not match - FAIL'
end
message.push("#{data_layer_key} #{result}")
end
end
return message.join("\n")
end
-------------------------------------------------------------------------
data_layer = read_data_layer(browser)
puts jira_data_layer(browser, data_layer)
I want the following OUTPUT to be achieved:
'event => gtm.js' matches - PASS
'gtm.start => 1468393184212' matches - PASS
But I am getting this:
event does not match - FAIL
gtm.start does not match - FAIL
Where am I going wrong? Please help. Thanks in advance