summaryrefslogtreecommitdiff
path: root/testautomation/framework/required/includes/wizard_mailmerge.inc
blob: 95f8d6d19a5414cc4bcee4e12568522b7b9f45d8 (plain)
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
'encoding UTF-8  Do not remove or change this line!
'**************************************************************************
' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
'
' Copyright 2000, 2010 Oracle and/or its affiliates.
'
' OpenOffice.org - a multi-platform office productivity suite
'
' This file is part of OpenOffice.org.
'
' OpenOffice.org is free software: you can redistribute it and/or modify
' it under the terms of the GNU Lesser General Public License version 3
' only, as published by the Free Software Foundation.
'
' OpenOffice.org is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU Lesser General Public License version 3 for more details
' (a copy is included in the LICENSE file that accompanied this code).
'
' You should have received a copy of the GNU Lesser General Public License
' version 3 along with OpenOffice.org.  If not, see
' <http://www.openoffice.org/license.html>
' for a copy of the LGPLv3 License.
'
'/************************************************************************
'*
'*  owner : joerg.skottke@oracle.com
'*
'*  short description : Update test for the mailmerge wizard
'*
'\******************************************************************************

private CSV_DATABASE as string

testcase tUpdtWizardMailMerge

    printlog( "Resource test for the mailmerge wizard" )

    dim brc as boolean
    dim irc as integer
    
    qaerrorlog( "#i54524# - MM-Wizard modifies datasource -> CVS merge conflict" )
    
    CSV_DATABASE = hGetWorkPath() & "myDatabase"
    hDeleteFile( CSV_DATABASE )
    hRemoveDatabaseConnections()

    
    hInitSingleDoc()
    
    printlog( "Open the Mailmerge-Wizard" )
    ToolsMailMergeWizard
    
    Kontext "MailMergeWizard"
    brc = hUpdtMMWpage1()
    if ( not brc ) then
        warnlog( "MailMergeWizard is not visible, aborting test" )
        goto endsub
    endif
    
    Kontext "MailMergeWizard"
    hClickButton( NextButton )
    hUpdtMMWPage2()
    
    Kontext "MailMergeWizard"
    hClickButton( NextButton )
    hUpdtMMWpage3()
    
    Kontext "MailMergeWizard"
    hClickButton( NextButton )
    hUpdtMMWPage4()
    
    Kontext "MailMergeWizard"
    hClickButton( NextButton )
    hUpdtMMWPage5()

    Kontext "MailMergeWizard"
    hClickButton( NextButton )
    hUpdtMMWPage6()
    
    Kontext "MailMergeWizard"
    hClickButton( NextButton )
    hUpdtMMWPage7()
    
    Kontext "MailMergeWizard"
    hClickNextButton()
    hUpdtMMWPage8()
    
    printlog( "close the wizard" )
    Kontext "MailMergeWizard"
    hCloseDialog( MailMergeWizard, "cancel" )

    hRemoveDatabaseConnections()
    hCloseDocument()
    hCloseDocument()
    

endcase

'**********************************************************************

