Class: CukeParser::ParseEngine::HtmlParser

Inherits:
Object
  • Object
show all
Defined in:
lib/parse_engine/html_parser.rb

Instance Method Summary collapse

Constructor Details

#initializeHtmlParser

Returns a new instance of HtmlParser.



7
8
9
10
11
# File 'lib/parse_engine/html_parser.rb', line 7

def initialize
	@utils = ParserUtils.new
	@system_data_path = "/archive/systemData.json"
	@cuke_data = "/archive/cucumber.html"
end

Instance Method Details

#get_build(file_path) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/parse_engine/html_parser.rb', line 13

def get_build(file_path)
	if File.exists?(file_path)
  		today = Time.now
    	date = today.to_s.split(" ")[0]
    	time = today.to_s.split(" ")[1]
    	@cur_build = CukeModel::CukeSuite.new(date,time,today,nil,nil,nil,nil,nil)
		return parse_build(file_path)
	else
		#nothing was found
		return false
	end
end

#parse_build(file_path) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/parse_engine/html_parser.rb', line 26

def parse_build(file_path)
	page = Nokogiri::HTML(open(file_path))
   	features = parse_features(page)
	if @cur_build.status.empty?
		#all the steps passed
		@cur_build.status = "passed"
	end
	script = page.css('script').to_a.pop(2)
	duration = script[0].text.gsub("document.getElementById('duration').innerHTML = \"Finished in <strong>","")
	duration = duration.to_s.gsub(" seconds</strong>\";","")
	@cur_build.duration = 0
	@cur_build.converted_duration = duration
	@cur_build.features = features['list']
	return @cur_build
end

#parse_features(features) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/parse_engine/html_parser.rb', line 42

def parse_features(features)
	feature_data = Hash['duration', 0, 'list', Array.new]
	features.css('div.feature').each do |feature|
		@cur_feature = CukeModel::CukeFeature.new("Feature",feature.css('span.val')[0].text.gsub("Feature: ",""))
		scenarios = parse_scenarios((feature.css('div.background') + feature.css('div.scenario')))
		if @cur_feature.status.empty?
				#all the steps passed
				@cur_feature.status = "passed"
		end
		@cur_feature.duration = scenarios['duration']
		@cur_feature.converted_duration = @utils.format_time(scenarios['duration'])
		@cur_feature.scenarios = scenarios['list']
		feature_data['list'].push(@cur_feature)
		feature_data['duration'] = feature_data['duration'] + @cur_feature.duration
	end
	return feature_data
end

#parse_scenarios(scenarios) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/parse_engine/html_parser.rb', line 60

def parse_scenarios(scenarios)
	scenario_data = Hash['duration', 0, 'list', Array.new]
	scenarios.each do |scenario|
		@cur_scenario = CukeModel::CukeScenario.new(scenario.css('span.keyword')[0].text.gsub(":",""),scenario.css('span.val')[0].text)
		steps = parse_steps(scenario.css('ol li div.step_name'))
		if @cur_scenario.status.empty?
			#all the steps passed
			@cur_scenario.status = "passed"
		end
		@cur_scenario.duration = steps['duration']
		@cur_scenario.converted_duration = @utils.format_time(steps['duration'])
		@cur_scenario.steps = steps['list']
		scenario_data['list'].push(@cur_scenario)
		scenario_data['duration'] = scenario_data['duration'] + @cur_scenario.duration
	end
	return scenario_data
end

#parse_steps(steps) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/parse_engine/html_parser.rb', line 78

def parse_steps(steps)
	step_data = Hash['duration', 0, 'list', Array.new]
	steps.each do |step|
		stepErrorMessage = ''
		stepFailureImage = "I NEED TO FIND IMAGE"
		if step.parent.attribute('class').to_s.gsub("step ","") == "failed"
			@cur_scenario.status = "failed"
			@cur_feature.status = "failed"
			@cur_build.status = "failed"
			stepErrorMessage = "I NEED TO FIND ERROR"			
			# #failed steps should have an image available:
			# unless step['embeddings'].nil?
			# 	stepFailureImage = step['embeddings'][0]['data']
			# end					
		end
		step_data['list'].push(CukeModel::CukeStep.new(step.css('span.keyword').text,step.css('span.val').text,0,0,step.parent.attribute('class').to_s.gsub("step ",""),stepErrorMessage,stepFailureImage))
	end
	return step_data
end