Class: TestCompleteWorld

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

Instance Method Summary collapse

Constructor Details

#initialize(test_complete_path, project_name, options = {}) ⇒ TestCompleteWorld

Returns a new instance of TestCompleteWorld.



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
# File 'lib/cucumber_test_complete.rb', line 6

def initialize(test_complete_path, project_name, options = {})
  defaults = {
    application: 'TestComplete'
  }

  options = defaults.merge(options)

  @project_name = project_name
	
  application_to_use = "#{options[:application]}.#{options[:application]}Application"
  
  begin
    puts "Connecting to #{options[:application]}"
    @test_execute = WIN32OLE.connect(application_to_use)
    @test_execute.Integration
  rescue
    puts "#{options[:application]} does not appear to be running - starting instead"
    @test_execute = WIN32OLE.new(application_to_use)
  end
  
  # dumb windows thing
  test_complete_path = test_complete_path.gsub!('/', '\\')

  puts "Connected to #{options[:application]} - making visible and opening project #{test_complete_path}"

  
	@test_execute.Visible = true unless options[:application] == "TestExecute"
  
	@test_execute.Integration.OpenProjectSuite(test_complete_path)

  @integration = @test_execute.Integration
end

Instance Method Details

#call_script(name, script_unit, *args) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/cucumber_test_complete.rb', line 75

def call_script(name, script_unit, *args)
  unless args.empty?
    run_routine_ex(name,script_unit, args)
  else
    run_routine(name,script_unit)
  end
end

#run_routine(name, script_unit) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/cucumber_test_complete.rb', line 39

def run_routine(name,script_unit)
  puts "Running #{name} in project #{@project_name}"
  begin
    run_with_delays do
      @integration.RunRoutine(@project_name, script_unit, name)
    end
  rescue
    raise "Call to #{name} failed"
  end
end

#run_routine_ex(name, script_unit, args = []) ⇒ Object



64
65
66
67
68
69
70
71
72
73
# File 'lib/cucumber_test_complete.rb', line 64

def run_routine_ex(name, script_unit, args=[])
  puts "Running #{name} with arguments #{args} in project #{@project_name}"
  begin
    run_with_delays do
      @integration.RunRoutineEx(@project_name, script_unit, name, args)
    end
  rescue
    raise "Call to #{name} with arguments #{args} failed"
  end
end

#run_with_delaysObject



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/cucumber_test_complete.rb', line 50

def run_with_delays
  while @integration.IsRunning
    sleep 0.1
  end

  yield

  while @integration.IsRunning
    sleep 0.1
  end

  @test_execute.Integration.GetLastResultDescription.Status.should_not eq 2
end