function hUpdtMMWpage1() as boolean

    

    const CFN = "hUpdtMMWpage1::"
    
    Kontext "TabMailMergeSourceDocument"
    if ( not TabMailMergeSourceDocument.exists() ) then
        warnlog( CFN & "Page 1 could not be accessed" )
        hUpdtMMWPage1() = false
        exit function
    endif

    Kontext "TabMailMergeSourceDocument"
    if ( BrowseDocument.exists( 1 ) ) then
        if ( BrowseDocument.isEnabled ) then
            BrowseDocument.click()
            
            Kontext "OeffnenDlg"
            if ( OeffnenDlg.exists( 1 ) ) then
                printlog( CFN & "BrowseDocument::File Open Dialog" )
                call dialogtest( OeffnenDlg )
                OeffnenDlg.cancel()
            else
                warnlog( CFN & "BrowseDocument::FileOpen not open" )
            endif
        else
            warnlog( CFN & "BrowseDocument::Button is disabled" )
       endif
    else
        warnlog( CFN & "BrowseDocument::Button does not exist" )
    endif
    
    Kontext "TabMailMergeSourceDocument"
    if ( BrowseTemplate.exists( 2 ) ) then
        if ( BrowseTemplate.isEnabled ) then
            BrowseTemplate.click()
            
            Kontext "Neu"
            if ( Neu.exists( 1 ) ) then
                printlog( CFN & "BrowseTemplate::New Dialog" )
                call dialogtest( Neu )
                Neu.cancel()
            else
                warnlog( CFN & "BrowseTemplate::FileOpen not open" )
            endif
        else
            warnlog( CFN & "BrowseTemplate::Button is disabled" )
        endif
    else
        warnlog( CFN & "BrowseTemplate::Button does not exist" )
    endif
        
    kontext "TabMailMergeSourceDocument"
    if ( CreateANewDocument.exists( 2 ) ) then
        if ( CreateANewDocument.isEnabled ) then
            printlog( CFN & "Check Create new Document" )
            CreateANewDocument.check()
        else
            warnlog( CFN & "CheckBbox is disabled" )
        endif
    else
        warnlog( CFN & "CheckBox does not exist" )
    endif

    hUpdtMMWPage1() = true

end function

'**********************************************************************

function hUpdtMMWpage2()


    const CFN = "hUpdtMMWpage2::"

    Kontext "TabMailMergeDocumentType"
    if ( not TabMailMergeDocumentType.exists( 2 ) ) then
        warnlog( CFN & "Page 2 could not be accessed" )
        exit function
    endif
    
    call dialogtest( TabMailMergeDocumentType )
    
    printlog( CFN & "Select to create a letter" )
    if ( Letter.exists() ) then
        if ( Letter.isEnabled() ) then
            Letter.check()
        else
            warnlog( CFN & "Cannot check Letter-Checkbox" )
        endif
    else
        warnlog( CFN & "Letter Checkbox does not exist" )
    endif
    
end function   

'*******************************************************************************

function hUpdtMMWpage3()


    const CFN = "hUpdtMMWpage3::"
    
    dim cDatabase as string
        cDatabase = gTesttoolpath & "framework\required\input\mailmerge_data.odb"
        cDatabase = convertpath( cDatabase )
    
    Kontext "TabMailMergeAddressBlock"
    if ( not TabMailMergeAddressBlock.exists( 2 ) ) then
        warnlog( CFN & "Page 3 could not be accessed" )
        exit function
    endif
    
    call Dialogtest( TabMailMergeAddressBlock )
    
    Kontext "TabMailMergeAddressBlock"
    hSelectDifferentAddressList( cDatabase )
    
    Kontext "TabMailMergeAddressBlock"
    if ( AddressBlock.exists( 2 ) ) then

        
	if( not AddressBlock.isChecked() ) then
            warnlog( CFN & "AddressBlock Checkbox not checked" )
            AddressBlock.check()
        endif

	hSelectAddressBlock()
    
        hUpdtMailmergeMatchFields()
    else
        warnlog( CFN & "AddressBlock-Checkbox missing, skipping dialogs" )
    endif
    
    
end function

'*******************************************************************************

function hUpdtMMWpage4()


    const CFN = "hUpdtMMWpage4::"
    dim brc as boolean
   
    brc = false

    Kontext "TabMailMergeGreetingsPage"
    if ( not TabMailMergeGreetingsPage.exists( 2 ) ) then
        warnlog( CFN & "Page 4 could not be accessed" )
        exit function
    endif
    
    call dialogtest( TabMailMergeGreetingsPage )
    
    ' the salutation checkbox must be checked, otherwise the buttons are not 
    ' available
    if ( not GreetingPersonalized.isEnabled() ) then
        warnlog( CFN & "CheckBox Salutation not in HID.LST, it should be checked" )
        exit function
    endif
    
    Kontext "TabMailMergeGreetingsPage"
    printlog( CFN & "GreetingButtonFemale" )
    if ( GreetingButtonFemale.isEnabled() ) then
        hNewEditAddressBlock( 3 )
    else
        warnlog( CFN & "GreetingButtonFemale is not enabled" )
    endif

    Kontext "TabMailMergeGreetingsPage"
    printlog( CFN & "GreetingButtonMale" )
    if ( GreetingButtonMale.isEnabled() ) then
        hNewEditAddressBlock( 4 )
    else
        warnlog( CFN & "GreetingButtonMale is not enabled" )
    endif

    Kontext "TabMailMergeGreetingsPage"

