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
|
# --
# Copyright (C) 2001-2021 OTRS AG, https://otrs.com/
# Copyright (C) 2021 Znuny GmbH, https://znuny.org/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
# --
use strict;
use warnings;
use utf8;
use vars (qw($Self));
my $Selenium = $Kernel::OM->Get('Kernel::System::UnitTest::Selenium');
$Selenium->RunTest(
sub {
my $HelperObject = $Kernel::OM->Get('Kernel::System::UnitTest::Helper');
# Hide Fred.
$HelperObject->ConfigSettingChange(
Valid => 1,
Key => 'Fred::Active',
Value => 0
);
# Enable Responsible feature.
$HelperObject->ConfigSettingChange(
Valid => 1,
Key => "Ticket::Responsible",
Value => 1
);
# Enable Drafts in AgentTicketActionCommon screens.
for my $SysConfig (qw(Priority Owner Note FreeText Pending Close Responsible)) {
$HelperObject->ConfigSettingChange(
Valid => 1,
Key => "Ticket::Frontend::AgentTicket${SysConfig}###FormDraft",
Value => 1
);
}
# Enable NoteMandatory for AgentTicketOwner and AgentTicketResponsible screen.
$HelperObject->ConfigSettingChange(
Valid => 1,
Key => "Ticket::Frontend::AgentTicketOwner###NoteMandatory",
Value => 1
);
$HelperObject->ConfigSettingChange(
Valid => 1,
Key => "Ticket::Frontend::AgentTicketResponsible###NoteMandatory",
Value => 1
);
my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
# Create test ticket.
my $TicketID = $TicketObject->TicketCreate(
Title => 'Selenium Test Ticket',
Queue => 'Raw',
Lock => 'unlock',
Priority => '3 normal',
State => 'new',
CustomerID => 'SeleniumCustomer',
CustomerUser => 'SeleniumCustomer@localhost.com',
OwnerID => 1,
UserID => 1,
);
$Self->True(
$TicketID,
"Ticket ID $TicketID is created",
);
# Get RandomID.
my $RandomID = $HelperObject->GetRandomID();
# Create test user and login.
my $TestUserLogin = $HelperObject->TestUserCreate(
Groups => [ 'admin', 'users' ],
) || die "Did not get test user";
$Selenium->Login(
Type => 'Agent',
User => $TestUserLogin,
Password => $TestUserLogin,
);
my $ConfigObject = $Kernel::OM->Get('Kernel::Config');
my $ScriptAlias = $ConfigObject->Get('ScriptAlias');
# Navigate to zoom view of created test ticket.
$Selenium->VerifiedGet("${ScriptAlias}index.pl?Action=AgentTicketZoom;TicketID=$TicketID");
# Create test case matrix.
my @Tests = (
{
Module => 'Priority',
Fields => {
Priority => {
ID => 'NewPriorityID',
Type => 'DropDown',
Value => 1,
Update => 2,
},
Subject => {
ID => 'Subject',
Type => 'Input',
Value => 'Selenium Priority Subject',
Update => 'Selenium Priority Subject - Update'
},
Body => {
ID => 'RichText',
Type => 'RichText',
Value => 'Selenium Priority Body',
Update => 'Selenium Priority Body - Update',
},
Attachments => {
ID => 'FileUpload',
Type => 'Attachment',
},
},
},
{
Module => 'Note',
Fields => {
Subject => {
ID => 'Subject',
Type => 'Input',
Value => 'Selenium Note Subject',
Update => 'Selenium Note Subject - Update'
},
Body => {
ID => 'RichText',
Type => 'RichText',
Value => 'Selenium Note Body',
Update => 'Selenium Note Body - Update',
},
Attachments => {
ID => 'FileUpload',
Type => 'Attachment',
},
},
},
{
Module => 'Close',
Fields => {
State => {
ID => 'NewStateID',
Type => 'DropDown',
Value => 2,
Update => 3,
},
Subject => {
ID => 'Subject',
Type => 'Input',
Value => 'Selenium Close Subject',
Update => 'Selenium Close Subject - Update'
},
Body => {
ID => 'RichText',
Type => 'RichText',
Value => 'Selenium Close Body',
Update => 'Selenium Close Body - Update',
},
Attachments => {
ID => 'FileUpload',
Type => 'Attachment',
},
},
},
{
Module => 'Pending',
Fields => {
State => {
ID => 'NewStateID',
Type => 'DropDown',
Value => 7,
Update => 8,
},
Subject => {
ID => 'Subject',
Type => 'Input',
Value => 'Selenium Pending Subject',
Update => 'Selenium Pending Subject - Update'
},
Body => {
ID => 'RichText',
Type => 'RichText',
Value => 'Selenium Pending Body',
Update => 'Selenium Pending Body - Update',
},
Attachments => {
ID => 'FileUpload',
Type => 'Attachment',
},
},
},
{
Module => 'Owner',
Fields => {
Subject => {
ID => 'Subject',
Type => 'Input',
Value => 'Selenium Owner Subject',
Update => 'Selenium Owner Subject - Update'
},
Body => {
ID => 'RichText',
Type => 'RichText',
Value => 'Selenium Owner Body',
Update => 'Selenium Owner Body - Update',
},
Attachments => {
ID => 'FileUpload',
Type => 'Attachment',
},
},
},
{
Module => 'Responsible',
Fields => {
Title => {
ID => 'Title',
Type => 'Input',
Value => 'Selenium Responsible Title',
Update => 'Selenium Responsible Title - Update'
},
Subject => {
ID => 'Subject',
Type => 'Input',
Value => 'Selenium Responsible Subject',
Update => 'Selenium Responsible Subject - Update'
},
Body => {
ID => 'RichText',
Type => 'RichText',
Value => 'Selenium Responsible Body',
Update => 'Selenium Responsible Body - Update',
},
Attachments => {
ID => 'FileUpload',
Type => 'Attachment',
},
},
},
{
Module => 'FreeText',
Fields => {
Title => {
ID => 'Title',
Type => 'Input',
Value => 'Selenium FreeText Title',
Update => 'Selenium FreeText Title - Update'
},
},
},
);
# Execute test scenarios.
my $Handles;
for my $Test (@Tests) {
# Create Draft name.
my $Title = $Test->{Module} . 'Draft' . $RandomID;
$Selenium->VerifiedGet("${ScriptAlias}index.pl?Action=AgentTicket$Test->{Module};TicketID=$TicketID");
# Wait until page has loaded, if necessary.
$Selenium->WaitFor(
JavaScript =>
'return typeof($) === "function" && $(".WidgetSimple").length;'
);
# Input fields.
for my $Field ( sort keys %{ $Test->{Fields} } ) {
if ( $Test->{Fields}->{$Field}->{Type} eq 'DropDown' ) {
$Selenium->WaitFor(
JavaScript =>
"return typeof(\$) === 'function' && \$('#$Test->{Fields}->{$Field}->{ID}').length;"
);
$Selenium->InputFieldValueSet(
Element => "#$Test->{Fields}->{$Field}->{ID}",
Value => $Test->{Fields}->{$Field}->{Value},
);
}
elsif ( $Test->{Fields}->{$Field}->{Type} eq 'Attachment' ) {
# Make the file upload field visible.
$Selenium->execute_script(
"\$('#FileUpload').css('display', 'block');"
);
$Selenium->WaitFor(
JavaScript =>
'return typeof($) === "function" && $("#FileUpload:visible").length;'
);
sleep 1;
# Upload a file.
$Selenium->find_element( "#FileUpload", 'css' )
->send_keys( $Selenium->{Home} . "/scripts/test/sample/Main/Main-Test1.pdf" );
$Selenium->WaitFor(
JavaScript =>
"return typeof(\$) === 'function' && \$('.AttachmentList td.Filename:contains(\"Main-Test1.pdf\")').length === 1;"
);
# Wait until file is uploaded and 'Progress' class is removed.
$Selenium->WaitFor(
JavaScript =>
"return !\$('.AttachmentList td.Filename:contains(\"Main-Test1.pdf\")').siblings('.Filesize').find('.Progress').length;"
);
# Check if uploaded.
$Self->Is(
$Selenium->execute_script(
"return \$('.AttachmentList td.Filename:contains(\"Main-Test1.pdf\")').length;"
),
1,
$Test->{Module} . " - Uploaded file correctly"
);
}
elsif ( $Test->{Fields}->{$Field}->{Type} eq 'RichText' ) {
# wait for the CKE to load
$Selenium->WaitFor(
JavaScript =>
"return \$('body.cke_editable', \$('.cke_wysiwyg_frame').contents()).length == 1;"
);
$Selenium->execute_script(
"return CKEDITOR.instances.RichText.setData('$Test->{Fields}->{$Field}->{Value}');"
);
$Selenium->execute_script(
"return CKEDITOR.instances.RichText.updateElement();"
);
}
else {
$Selenium->WaitFor(
JavaScript =>
"return typeof(\$) === 'function' && \$('#$Test->{Fields}->{$Field}->{ID}').length;"
);
$Selenium->find_element( "#$Test->{Fields}->{$Field}->{ID}", 'css' )->clear();
$Selenium->find_element( "#$Test->{Fields}->{$Field}->{ID}", 'css' )
->send_keys( $Test->{Fields}->{$Field}->{Value} );
}
}
# Create Draft and submit.
$Selenium->WaitForjQueryEventBound(
CSSSelector => "#FormDraftSave",
);
# Save form in Draft.
$Selenium->execute_script("\$('#FormDraftSave').click();");
$Selenium->WaitFor(
JavaScript =>
'return typeof($) === "function" && $("#FormDraftTitle").length && $("#SaveFormDraft").length;'
);
$Selenium->find_element( "#FormDraftTitle", 'css' )->send_keys($Title);
$Selenium->execute_script("\$('#SaveFormDraft').click();");
$Selenium->WaitFor( JavaScript => 'return typeof($) === "function" && !$(".Dialog.Modal").length;' );
# Navigate to zoom view of created test ticket.
$Selenium->VerifiedGet("${ScriptAlias}index.pl?Action=AgentTicketZoom;TicketID=$TicketID");
# Verify Draft is created in zoom screen.
$Self->True(
$Selenium->execute_script("return \$('#FormDraftTable a:contains(\"$Title\")').length;"),
"Draft for $Test->{Module} $Title is found",
);
my $ArticleObject = $Kernel::OM->Get('Kernel::System::Ticket::Article');
my $ArticleBackendObject = $ArticleObject->BackendForChannel( ChannelName => 'Phone' );
# Create test Article to trigger that draft is outdated.
my $ArticleID = $ArticleBackendObject->ArticleCreate(
TicketID => $TicketID,
IsVisibleForCustomer => 1,
SenderType => 'customer',
Subject => "Article $Test->{Module} OutDate Draft trigger",
Body => 'Selenium body article',
MimeType => 'text/plain',
Charset => 'ISO-8859-15',
UserID => 1,
HistoryType => 'AddNote',
HistoryComment => 'Some free text!',
);
$Self->True(
$ArticleID,
"Article ID $ArticleID is created",
);
my $FormDraftLink = $Selenium->execute_script("return \$('.DraftName .MasterActionLink').attr('href');");
my ($FormDraftID) = $FormDraftLink =~ m{FormDraftID=(\d*)};
# Click on test created FormDraft and switch window.
$Selenium->VerifiedGet(
"${ScriptAlias}index.pl?Action=AgentTicket$Test->{Module};TicketID=$TicketID;LoadFormDraft=1;FormDraftID=$FormDraftID"
);
# Make sure that draft loaded notification is present.
$Self->True(
index( $Selenium->get_page_source(), "You have loaded the draft \"$Title\"" ) > 0,
'Draft loaded notification is present',
);
# Make sure that outdated notification is present.
$Self->True(
index(
$Selenium->get_page_source(),
"Please note that this draft is outdated because the ticket was modified since this draft was created."
)
> 0,
'Outdated notification is present',
);
# Verify initial Draft values and update them.
for my $FieldValue ( sort keys %{ $Test->{Fields} } ) {
if ( $Test->{Fields}->{$FieldValue}->{Type} eq 'DropDown' ) {
my $ID = $Test->{Fields}->{$FieldValue}->{ID};
my $Value = $Test->{Fields}->{$FieldValue}->{Value};
$Selenium->WaitFor(
JavaScript =>
"return typeof(\$) === 'function' && \$('#$ID').length && \$('#$ID').val() == '$Value';"
);
$Self->Is(
$Selenium->execute_script("return \$('#$ID').val();"),
$Value,
"Initial Draft value for $Test->{Module} field $FieldValue is correct - $Value"
);
$Selenium->InputFieldValueSet(
Element => "#$ID",
Value => $Test->{Fields}->{$FieldValue}->{Update},
);
}
elsif ( $Test->{Fields}->{$FieldValue}->{Type} eq 'Attachment' ) {
# there should be only one file with a certain name
$Self->Is(
$Selenium->execute_script(
"return \$('.AttachmentList tbody tr td.Filename:contains(\"Main-Test1.pdf\")').length;"
),
1,
$Test->{Module} . " - Uploaded file correctly"
);
$Self->Is(
$Selenium->execute_script(
"return \$('.AttachmentList tbody tr td.Filename').length;"
),
1,
$Test->{Module} . " - Only one file present"
);
# Add a second file.
$Selenium->VerifiedRefresh();
$Selenium->execute_script(
"\$('#FileUpload').css('display', 'block');"
);
$Selenium->WaitFor(
JavaScript =>
'return typeof($) === "function" && $("#FileUpload:visible").length;'
);
sleep 1;
# Upload a file.
$Selenium->find_element( "#FileUpload", 'css' )
->send_keys( $Selenium->{Home} . "/scripts/test/sample/Main/Main-Test1.doc" );
$Selenium->WaitFor(
JavaScript =>
"return typeof(\$) === 'function' && \$('.AttachmentList td.Filename:contains(\"Main-Test1.doc\")').length === 1;"
);
# Wait until file is uploaded and 'Progress' class is removed.
$Selenium->WaitFor(
JavaScript =>
"return !\$('.AttachmentList td.Filename:contains(\"Main-Test1.doc\")').siblings('.Filesize').find('.Progress').length;"
);
# Check if uploaded.
$Self->Is(
$Selenium->execute_script(
"return \$('.AttachmentList tbody tr td.Filename:contains(\"Main-Test1.doc\")').length;"
),
1,
$Test->{Module} . " - Uploaded file correctly"
);
}
elsif ( $Test->{Fields}->{$FieldValue}->{Type} eq 'RichText' ) {
# wait for the CKE to load
$Selenium->WaitFor(
JavaScript =>
"return \$('body.cke_editable', \$('.cke_wysiwyg_frame').contents()).length == 1;"
);
$Self->Is(
$Selenium->execute_script('return CKEDITOR.instances.RichText.getData();'),
$Test->{Fields}->{$FieldValue}->{Value},
"Initial Draft value for $Test->{Module} field $FieldValue is correct"
);
$Selenium->execute_script(
"return CKEDITOR.instances.RichText.setData('$Test->{Fields}->{$FieldValue}->{Update}');"
);
$Selenium->execute_script(
"return CKEDITOR.instances.RichText.updateElement();"
);
}
else {
my $ID = $Test->{Fields}->{$FieldValue}->{ID};
my $Value = $Test->{Fields}->{$FieldValue}->{Value};
$Selenium->WaitFor(
JavaScript =>
"return typeof(\$) === 'function' && \$('#$ID').length && \$('#$ID').val() == '$Value';"
);
$Self->Is(
$Selenium->execute_script("return \$('#$ID').val();"),
$Value,
"Initial Draft value for $Test->{Module} field $FieldValue is correct - $Value"
);
$Selenium->find_element( "#$ID", 'css' )->clear();
$Selenium->find_element( "#$ID", 'css' )->send_keys( $Test->{Fields}->{$FieldValue}->{Update} );
}
}
# Try to add draft with same name.
$Selenium->WaitForjQueryEventBound(
CSSSelector => "#FormDraftSave",
);
$Selenium->execute_script("\$('#FormDraftSave').click();");
$Selenium->WaitFor(
JavaScript =>
'return typeof($) === "function" && $("#FormDraftTitle").length && $("#SaveFormDraft").length;'
);
$Selenium->find_element( "#FormDraftTitle", 'css' )->send_keys($Title);
$Selenium->execute_script("\$('#SaveFormDraft').click();");
$Selenium->WaitFor( AlertPresent => 1 ) || die 'Alert not found';
# Verify the alert message.
my $ExpectedAlertText = "Draft name $Title is already in use!";
$Self->True(
( $Selenium->get_alert_text() =~ /$ExpectedAlertText/ ),
"Check alert message text.",
);
# Accept the alert to continue with the tests.
$Selenium->accept_alert();
$Selenium->find_element( ".CloseDialog", 'css' )->click();
# Navigate to zoom view of created test ticket.
$Selenium->VerifiedGet("${ScriptAlias}index.pl?Action=AgentTicketZoom;TicketID=$TicketID");
# Delete draft
$Selenium->find_element( ".FormDraftDelete", 'css' )->click();
$Selenium->WaitFor(
JavaScript =>
'return typeof($) === "function" && $("#DeleteConfirm").length;'
);
$Selenium->find_element( "#DeleteConfirm", 'css' )->click();
my $Deleted = $Selenium->WaitFor(
JavaScript =>
'return typeof($) === "function" && $(".FormDraftDelete").length == 0;'
);
$Self->True(
$Deleted,
"Check if Draft is deleted.",
);
}
# Test for Save the draft without JSON error in window, bug#13556 https://bugs.otrs.org/show_bug.cgi?id=13556.
# Navigate to AgentTicketNote screen.
$Selenium->VerifiedGet("${ScriptAlias}index.pl?Action=AgentTicketNote;TicketID=$TicketID");
$Selenium->WaitForjQueryEventBound(
CSSSelector => "#FormDraftSave",
);
# Save form in Draft.
$Selenium->execute_script("\$('#FormDraftSave').click();");
$Selenium->WaitFor(
JavaScript =>
'return typeof($) === "function" && $("#FormDraftTitle").length && $("#SaveFormDraft").length;'
);
# Click on save Draft title dialog.
$Selenium->find_element( "#SaveFormDraft", 'css' )->click();
# Wait alert to appear.
$Selenium->WaitFor( AlertPresent => 1 ) || die 'Alert not found';
# Verify the alert message.
my $ExpectedAlertText = "Draft name is required!";
$Self->True(
( $Selenium->get_alert_text() =~ /$ExpectedAlertText/ ),
"Check alert message text.",
);
# Accept the validation alert.
$Selenium->accept_alert();
# Close save draft title dialog.
$Selenium->find_element( ".CloseDialog", 'css' )->click();
# Wait to close Dialog.
$Selenium->WaitFor( JavaScript => 'return typeof($) === "function" && $(".Dialog:visible").length === 0;' );
# Submit empty form to check validation.
$Selenium->find_element( "#submitRichText", 'css' )->click();
# Wait error Dialog to be visible.
$Selenium->WaitFor( JavaScript => 'return typeof($) === "function" && $(".Dialog:visible").length === 1;' );
# Close error Dialog.
$Selenium->find_element( "#DialogButton1", 'css' )->click();
$Selenium->WaitFor( JavaScript => 'return typeof($) === "function" && $(".Dialog:visible").length === 0;' );
# Check validation.
$Self->Is(
$Selenium->execute_script(
"return \$('#Subject').hasClass('Error');"
),
'1',
'Client side validation correctly detected missing input value',
);
# Delete created test ticket.
my $Success = $TicketObject->TicketDelete(
TicketID => $TicketID,
UserID => 1,
);
# Ticket deletion could fail if apache still writes to ticket history. Try again in this case.
if ( !$Success ) {
sleep 3;
$Success = $TicketObject->TicketDelete(
TicketID => $TicketID,
UserID => 1,
);
}
$Self->True(
$Success,
"Ticket ID $TicketID is deleted"
);
# Make sure the cache is correct.
my $CacheObject = $Kernel::OM->Get('Kernel::System::Cache');
for my $Cache (qw(Ticket Article)) {
$CacheObject->CleanUp( Type => $Cache );
}
}
);
1;
|