     l_expected_list ut3.ut_varchar2_list;
     l_expected clob;
   begin
-    l_actual := 
-      g_actual_xml_report.extract(
-        '/report/runEvents/endSuiteEvent[@id="realtime_reporting.check_realtime_reporting3"]/serverOutput/text()'
-      ).getclobval();
+    select t.column_value.extract('//event/suite/serverOutput/text()').getstringval()
+      into l_actual
+      from table(g_xml_reports) t
+     where t.column_value.extract('/event[@type="post-suite"]/suite/@id').getstringval() 
+           = 'realtime_reporting.check_realtime_reporting3';
     ut3.ut_utils.append_to_list(l_expected_list, '<![CDATA[Now, a no_data_found exception is raised');
     ut3.ut_utils.append_to_list(l_expected_list, 'dbms_output and error stack is reported for this suite.');
     ut3.ut_utils.append_to_list(l_expected_list, 'A runtime error in afterall is counted as a warning.');

create or replace package body test_realtime_reporter as

  g_actual_xml_report xmltype;

  procedure create_test_suites_and_run is
    pragma autonomous_transaction;

    end;]';
    
    <<run_report_and_cache_result>>
    declare 
      l_clob clob;
    begin
      g_xml_reports.delete;
      <<report_lines>>
      for r in (
        with
          base as (
            select sum(case when column_value like '<?xml%' then 1 else 0 end) over(order by rownum) group_no, 
                   rownum as rn,
                   column_value as line
              from table(ut3.ut.run('ut3_tester:realtime_reporting', ut3.ut_realtime_reporter()))
          )
        select group_no,
               lead(group_no, 1, -1) over (order by rn) as next_group_no,
               rn,
               line
          from base
         order by rn
      ) loop
        ut3.ut_utils.append_to_clob(l_clob, r.line);
        ut3.ut_utils.append_to_clob(l_clob, chr(10));
        if r.group_no != r.next_group_no then
           g_xml_reports.extend;
           g_xml_reports(g_xml_reports.count) := xmltype(l_clob);
           l_clob := null;
        end if;
      end loop report_lines;
    end run_report_and_cache_result;
  end create_test_suites_and_run;
  
  procedure xml_report_structure is
    l_actual   sys_refcursor;
    l_expected sys_refcursor;
  begin
    open l_actual for
      select t.column_value.extract('/event/@type').getstringval()                     as event_type, 
             t.column_value.extract('/event/suite/@id|/event/test/@id').getstringval() as item_id
        from table(g_xml_reports) t;
    open l_expected for
      select 'pre-run'    as event_type, null                                                                     as item_id from dual union all
      select 'pre-suite'  as event_type, 'realtime_reporting'                                                     as item_id from dual union all
      select 'pre-suite'  as event_type, 'realtime_reporting.check_realtime_reporting3'                           as item_id from dual union all
      select 'pre-test'   as event_type, 'realtime_reporting.check_realtime_reporting3.test_6_with_runtime_error' as item_id from dual union all
      select 'post-test'  as event_type, 'realtime_reporting.check_realtime_reporting3.test_6_with_runtime_error' as item_id from dual union all
      select 'pre-test'   as event_type, 'realtime_reporting.check_realtime_reporting3.test_7_with_serveroutput'  as item_id from dual union all
      select 'post-test'  as event_type, 'realtime_reporting.check_realtime_reporting3.test_7_with_serveroutput'  as item_id from dual union all
      select 'post-suite' as event_type, 'realtime_reporting.check_realtime_reporting3'                           as item_id from dual union all
      select 'pre-suite'  as event_type, 'realtime_reporting.check_realtime_reporting2'                           as item_id from dual union all
      select 'pre-test'   as event_type, 'realtime_reporting.check_realtime_reporting2.test_3_ok'                 as item_id from dual union all
      select 'post-test'  as event_type, 'realtime_reporting.check_realtime_reporting2.test_3_ok'                 as item_id from dual union all
      select 'pre-test'   as event_type, 'realtime_reporting.check_realtime_reporting2.test_4_nok'                as item_id from dual union all
      select 'post-test'  as event_type, 'realtime_reporting.check_realtime_reporting2.test_4_nok'                as item_id from dual union all
      select 'pre-test'   as event_type, 'realtime_reporting.check_realtime_reporting2.test_5'                    as item_id from dual union all
      select 'post-test'  as event_type, 'realtime_reporting.check_realtime_reporting2.test_5'                    as item_id from dual union all
      select 'post-suite' as event_type, 'realtime_reporting.check_realtime_reporting2'                           as item_id from dual union all
      select 'pre-suite'  as event_type, 'realtime_reporting.check_realtime_reporting1'                           as item_id from dual union all
      select 'pre-suite'  as event_type, 'realtime_reporting.check_realtime_reporting1.test context'              as item_id from dual union all
      select 'pre-test'   as event_type, 'realtime_reporting.check_realtime_reporting1.test context.test_1_ok'    as item_id from dual union all
      select 'post-test'  as event_type, 'realtime_reporting.check_realtime_reporting1.test context.test_1_ok'    as item_id from dual union all
      select 'pre-test'   as event_type, 'realtime_reporting.check_realtime_reporting1.test context.test_2_nok'   as item_id from dual union all
      select 'post-test'  as event_type, 'realtime_reporting.check_realtime_reporting1.test context.test_2_nok'   as item_id from dual union all
      select 'post-suite' as event_type, 'realtime_reporting.check_realtime_reporting1.test context'              as item_id from dual union all
      select 'post-suite' as event_type, 'realtime_reporting.check_realtime_reporting1'                           as item_id from dual union all
      select 'post-suite' as event_type, 'realtime_reporting'                                                     as item_id from dual union all
      select 'post-run'   as event_type, null                                                                     as item_id from dual;
    ut.expect(l_actual).to_equal(l_expected);
  end xml_report_structure;
  
  procedure total_number_of_tests is
    l_actual   integer;
    l_expected integer := 7; 
  begin
    select t.column_value.extract('/event/totalNumberOfTests/text()').getnumberval()
      into l_actual
      from table(g_xml_reports) t
     where t.column_value.extract('/event/@type').getstringval() = 'pre-run';
  end total_number_of_tests; 
  
  procedure escaped_characters is
    l_actual   varchar2(32767);
    l_expected varchar2(20) := 'suite &lt;A&gt;'; 
  begin
    select t.column_value.extract(
             '//suite[@id="realtime_reporting.check_realtime_reporting1"]/description/text()'
           ).getstringval()
      into l_actual
      from table(g_xml_reports) t
     where t.column_value.extract('/event/@type').getstringval() = 'pre-run';
    ut.expect(l_actual).to_equal(l_expected);
  end escaped_characters;
  
  procedure pre_test_nodes is
    l_actual   sys_refcursor;
    l_expected sys_refcursor;
  begin
    open l_actual for
       select t.column_value.extract('//test/testNumber/text()')
                .getnumberval() as test_number,
              t.column_value.extract('//test/totalNumberOfTests/text()')
                .getnumberval() as total_number_of_tests
         from table(g_xml_reports) t
        where t.column_value.extract('/event/@type').getstringval() = 'pre-test'
          and t.column_value.extract('//test/@id').getstringval() is not null;
    open l_expected for
       select level as test_number, 
              7     as total_number_of_tests 
         from dual
      connect by level <= 7;
    ut.expect(l_actual).to_equal(l_expected).unordered;
  end pre_test_nodes;
  
  procedure post_test_nodes is
    l_actual   sys_refcursor;
    l_expected sys_refcursor;
  begin
    open l_actual for
       select t.column_value.extract('//test/testNumber/text()')
                .getnumberval() as test_number,
              t.column_value.extract('//test/totalNumberOfTests/text()')
                .getnumberval() as total_number_of_tests
         from table(g_xml_reports) t
        where t.column_value.extract('/event/@type').getstringval() = 'post-test'
          and t.column_value.extract('//test/@id').getstringval() is not null
          and t.column_value.extract('//test/startTime/text()').getstringval() is not null
          and t.column_value.extract('//test/endTime/text()').getstringval() is not null
          and t.column_value.extract('//test/executionTime/text()').getnumberval() is not null
          and t.column_value.extract('//test/counter/disabled/text()').getnumberval() is not null
          and t.column_value.extract('//test/counter/success/text()').getnumberval() is not null
          and t.column_value.extract('//test/counter/failure/text()').getnumberval() is not null
          and t.column_value.extract('//test/counter/error/text()').getnumberval() is not null
          and t.column_value.extract('//test/counter/warning/text()').getnumberval() is not null;
    open l_expected for
       select level as test_number, 
              7     as total_number_of_tests 
         from dual
      connect by level <= 7;
    ut.expect(l_actual).to_equal(l_expected).unordered;
  end post_test_nodes;

  procedure single_failed_message is
    l_actual   varchar2(32767);
    l_expected varchar2(80) := '<![CDATA[Actual: 1 (number) was expected to equal: 2 (number) ]]>';
  begin
    select t.column_value.extract(
             '/event/test/failedExpectations/expectation[1]/message/text()'
           ).getstringval()
      into l_actual
      from table(g_xml_reports) t
     where t.column_value.extract('/event[@type="post-test"]/test/@id').getstringval() 
           = 'realtime_reporting.check_realtime_reporting1.test context.test_2_nok';
    ut.expect(l_actual).to_equal(l_expected);
  end single_failed_message;
  