end function


'**************************************************************************

function hUpdtMMWpage5()


    const CFN = "hUpdtMMWpage5::"
    
    kontext "TabMailMergeLayoutPage"
    if ( not TabMailMergeLayoutPage.exists( 2 ) ) then
        warnlog( CFN & "Page 5 could not be accessed" )
        exit function
    endif
    
    call DialogTest( TabMailMergeLayoutPage )
    
    printlog( CFN )
    
end function

'**************************************************************************

function hUpdtMMWpage6()


    const CFN = "hUpdtMMWpage6::"
    
    printlog( CFN )
    
    kontext "TabMailMergePrepare"
    if ( not TabMailMergePrepare.exists( 2 ) ) then
        warnlog( CFN & "Page 6 could not be accessed" )
        exit function
    endif
    
    call DialogTest( TabMailMergePrepare )
    
    qaerrorlog( "Skipping preview button" )
    
end function

'**************************************************************************

function hUpdtMMWpage7()

    
    const CFN = "hUpdtMMWpage7::"
    
    printlog( CFN )    
    
    kontext "TabMailMergePersonalize"
    hWaitForObject( EditIndividualButton, 8000 )
    'if ( not TabMailMergePersonalize.exists( 2 ) ) then
    '    warnlog( CFN & "Page 7 could not be accessed" )
    '    exit function
    'endif
    
    call DialogTest( TabMailMergePersonalize )
    
    qaerrorlog( "Skipping Preview-Button" )
    
end function

'**************************************************************************

function hUpdtMMWpage8()


    const CFN = "hUpdtMMWpage8::"
    
    kontext "TabMailMergeOutputPage"
    if ( not TabMailMergeOutputPage.exists( 2 ) ) then
        warnlog( CFN & "Page 8 could not be accessed" )
        exit function
    endif
    
    printlog( CFN )
    
    call DialogTest( TabMailMergeOutputPage )
    
    kontext "TabMailMergeOutputPage"
    hSaveStartingDocument()
    
    kontext "TabMailMergeOutputPage"
    hSaveMailMergeDocument()
    
    kontext "TabMailMergeOutputPage"
    hPrintMailMergeDocument()
    
    kontext "TabMailMergeOutputPage"
    hSendMailMergeDocument()
    
end function

'*******************************************************************************

function hSelectDifferentAddressList( cDatabase as string ) as boolean


    const CFN = "hSelectDifferentAddressList::"
    
    dim brc as boolean
        
    dim iAddressList as integer
    dim cAddressList as string
        
    Kontext "TabMailMergeAddressBlock"
    SelectAddressListButton.click()

    Kontext "SelectAddressList"
    if ( SelectAddressList.exists( 2 ) ) then
        printlog( CFN & "Select Address List Dialog" )
        call dialogtest( SelectAddressList )
    else
        warnlog( CFN & "SelectAddressList dialog is not open" )
        hSelectDifferentAddressList() = false
        exit function
    endif
	    
    Kontext "SelectAddressList"
    brc = hAddDatabase( cDatabase ) 

    
    Kontext "SelectAddressList"
    if ( SelectAddressList.exists( 2 ) ) then
        if ( AddressList.getItemCount() < 2 ) then
            brc = hAddDatabase( cDatabase )
        endif
        
        Kontext "SelectAddressList"
        brc = hEditCreateAddressList( 1 )
	
        Kontext "SelectAddressList" 
        brc = hFilterDialog()

        Kontext "SelectAddressList"
        brc = hEditCreateAddressList( 2 )
	
        Kontext "SelectAddressList"
        for iAddressList = 1 to AddressList.getItemCount()
        
            AddressList.select( iAddressList )
            cAddressList = AddressList.getText()
            printlog( CFN & "Current address list: " & cAddressList )
            
            try
                SelectAddressList.ok()
                brc = true
                exit for
            catch
                qaerrorlog( CFN & "Ok-Button disabled for <" & cAddressList & ">" )
                brc = false
            endcatch
            
        next iAddressList
        
        if ( not brc ) then
            warnlog( "#i84250# OK button not enabled for any address list." )
        endif        
    else
        warnlog( CFN & "Select Address List dialog is not open" )
        brc = false
    endif
    

    
    Kontext "TabMailMergeAddressBlock"
    hSelectDifferentAddressList() = brc

