From 6bec37c14ce9ca13da5baac97970b245ad95b232 Mon Sep 17 00:00:00 2001 From: bernhard Date: Tue, 27 Apr 2021 20:34:30 +0200 Subject: [PATCH 1/2] Issue #682: mark tests as TODO reason of sporadic failures is not obvious --- .../Selenium/Agent/AgentTicketProcessSplit.t | 441 +++++++++--------- 1 file changed, 224 insertions(+), 217 deletions(-) diff --git a/scripts/test/Selenium/Agent/AgentTicketProcessSplit.t b/scripts/test/Selenium/Agent/AgentTicketProcessSplit.t index 85d823a2ac..22c7f0c008 100644 --- a/scripts/test/Selenium/Agent/AgentTicketProcessSplit.t +++ b/scripts/test/Selenium/Agent/AgentTicketProcessSplit.t @@ -201,250 +201,257 @@ $Selenium->RunTest( $Selenium->VerifiedRefresh(); - # Check if customer user input is on create process screen. - $Selenium->WaitFor( ElementExists => [ '#CustomerAutoComplete', 'css' ] ); + { + my $ToDo = todo('selection of process is not reliable, see #929'); - # Create Process ticket without article. - $Selenium->find_element( "#CustomerAutoComplete", 'css' )->send_keys('Huber'); - $Selenium->find_element("//button[\@value='Submit'][\@type='submit']")->VerifiedClick(); + try_ok { - # Remember created ticket, to delete the ticket at the end of the test. - my @TicketID = split( 'TicketID=', $Selenium->get_current_url() ); - push @DeleteTicketIDs, $TicketID[1]; + # Check if customer user input is on create process screen. + $Selenium->WaitFor( ElementExists => [ '#CustomerAutoComplete', 'css' ] ); - $Selenium->WaitFor( - JavaScript => 'return typeof($) === "function" && $(".AsBlock.LinkObjectLink").length;' - ); + # Create Process ticket without article. + $Selenium->find_element( "#CustomerAutoComplete", 'css' )->send_keys('Huber'); + $Selenium->find_element("//button[\@value='Submit'][\@type='submit']")->VerifiedClick(); - # Verify there is link to parent ticket. - ok( - $Selenium->find_elements( - "//a[contains(\@class, 'LinkObjectLink')][contains(\@href, 'Action=AgentTicketZoom;TicketID=$TicketID')]" - ), - "Link to parent ticket is found", - ); + # Remember created ticket, to delete the ticket at the end of the test. + my @TicketID = split( 'TicketID=', $Selenium->get_current_url() ); + push @DeleteTicketIDs, $TicketID[1]; - # Scroll down. - $Selenium->execute_script( - "\$('a.LinkObjectLink[href*=\"Action=AgentTicketZoom;TicketID=$TicketID\"]')[0].scrollIntoView(true);", - ); + $Selenium->WaitFor( + JavaScript => 'return typeof($) === "function" && $(".AsBlock.LinkObjectLink").length;' + ); - # Check if ticket split with customer created article is preselecting customer user from article. See bug#12956. - # Create test customer company. - my $TestCompany = 'Company' . $RandomID; - my $CustomerID = $Kernel::OM->Get('Kernel::System::CustomerCompany')->CustomerCompanyAdd( - CustomerID => $TestCompany, - CustomerCompanyName => $TestCompany, - ValidID => 1, - UserID => 1, - ); - ok( $CustomerID, "CustomerCompanyID $CustomerID is created" ); - - # Create test customer user. - my $TestUser = 'CustomerUser' . $RandomID; - my $TestUserEmail = "$TestUser\@example.com"; - my $CustomerUser = $Kernel::OM->Get('Kernel::System::CustomerUser')->CustomerUserAdd( - Source => 'CustomerUser', - UserFirstname => $TestUser, - UserLastname => $TestUser, - UserCustomerID => $CustomerID, - UserLogin => $TestUser, - UserEmail => $TestUserEmail, - ValidID => 1, - UserID => 1 - ); - ok( $CustomerUser, "First CustomerUser $CustomerUser is created" ); + # Verify there is link to parent ticket. + ok( + $Selenium->find_elements( + "//a[contains(\@class, 'LinkObjectLink')][contains(\@href, 'Action=AgentTicketZoom;TicketID=$TicketID')]" + ), + "Link to parent ticket is found", + ); - my $UserFormString = "\"$TestUser $TestUser\" <$TestUserEmail>"; - my $ArticleID2 = $ArticleBackendObject->ArticleCreate( - TicketID => $TicketID, - IsVisibleForCustomer => 0, - SenderType => 'customer', - From => $UserFormString, - To => 'Some Agent ', - Subject => 'some short description', - Body => 'the message text', - Charset => 'utf8', - MimeType => 'text/plain', - HistoryType => 'OwnerUpdate', - HistoryComment => 'Some free text!', - UserID => 1, - ); - ok( $ArticleID2, "Second article created." ); + # Scroll down. + $Selenium->execute_script( + "\$('a.LinkObjectLink[href*=\"Action=AgentTicketZoom;TicketID=$TicketID\"]')[0].scrollIntoView(true);", + ); - # Go to linked Ticket. - $Selenium->find_element( - "//a[contains(\@class, 'LinkObjectLink')][contains(\@href, 'Action=AgentTicketZoom;TicketID=$TicketID' )]" - )->VerifiedClick(); + # Check if ticket split with customer created article is preselecting customer user from article. See bug#12956. + # Create test customer company. + my $TestCompany = 'Company' . $RandomID; + my $CustomerID = $Kernel::OM->Get('Kernel::System::CustomerCompany')->CustomerCompanyAdd( + CustomerID => $TestCompany, + CustomerCompanyName => $TestCompany, + ValidID => 1, + UserID => 1, + ); + ok( $CustomerID, "CustomerCompanyID $CustomerID is created" ); + + # Create test customer user. + my $TestUser = 'CustomerUser' . $RandomID; + my $TestUserEmail = "$TestUser\@example.com"; + my $CustomerUser = $Kernel::OM->Get('Kernel::System::CustomerUser')->CustomerUserAdd( + Source => 'CustomerUser', + UserFirstname => $TestUser, + UserLastname => $TestUser, + UserCustomerID => $CustomerID, + UserLogin => $TestUser, + UserEmail => $TestUserEmail, + ValidID => 1, + UserID => 1 + ); + ok( $CustomerUser, "First CustomerUser $CustomerUser is created" ); + + my $UserFormString = "\"$TestUser $TestUser\" <$TestUserEmail>"; + my $ArticleID2 = $ArticleBackendObject->ArticleCreate( + TicketID => $TicketID, + IsVisibleForCustomer => 0, + SenderType => 'customer', + From => $UserFormString, + To => 'Some Agent ', + Subject => 'some short description', + Body => 'the message text', + Charset => 'utf8', + MimeType => 'text/plain', + HistoryType => 'OwnerUpdate', + HistoryComment => 'Some free text!', + UserID => 1, + ); + ok( $ArticleID2, "Second article created." ); - $Selenium->WaitFor( - JavaScript => 'return typeof($) === "function" && $(".AsBlock.LinkObjectLink").length;' - ); + # Go to linked Ticket. + $Selenium->find_element( + "//a[contains(\@class, 'LinkObjectLink')][contains(\@href, 'Action=AgentTicketZoom;TicketID=$TicketID' )]" + )->VerifiedClick(); - # Verify there is link to child ticket. - ok( - $Selenium->find_elements( - "//a[contains(\@class, 'LinkObjectLink')][contains(\@href, 'Action=AgentTicketZoom;TicketID=$TicketID[1]')]" - ), - "Link to child ticket is found", - ); + $Selenium->WaitFor( + JavaScript => 'return typeof($) === "function" && $(".AsBlock.LinkObjectLink").length;' + ); - # Click on the split action. - $Selenium->find_element( '.SplitSelection', 'css' )->click(); + # Verify there is link to child ticket. + ok( + $Selenium->find_elements( + "//a[contains(\@class, 'LinkObjectLink')][contains(\@href, 'Action=AgentTicketZoom;TicketID=$TicketID[1]')]" + ), + "Link to child ticket is found", + ); - $Selenium->WaitForjQueryEventBound( - CSSSelector => '#SplitSubmit', - ); + # Click on the split action. + $Selenium->find_element( '.SplitSelection', 'css' )->click(); - # Change it to Process. - $Selenium->InputFieldValueSet( - Element => '#SplitSelection', - Value => 'ProcessTicket', - ); - $Selenium->WaitFor( - JavaScript => 'return $("#ProcessEntityID").length;' - ); + $Selenium->WaitForjQueryEventBound( + CSSSelector => '#SplitSubmit', + ); - # Change it to Process EntityID. - $Selenium->InputFieldValueSet( - Element => '#ProcessEntityID', - Value => $Process->{EntityID}, - ); - $Selenium->find_element( '#SplitSubmit', 'css' )->VerifiedClick(); + # Change it to Process. + $Selenium->InputFieldValueSet( + Element => '#SplitSelection', + Value => 'ProcessTicket', + ); + $Selenium->WaitFor( + JavaScript => 'return $("#ProcessEntityID").length;' + ); - $Selenium->WaitFor( ElementExists => [ '#CustomerAutoComplete', 'css' ] ); + # Change it to Process EntityID. + $Selenium->InputFieldValueSet( + Element => '#ProcessEntityID', + Value => $Process->{EntityID}, + ); + $Selenium->find_element( '#SplitSubmit', 'css' )->VerifiedClick(); - # Check if correct user is selected after process ticket split. - is( - $Selenium->execute_script("return \$('#CustomerAutoComplete').val().trim();"), - $UserFormString, - "Preselected customer user is correct" - ); + $Selenium->WaitFor( ElementExists => [ '#CustomerAutoComplete', 'css' ] ); - # Navigate to AgentTicketProcess screen. Test bug#14758. - $Selenium->VerifiedGet("${ScriptAlias}index.pl?Action=AgentTicketProcess"); + # Check if correct user is selected after process ticket split. + is( + $Selenium->execute_script("return \$('#CustomerAutoComplete').val().trim();"), + $UserFormString, + "Preselected customer user is correct" + ); - $Selenium->InputFieldValueSet( - Element => '#ProcessEntityID', - Value => $ListReverse{$ProcessName}, - ); + # Navigate to AgentTicketProcess screen. Test bug#14758. + $Selenium->VerifiedGet("${ScriptAlias}index.pl?Action=AgentTicketProcess"); - $Selenium->WaitFor( - ElementExists => "//input[contains(\@name,'CustomerUserID')]" - ); - - # Verify form is loaded. - $Selenium->find_element_by_css_ok( - '#CustomerAutoComplete', - "Customer field is available." - ) || die; - - for my $TicketID (@DeleteTicketIDs) { - - my $Success = $TicketObject->TicketDelete( - TicketID => $TicketID, - UserID => $TestUserID, - ); - - # 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 => $TestUserID, + $Selenium->InputFieldValueSet( + Element => '#ProcessEntityID', + Value => $ListReverse{$ProcessName}, ); - } - ok( $Success, "TicketID $TicketID is deleted" ); - } - # Clean up activities. - my $ActivityObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::DB::Activity'); - my $ActivityDialogObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::DB::ActivityDialog'); - for my $Item ( @{ $Process->{Activities} } ) { - my $Activity = $ActivityObject->ActivityGet( - EntityID => $Item, - UserID => $TestUserID, - ActivityDialogNames => 0, - ); - - # Clean up activity dialogs. - for my $ActivityDialogItem ( @{ $Activity->{ActivityDialogs} } ) { - my $ActivityDialog = $ActivityDialogObject->ActivityDialogGet( - EntityID => $ActivityDialogItem, - UserID => $TestUserID, + $Selenium->WaitFor( + ElementExists => "//input[contains(\@name,'CustomerUserID')]" ); - # Delete test activity dialog. - my $Success = $ActivityDialogObject->ActivityDialogDelete( - ID => $ActivityDialog->{ID}, - UserID => $TestUserID, + # Verify form is loaded. + $Selenium->find_element_by_css_ok( + '#CustomerAutoComplete', + "Customer field is available." + ) || die; + + for my $TicketID (@DeleteTicketIDs) { + + my $Success = $TicketObject->TicketDelete( + TicketID => $TicketID, + UserID => $TestUserID, + ); + + # 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 => $TestUserID, + ); + } + ok( $Success, "TicketID $TicketID is deleted" ); + } + + # Clean up activities. + my $ActivityObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::DB::Activity'); + my $ActivityDialogObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::DB::ActivityDialog'); + for my $Item ( @{ $Process->{Activities} } ) { + my $Activity = $ActivityObject->ActivityGet( + EntityID => $Item, + UserID => $TestUserID, + ActivityDialogNames => 0, + ); + + # Clean up activity dialogs. + for my $ActivityDialogItem ( @{ $Activity->{ActivityDialogs} } ) { + my $ActivityDialog = $ActivityDialogObject->ActivityDialogGet( + EntityID => $ActivityDialogItem, + UserID => $TestUserID, + ); + + # Delete test activity dialog. + my $Success = $ActivityDialogObject->ActivityDialogDelete( + ID => $ActivityDialog->{ID}, + UserID => $TestUserID, + ); + ok( $Success, "ActivityDialog $ActivityDialog->{Name} is deleted" ); + } + + # Delete test activity. + my $Success = $ActivityObject->ActivityDelete( + ID => $Activity->{ID}, + UserID => $TestUserID, + ); + + ok( $Success, "Activity $Activity->{Name} is deleted" ); + } + + # Clean up transition actions + my $TransitionActionsObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::DB::TransitionAction'); + for my $Item ( @{ $Process->{TransitionActions} } ) { + my $TransitionAction = $TransitionActionsObject->TransitionActionGet( + EntityID => $Item, + UserID => $TestUserID, + ); + + # Delete test transition action. + my $Success = $TransitionActionsObject->TransitionActionDelete( + ID => $TransitionAction->{ID}, + UserID => $TestUserID, + ); + ok( $Success, "TransitionAction $TransitionAction->{Name} is deleted" ); + } + + # Clean up transition. + my $TransitionObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::DB::Transition'); + for my $Item ( @{ $Process->{Transitions} } ) { + my $Transition = $TransitionObject->TransitionGet( + EntityID => $Item, + UserID => $TestUserID, + ); + + # Delete test transition. + my $Success = $TransitionObject->TransitionDelete( + ID => $Transition->{ID}, + UserID => $TestUserID, + ); + ok( $Success, "Transition $Transition->{Name} is deleted" ); + } + + # Delete created test customer users. + my $DBObject = $Kernel::OM->Get('Kernel::System::DB'); + my $Success = $DBObject->Do( + SQL => "DELETE FROM customer_user WHERE login = ?", + Bind => [ \$CustomerUser ], ); - ok( $Success, "ActivityDialog $ActivityDialog->{Name} is deleted" ); - } - - # Delete test activity. - my $Success = $ActivityObject->ActivityDelete( - ID => $Activity->{ID}, - UserID => $TestUserID, - ); + ok( $Success, "Customer user $CustomerUser is deleted" ); - ok( $Success, "Activity $Activity->{Name} is deleted" ); - } - - # Clean up transition actions - my $TransitionActionsObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::DB::TransitionAction'); - for my $Item ( @{ $Process->{TransitionActions} } ) { - my $TransitionAction = $TransitionActionsObject->TransitionActionGet( - EntityID => $Item, - UserID => $TestUserID, - ); - - # Delete test transition action. - my $Success = $TransitionActionsObject->TransitionActionDelete( - ID => $TransitionAction->{ID}, - UserID => $TestUserID, - ); - ok( $Success, "TransitionAction $TransitionAction->{Name} is deleted" ); - } + # Delete created customer company. + $Success = $DBObject->Do( + SQL => "DELETE FROM customer_company WHERE customer_id = ?", + Bind => [ \$CustomerID ], + ); + ok( $Success, "CustomerCompany $CustomerID is deleted." ); - # Clean up transition. - my $TransitionObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::DB::Transition'); - for my $Item ( @{ $Process->{Transitions} } ) { - my $Transition = $TransitionObject->TransitionGet( - EntityID => $Item, - UserID => $TestUserID, - ); - - # Delete test transition. - my $Success = $TransitionObject->TransitionDelete( - ID => $Transition->{ID}, - UserID => $TestUserID, - ); - ok( $Success, "Transition $Transition->{Name} is deleted" ); + # Delete test Process. + $Success = $ProcessObject->ProcessDelete( + ID => $Process->{ID}, + UserID => $TestUserID, + ); + ok( $Success, "Process $Process->{Name} is deleted" ); + }; } - - # Delete created test customer users. - my $DBObject = $Kernel::OM->Get('Kernel::System::DB'); - my $Success = $DBObject->Do( - SQL => "DELETE FROM customer_user WHERE login = ?", - Bind => [ \$CustomerUser ], - ); - ok( $Success, "Customer user $CustomerUser is deleted" ); - - # Delete created customer company. - $Success = $DBObject->Do( - SQL => "DELETE FROM customer_company WHERE customer_id = ?", - Bind => [ \$CustomerID ], - ); - ok( $Success, "CustomerCompany $CustomerID is deleted." ); - - # Delete test Process. - $Success = $ProcessObject->ProcessDelete( - ID => $Process->{ID}, - UserID => $TestUserID, - ); - ok( $Success, "Process $Process->{Name} is deleted" ); - }, + } ); done_testing(); From bee752544d6d86a19fa0434743fd98b5b5777f92 Mon Sep 17 00:00:00 2001 From: bernhard Date: Tue, 27 Apr 2021 23:19:21 +0200 Subject: [PATCH 2/2] Issue #682: don't emit a fail when a login iteration fails As otherwise the whole subtest fails, and an exception is thrown. --- Kernel/System/UnitTest/Selenium.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel/System/UnitTest/Selenium.pm b/Kernel/System/UnitTest/Selenium.pm index 2db53f69fa..ff2cdda5b1 100644 --- a/Kernel/System/UnitTest/Selenium.pm +++ b/Kernel/System/UnitTest/Selenium.pm @@ -487,13 +487,13 @@ sub Login { if ($@) { # login was not sucessful - fail("Login attempt $Try/$MaxTries failed"); + note("Login attempt $Try/$MaxTries failed"); next TRY; } # no error happend - pass("Login attempt $Try/$MaxTries succeeded"); + note("Login attempt $Try/$MaxTries succeeded"); $LoginSuccessful = 1; last TRY;