end function

'*******************************************************************************

function hWaitForBackToWizardFloat() as boolean


    const CFN = "hWaitForBackToWizardFloat::"
    dim brc as boolean
    
    printlog( CFN & "Enter" )
           
    Kontext "MailMergeFloat"
    if ( MailMergeFloat.exists( 20 ) ) then
        printlog( CFN & "Back to document float is open" )
        ReturnToMailMergeWizard.click()
        
        Kontext "MailMergeWizard"
        if ( MailMergeWizard.exists( 5 ) ) then
            printlog( CFN & "Successfully returned to Mail Merge Wizard" )
            brc = true
        else
            warnlog( CFN & "Could not return to Mail Merge Wizard" )
            brc = false
        endif
    else
        warnlog( CFN & "Unable to access Mail Merge Float" )
        brc = false
    endif
    
    printlog( CFN & "Exit with result = " & brc )
    hWaitForBackToWizardFloat() = brc
        
end function

'*******************************************************************************

function hAddDatabase( cDatabase as string ) as boolean

    
    const CFN = "hAddDatabase::"
    
    dim brc as boolean
        brc = false
        
    dim iWait as integer
    
    add.click()

    Kontext "OeffnenDlg"
    if ( OeffnenDlg.exists( 2 ) ) then
        printlog( CFN & "File Open Dialog" )
        DateiName.setText( cDatabase )
        Oeffnen.click()
        brc = true
    else
        warnlog( CFN & "FileOpen is missing" )
    endif
	
    ' When a new addressdatabase is imported it might take some time before we
    ' get back to the SelectAddressList dialog
    hWaitForSelectAddressListDialog()
    
    hAddDatabase() = brc
    
end function

'******************************************************************************

function hEditCreateAddressList( iMode as integer ) as boolean

    const CFN = "hEditCreateAddressList::"

    dim brc as boolean
        brc = false
        
    dim iWait as integer
        
    Kontext "SelectAddressList"
    select case iMode
    case 1 : create.click()
    case 2 : edit.click()
    end select

    Kontext "NewAddressList"
    if ( NewAddressList.exists( 2 ) ) then
        printlog( CFN & "New/Edit Address List Dialog is open" )
        call dialogtest( NewAddressList )
        brc = true
    else
        warnlog( CFN & "New/EditAddressList does not exist" )
    endif

    if ( not brc ) then
        hEditCreateAddressList() = brc
        exit function
    endif
        

    ' Try to use the Find-dialog, do not evaluate the returncode,
    ' the test should continue even if the dialog does not come up.
    brc = hFindDialog()
    
    ' Try to use the Customize-dialog, don't evaluate the rc either
    brc = hCustomizeAddressList()
    
    ' Return to "NewAddressList" 
    Kontext "NewAddressList"
    NewAddressList.ok()
    
    ' only save when a new list has been created, editing saves automatically
    if ( iMode = 1 ) then
        hSaveNewAddressList()
    endif
    
    hWaitForSelectAddressListDialog()
    
    Kontext "SelectAddressList"
    hEditCreateAddressList() = brc
	
end function

'*******************************************************************************

function hFindDialog() as boolean


    const CFN = "hFindDialog::"

    dim brc as boolean
        brc = false
        
    printlog( CFN )

    Kontext "NewAddressList"
    find.click()

    kontext "FindEntry"
    if ( FindEntry.exists( 2 ) ) then
        call dialogtest( FindEntry )
        printlog( CFN & "Find Entry Dialog is open" )
        FindEntry.cancel()
        brc = true
    else
        warnlog( CFN & "Dialog is not open" )
    endif
	
    Kontext "NewAddressList"
    hFindDialog() = brc
	
end function

'******************************************************************************

function hCustomizeAddressList() as boolean



    const CFN = "hCustomizeAddressList::"

    dim brc as boolean
        brc = false
        
    printlog( CFN )

    Kontext "NewAddressList"
    if ( Customize.exists( 2 ) ) then
        if ( Customize.isEnabled() ) then
            Customize.click()

            kontext "CustomizeAddressList"
            if ( CustomizeAddressList.exists( 2 ) ) then
                printlog( CFN & "Customize Address List Dialog" )
                call dialogtest( CustomizeAddressList )
		
                kontext "CustomizeAddressList"
                hAddRenameElement( "NewElement" , 1 ) 
                
                kontext "CustomizeAddressList"
                hAddRenameElement( "Renamed" , 2 )
                
                kontext "CustomizeAddressList"
                printlog( CFN & "Delete" )
                delete.click()
                
                kontext "CustomizeAddressList"
                CustomizeAddressList.cancel()
                brc = true
            else
                warnlog( CFN & "Dialog is not open" )
            endif
        else
            warnlog( CFN & "Button is not enabled" )
        endif
    else
        warnlog( CFN & "Button does not exist" )
    endif
        
    Kontext "NewAddressList"
    hCustomizeAddressList() = brc
	
end function

'************************************************************************************

function hAddRenameElement( cElementName as string , iMode as integer ) as boolean

    const CFN = "hAddRenameElement::"
    dim brc as boolean
        brc = false

    select case iMode
    case 1 : Add.click()
    case 2 : Rename.click()
    end select
    
    Kontext "RenameElement"
    if ( RenameElement.exists( 2 ) ) then
        printlog( CFN & "Add/Rename Element Dialog" )
        call Dialogtest( RenameElement )
        
        FieldTitle.setText( cElementName )
        RenameElement.ok()
        brc = true
    else
        warnlog( CFN & "Dialog is not open" )
    endif
       	
    hAddRenameElement() = brc
	
end function

'*******************************************************************************

function hFilterDialog() as integer


    const CFN = "hFilterDialog::"
    
    dim brc as boolean
        brc = false
        
    Kontext "SelectAddressList"
    if ( Filter.exists( 2 ) ) then
        if ( Filter.isEnabled() ) then
            Filter.click()
            
            kontext "FilterDialog"
            if ( FilterDialog.exists( 2 ) ) then
                printlog( CFN & "Filter Dialog" )
                call Dialogtest( FilterDialog )
                
                FilterDialog.cancel()
                brc = true
            else
                warnlog( "#i54150 " & CFN & "Filter dialog is not open" )
            endif
        else
            warnlog( CFN & "Filter Button is not enabled" )
        endif
    else
        warnlog( CFN & "Filter Button is missing" )
    endif
    
    hWaitForSelectAddressListDialog()
    hFilterDialog() = brc
  
end function

'****************************************************************************

function hSelectAddressBlock() as boolean

    const CFN = "hSelectAddressBlock::"
    
    dim brc as boolean
        brc = false
        
    printlog( CFN  & "More..." )
        
    Kontext "TabMailMergeAddressBlock"
    if ( more.exists( 2 ) ) then
    
        ' A dynamic delay (function borrowed from toolbar_tools.inc)
        hWaitForObject( more , 3000 )
        
        if ( more.isEnabled() ) then
            more.click()
            
            Kontext "SelectAddressBlock"
            if ( SelectAddressBlock.exists( 2 ) ) then
                printlog( CFN & "SelectAddressBlock dialog is open" )
                call DialogTest( SelectAddressBlock )
                
                Kontext "SelectAddressBlock"
                hNewEditAddressBlock( 1 )
                
                Kontext "SelectAddressBlock"
                hNewEditAddressBlock( 2 )
                
                Kontext "SelectAddressBlock"
                SelectAddressBlock.ok()
                brc = true
            else
                warnlog( CFN & "Dialog is not open" )
            endif        
        else
            warnlog( CFN & "Button is disabled" )
        endif
    else
        warnlog( CFN & "Button does not exist" )
    endif
        
    hSelectAddressBlock() = brc
    
end function

'*******************************************************************************

function hNewEditAddressBlock( iMode as integer ) as boolean

    const CFN = "hNewEditAddressBlock::"

    select case iMode
    case 1 : NewBtn.click()
    case 2 : Customize.click()
    case 3 : GreetingButtonFemale.click()
    case 4 : GreetingButtonMale.click()
    end select
    
    Kontext "NewAddressBlock"
    if ( NewAddressBlock.exists( 2 ) ) then
        printlog( cfn & "Dialog is open" )
        NewAddressBlock.cancel()
        hNewEditAddressBlock() = true
    else
        warnlog( cfn & "Dialog is not open" )
        hNewEditAddressBlock() = false
    endif
        
end function

'*******************************************************************************

function hSaveStartingDocument() as boolean

    const CFN = "hSaveStartingDocument::"
    
    dim brc as boolean
        brc = false

    if ( RBSaveStartDoc.exists( 2 ) ) then
         if ( RBSaveStartDoc.isEnabled ) then
             RBSaveStartDoc.check()
             brc = true
         else
             warnlog( CFN & "Cannot set radiobutton" )
         endif
    else
        warnlog( CFN & "Radiobutton is missing" )
    endif
    
    ' save file
    if ( PBSaveStartDoc.exists( 2 ) ) then
        if ( PBSaveStartDoc.isEnabled ) then
            PBSaveStartDoc.click()
             
            Kontext "SpeichernDlg"
            if ( SpeichernDlg.exists( 2 ) ) then
                printlog( CFN & "Save As Dialog is open" )
                SpeichernDlg.cancel()
                brc = true
            else
                warnlog( CFN & "FileSave dialog is missing" )
            endif
        else
            warnlog( CFN & "SaveStartDoc is disabled" )
        endif
    else
        warnlog( CFN & "SaveStartDoc is missing" )
    endif            
    
    hSaveStartingDocument() = brc
    
end function

'******************************************************************************* 

function hSaveMailMergeDocument() as boolean

    const CFN = "hSaveMailMergeDocument::"
    
    dim brc as boolean
        brc = false

    if ( RBSaveMergedDoc.exists( 2 ) ) then
         if ( RBSaveMergedDoc.isEnabled() ) then
             RBSaveMergedDoc.check()
             brc = true
         else
             warnlog( CFN & "Cannot set radiobutton" )
         endif
    else
        warnlog( CFN & "Radiobutton is missing" )
    endif
    
    ' save file
    if ( PBSaveNow.exists( 2 ) ) then
        if ( PBSaveNow.isEnabled() ) then
            PBSaveNow.click()
             
            Kontext "SpeichernDlg"
            if ( SpeichernDlg.exists( 2 ) ) then
                printlog( CFN & "Save As Dialog is open" )
                SpeichernDlg.cancel()
                brc = true
            else
                warnlog( CFN & "FileSave dialog is missing" )
            endif
        else
            warnlog( CFN & "Save Now is disabled" )
        endif
    else
        warnlog( CFN & "Save Now is missing" )
    endif            
    
    hSaveMailMergeDocument() = brc
    
end function

'******************************************************************************* 

function hPrintMailMergeDocument() as boolean

    const CFN = "hPrintMailMergeDocument::"
    
    dim brc as boolean
        brc = false

    if ( RBPrintMerged.exists( 2 ) ) then
         if ( RBPrintMerged.isEnabled() ) then
             RBPrintMerged.check()
             brc = true
         else
             warnlog( CFN & "Cannot set radiobutton" )
         endif
    else
        warnlog( CFN & "Radiobutton is missing" )
    endif

    if ( instr( gtSYSName , "win" ) > 0 ) then
        printlog( CFN & "Skipping printer dialog on windows" )
        hPrintMailMergeDocument() = true
        exit function
    endif
    
    if ( lcase( gPlatform ) = "osx" ) then
        qaerrorlog( "#i81545# No printer settings on MacOS X" )
        hPrintMailMergeDocument() = true
        exit function
    endif
    
    ' printer settings
    if ( PBPrinterSettings.exists( 2 ) ) then
        if ( PBPrinterSettings.isEnabled() ) then
            PBPrinterSettings.click()
             
            Kontext "TabSPAPaper"
            if ( TabSPAPaper.exists() ) then
                printlog( CFN & "Printer Settings Dialog" )
                TabSPAPaper.OK
                brc = true
            else
                warnlog( "#i89114# Printer Settings dialog is missing" )
            endif
        else
            warnlog( CFN & "Printer Settings is disabled" )
        endif
    else
        warnlog( CFN & "Printer Settings is missing" )
    endif   
    
    hPrintMailMergeDocument() = brc
    
end function

'******************************************************************************* 

function hSendMailMergeDocument() as boolean

    const CFN = "hSendMailMergeDocument::"
    
    dim brc as boolean
        brc = false

    if ( RBSendAsMail.exists( 2 ) ) then
         if ( RBSendAsMail.isEnabled() ) then
             RBSendAsMail.check()
         else
             warnlog( CFN & "Cannot set radiobutton" )
         endif
    else
        warnlog( CFN & "Radiobutton is missing" )
    endif
    
    ' send copy to
    if ( PBCopyTo.exists( 2 ) ) then
        if ( PBCopyTo.isEnabled() ) then
            PBCopyTo.click()
             
            Kontext "CopyToDialog"
            if ( CopyToDialog.exists( 2 ) ) then
                printlog( CFN & "CopyToDialog is open" )
                call DialogTest( CopyToDialog )
                CopyToDialog.OK()
            else
                warnlog( CFN & "CopyToDialog dialog is missing" )
            endif
        else
            warnlog( CFN & "PBCopyTo is disabled" )
        endif
    else
        warnlog( CFN & "PBCopyTo is missing" )
    endif   
    
    kontext "TabMailMergeOutputPage"
    if ( PBSendDocuments.exists( 2 ) ) then
        if ( PBSendDocuments.isEnabled() ) then
            PBSendDocuments.click()
            Kontext "Active"
            if ( active.exists( 2 ) ) then
                printlog( CFN & "Dialog asking for EMail-account is open" )
                call Dialogtest( active )
                active.yes()
                
                kontext "TabMailMergeEmail"
                hMailMergeEmailDialog()
            else
                warnlog( CFN & "Dialog asking for EMail-account is missing" )
            endif
        else
            warnlog( CFN & "Send documents Button is disabled" )
        endif
    else
        warnlog( CFN & "Send Documents Button is missing" )
    endif
    
    hSendMailMergeDocument() = brc
    
end function

'******************************************************************************* 

function hMailMergeEmailDialog() as boolean

    const CFN = "hMailMergeEmailDialog::"
    dim brc as boolean
        brc = false
    
    if ( TabMailMergeEmail.exists( 2 ) ) then
        printlog( CFN & "EMail Account Dialog is open" )
        brc = true
    else
        warnlog( CFN & "EMail Account Dialog is not open" )
        exit function
    endif
    
    ' server authentication
    if ( ServerAuthentication.exists( 2 ) ) then
        if ( ServerAuthentication.isEnabled() ) then
            ServerAuthentication.click()
            
            Kontext "ServerAuthentication"
            if ( ServerAuthentication.exists( 2 ) ) then
                printlog( CFN & "Server Authentication dialog is open" )
                call DialogTest( ServerAuthentication )
                ServerAuthentication.cancel()
            else
                warnlog( CFN & "ServerAuthentication is not open" )
            endif
        else
            warnlog( CFN & "ServerAuthentication-Button is not enabled" )
        endif
    else
        warnlog( CFN & "ServerAuthentication-Button does not exist" )
        brc = false
    endif
    
    ' Test settings
    kontext "TabMailMergeEmail"   
    if ( TestSettings.exists( 2 ) ) then
        if ( TestSettings.isEnabled() ) then
            TestSettings.click()
            
            kontext "TestAccountSettings"
            if ( TestAccountSettings.exists( 2 ) ) then
                printlog( CFN & "Test Account Settings Dialog is open" )
                call DialogTest( TestAccountSettings )
                TestAccountSettings.cancel()
            else
                warnlog( CFN & "Test Account Settings Dialog is not open" )
            endif
        else
            warnlog( CFN & "Test Settings-button is disabled" )
        endif
    else
        warnlog( CFN & "Test Settings-button is missing" )
    endif
    
    kontext "TabMailMergeEmail"
    TabMailMergeEmail.cancel()
    
    hMailMergeEmailDialog() = brc
    
end function

'*******************************************************************************

function hWaitForSelectAddressListDialog() as boolean

    Kontext "SelectAddressList"
    if ( SelectAddressList.exists( 5 ) ) then
        hWaitForSelectAddressListDialog() = true
    else
        hWaitForSelectAddressListDialog() = false
    endif
    
    
end function

'*******************************************************************************

function hSaveNewAddressList()

    const CFN = "hSaveNewAddressList::"

    Kontext "SpeichernDlg"
    if ( SpeichernDlg.exists( 2 ) ) then
    
        DateiName.setText( CSV_DATABASE )
        Speichern.click()
        
        kontext "active"
        if ( active.exists( 2 ) ) then
            warnlog( active.getText() ) 
            active.yes()
        endif
        
        printlog( CFN & "File saved" )
    else
        warnlog( CFN & "FileSave did not come up" )
    endif
    
end function

'*******************************************************************************

function hRemoveDatabaseConnections() as integer

    const CFN = "hRemoveDatabaseConnections()::"
    const DEFAULT_DATABASE = "Bibliography"
    
    dim iConnectionCount as integer
    dim iCurrentConnection as integer
    dim cConnectionName as string
    dim bOptionsOpen as boolean : bOptionsOpen = true
    
    kontext "OptionenDlg"
    if ( not OptionenDlg.exists() ) then
        bOptionsOpen = false
        ToolsOptions
    endif
    
    hToolsOptions( "DataSources", "Databases" )
    
    kontext "TabRegisteredDatabase"
    iConnectionCount = RegisteredDatabases.getItemCount()
    
    for iCurrentConnection = iConnectionCount to 1 step -1
    
        kontext "TabRegisteredDatabase"
        if ( TabRegisteredDatabase.exists( 2 ) ) then
        
            RegisteredDatabases.select( iCurrentConnection )
            cConnectionName = RegisteredDatabases.getSelText()
            printlog( CFN & "Current database: " & cConnectionName )
        
            if ( cConnectionName <> DEFAULT_DATABASE ) then
                DeleteBtn.click()
                kontext "active"
                if ( active.exists( 2 ) ) then
                    active.yes()
                else
                    warnlog( CFN & "Confirmation dialog for delete is missing" )
                endif
            else
                printlog( CFN & "Not deleting default database connection" )
            endif
        else
            warnlog( CFN & "Failed to set context to Registered Databases Tab" )
        endif
        
    next iCurrentConnection
    
    if ( not bOptionsOpen ) then
        kontext "OptionenDlg"
        OptionenDlg.ok()
    endif
    
    hRemoveDatabaseConnections() = iConnectionCount - 1
    
end function

'*******************************************************************************

function hUpdtMailmergeMatchFields() as boolean

    
    const CFN = "hUpdtMailmergeMatchFields::"
    dim brc as boolean
    
    printlog( CFN & "Accessing Match Fields Dialog" )
    Kontext "TabMailMergeAddressBlock"
    MatchFieldsButton.click()
    
    kontext "MatchFields"
    if ( not MatchFields.exists( 2 ) ) then
        warnlog( CFN & "Unable to access Match Fields dialog" )
        brc = false
    else
    
        Title.select( 2 )
        FirstName.select( 3 )
        LastName.select( 4 )
        Company.select( 5 )
        Address1.select( 6 )
        Address2.select( 7 )
        City.select( 8 )
        State.select( 2 )
        ZIP.select( 3 )
        Country.select( 4 )
        PhonePrivate.select( 1 )
        PhoneBusiness.select( 2 )
        EMail.select( 5 )
        Gender.select( 4 )
        
        MatchFields.OK()
        printlog( CFN & "Leaving Match Fields Dialog" )
        brc = true
        
    endif
    
    hUpdtMailmergeMatchFields() = brc
        
end function