1 package org.apache.archiva.web.test.parent;
3 import org.apache.archiva.web.test.tools.ArchivaSeleniumRunner;
4 import org.junit.After;
5 import org.junit.Assert;
6 import org.junit.Before;
7 import org.junit.runner.RunWith;
10 import java.io.IOException;
13 * Licensed to the Apache Software Foundation (ASF) under one
14 * or more contributor license agreements. See the NOTICE file
15 * distributed with this work for additional information
16 * regarding copyright ownership. The ASF licenses this file
17 * to you under the Apache License, Version 2.0 (the
18 * "License"); you may not use this file except in compliance
19 * with the License. You may obtain a copy of the License at
21 * http://www.apache.org/licenses/LICENSE-2.0
23 * Unless required by applicable law or agreed to in writing,
24 * software distributed under the License is distributed on an
25 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
26 * KIND, either express or implied. See the License for the
27 * specific language governing permissions and limitations
31 @RunWith( ArchivaSeleniumRunner.class )
32 public abstract class AbstractArchivaTest
33 extends AbstractSeleniumTest
35 protected String username;
37 protected String fullname;
56 public void assertAdminCreated()
59 initializeArchiva( System.getProperty( "baseUrl" ), System.getProperty( "browser" ),
60 Integer.getInteger( "maxWaitTimeInMs" ), System.getProperty( "seleniumHost", "localhost" ),
61 Integer.getInteger( "seleniumPort", 4444 ) );
64 public void initializeArchiva( String baseUrl, String browser, int maxWaitTimeInMs, String seleniumHost,
69 super.open( baseUrl, browser, seleniumHost, seleniumPort, Integer.toString( maxWaitTimeInMs ) );
71 getSelenium().open( baseUrl );
75 // if not admin user created create one
76 if ( isElementVisible( "create-admin-link" ) )
78 Assert.assertFalse( getSelenium().isVisible( "login-link-a" ) );
79 Assert.assertFalse( getSelenium().isVisible( "register-link-a" ) );
80 clickLinkWithLocator( "create-admin-link-a", false );
82 String fullname = getProperty( "ADMIN_FULLNAME" );
83 String username = getAdminUsername();
84 String mail = getProperty( "ADMIN_EMAIL" );
85 String password = getProperty( "ADMIN_PASSWORD" );
86 submitAdminData( fullname, mail, password );
87 assertUserLoggedIn( username );
88 clickLinkWithLocator( "logout-link-a" );
92 Assert.assertTrue( getSelenium().isVisible( "login-link-a" ) );
93 Assert.assertTrue( getSelenium().isVisible( "register-link-a" ) );
94 login( getAdminUsername(), getAdminPassword() );
99 protected static String getErrorMessageText()
101 return getSelenium().getText( "//ul[@class='errorMessage']/li/span" );
104 public String getUserEmail()
106 String email = getProperty( "USERROLE_EMAIL" );
110 public String getUserRolePassword()
112 String password = getProperty( "USERROLE_PASSWORD" );
116 public String getUserRoleNewPassword()
118 String password_new = getProperty( "NEW_USERROLE_PASSWORD" );
122 public String getBasedir()
124 String basedir = System.getProperty( "basedir" );
126 if ( basedir == null )
128 basedir = new File( "" ).getAbsolutePath();
134 public String getAdminUsername()
136 String adminUsername = getProperty( "ADMIN_USERNAME" );
137 return adminUsername;
140 public String getAdminPassword()
142 String adminPassword = getProperty( "ADMIN_PASSWORD" );
143 return adminPassword;
146 public void assertCreateAdmin()
148 assertElementPresent( "user-create" );
149 assertFieldValue( "admin", "username" );
150 assertElementPresent( "fullname" );
151 assertElementPresent( "password" );
152 assertElementPresent( "confirmPassword" );
153 assertElementPresent( "email" );
156 public void submitAdminData( String fullname, String email, String password )
158 setFieldValue( "fullname", fullname );
159 setFieldValue( "email", email );
160 setFieldValue( "password", password );
161 setFieldValue( "confirmPassword", password );
162 clickButtonWithLocator( "user-create-form-register-button" );
167 public void goToLoginPage()
169 getSelenium().open( baseUrl );
171 // are we already logged in ?
172 if ( isElementVisible( "logout-link" ) ) //isElementPresent( "logoutLink" ) )
175 clickLinkWithLocator( "logout-link-a", false );
176 clickLinkWithLocator( "login-link-a" );
178 else if ( isElementVisible( "login-link-a" ) )
180 clickLinkWithLocator( "login-link-a" );
185 public void submitUserData( String username, String password, boolean rememberme, boolean success )
188 setFieldValue( "username", username );
189 setFieldValue( "password", password );
192 checkField( "rememberMe" );
198 assertUserLoggedIn( username );
206 public void assertLoginModal()
208 assertElementPresent( "user-login-form" );
209 Assert.assertTrue( isElementVisible( "register-link" ) );
210 assertElementPresent( "user-login-form-username" );
211 assertElementPresent( "user-login-form-password" );
212 assertButtonWithIdPresent( "modal-login-ok" );
216 public void goToUserManagementPage()
218 getSelenium().open( "/archiva/security/userlist.action" );
219 assertUserManagementPage();
222 public void assertUserManagementPage()
224 assertPage( "Apache Archiva \\ [Admin] User List" );
225 assertTextPresent( "[Admin] List of Users in Role: Any" );
226 assertTextPresent( "Navigation" );
227 assertImgWithAlt( "First" );
228 assertImgWithAlt( "Prev" );
229 assertImgWithAlt( "Next" );
230 assertImgWithAlt( "Last" );
231 assertTextPresent( "Display Rows" );
232 assertTextPresent( "Username" );
233 assertTextPresent( "Full Name" );
234 assertTextPresent( "Email" );
235 assertTextPresent( "Permanent" );
236 assertTextPresent( "Validated" );
237 assertTextPresent( "Locked" );
238 assertTextPresent( "Tasks" );
239 assertTextPresent( "Tools" );
240 assertTextPresent( "Tasks" );
241 assertTextPresent( "The following tools are available for administrators to manipulate the user list." );
242 assertButtonWithValuePresent( "Create New User" );
243 assertButtonWithValuePresent( "Show Users In Role" );
244 assertElementPresent( "roleName" );
245 assertTextPresent( "Reports" );
246 assertTextPresent( "Name" );
247 assertTextPresent( "Types" );
248 assertTextPresent( "User List" );
249 assertTextPresent( "Roles Matrix" );
253 * //User Role public void goToUserRolesPage() { clickLinkWithText( "User Roles" ); assertUserRolesPage(); }
256 public void assertUserRolesPage()
258 //assertPage( "Apache Archiva \\ [Admin] User Edit" );
259 //[Admin] RĂ´les de l'utilisateur
261 assertTextPresent( "[Admin] User Roles", "[Admin] R\u00F4les de l'utilisateur" );
262 assertTextPresent( "Username", "Nom d'utilisateur" );
263 assertTextPresent( "Full Name", "Nom complet" );
265 "Guest,Registered User,System Administrator,User Administrator,Global Repository Observer,Global Repository Manager,Repository Observer,Repository Manager,internal";
266 String[] arrayRole = userRoles.split( "," );
267 for ( String userroles : arrayRole )
269 assertTextPresent( userroles );
273 public void assertDeleteUserPage( String username )
275 assertTextPresent( "[Admin] User Delete", "[Admin] Suppression de l'utilisateur",
276 "L'utilisateur suivant va \u00EAtre supprim\u00E9:" );
277 assertTextPresent( "The following user will be deleted:" );
278 assertTextPresent( "Username: " + username, "Nom d'utilisateur:" + username );
279 assertButtonWithIdPresent( "userDeleteSubmit" );
282 public void createUser( String userName, String fullName, String email, String password, boolean valid )
284 createUser( userName, fullName, email, password, password, valid );
287 private void createUser( String userName, String fullName, String emailAd, String password, String confirmPassword,
291 clickLinkWithLocator( "menu-users-list-a", true );
292 clickLinkWithLocator( "users-view-tabs-li-user-edit-a", true );
294 assertCreateUserPage();
295 setFieldValue( "username", userName );
296 setFieldValue( "fullname", fullName );
297 setFieldValue( "email", emailAd );
298 setFieldValue( "password", password );
299 setFieldValue( "confirmPassword", confirmPassword );
301 clickLinkWithLocator( "user-create-form-register-button", true );
303 assertTextPresent( "User " + userName + " created." );
304 assertElementPresent( "users-grid-user-id-" + userName );
308 //String[] columnValues = { userName, fullName, emailAd };
309 //assertElementPresent( XPathExpressionUtil.getTableRow( columnValues ) );
314 assertCreateUserPage();
318 public void deleteUser( String userName, String fullName, String emailAdd )
320 deleteUser( userName, fullName, emailAdd, false, false );
323 public void deleteUser( String userName, String fullName, String emailAd, boolean validated, boolean locked )
325 clickLinkWithLocator( "menu-users-list-a", true );
326 assertTextPresent( userName );
327 assertTextPresent( fullName );
329 clickLinkWithLocator( "users-grid-delete-" + userName );
331 clickLinkWithLocator( "dialog-confirm-modal-ok" );
332 assertTextPresent( "User " + userName + " deleted." );
334 clickLinkWithLocator( "alert-message-success-close-a" );
336 assertElementNotPresent( "users-grid-user-id-" + userName );
337 assertTextNotPresent( fullName );
342 public void login( String username, String password )
344 login( username, password, true, "Login Page" );
347 public void login( String username, String password, boolean valid, String assertReturnPage )
349 if ( isElementVisible( "login-link-a" ) )//isElementPresent( "loginLink" ) )
353 submitLoginPage( username, password, false, valid, assertReturnPage );
357 assertUserLoggedIn( username );
361 public void submitLoginPage( String username, String password )
363 submitLoginPage( username, password, false, true, "Login Page" );
366 public void submitLoginPage( String username, String password, boolean validUsernamePassword )
368 submitLoginPage( username, password, false, validUsernamePassword, "Login Page" );
371 public void submitLoginPage( String username, String password, boolean rememberMe, boolean validUsernamePassword,
372 String assertReturnPage )
374 clickLinkWithLocator( "login-link-a", false );
375 setFieldValue( "user-login-form-username", username );
376 setFieldValue( "user-login-form-password", password );
380 checkField( "rememberMe" );
383 clickButtonWithLocator( "modal-login-ok" );
384 if ( validUsernamePassword )
386 assertUserLoggedIn( username );
391 if ( "Login Page".equals( assertReturnPage ) )
397 assertPage( assertReturnPage );
402 protected void assertUserLoggedIn( String username )
404 Assert.assertFalse( isElementVisible( "login-link" ) );
405 Assert.assertTrue( isElementVisible( "logout-link" ) );
406 Assert.assertFalse( isElementVisible( "register-link" ) );
407 Assert.assertFalse( isElementVisible( "create-admin-link" ) );
411 public void assertUserRoleCheckBoxPresent( String value )
413 getSelenium().isElementPresent(
414 "xpath=//input[@id='addRolesToUser_addNDSelectedRoles' and @name='addNDSelectedRoles' and @value='" + value
418 public void assertResourceRolesCheckBoxPresent( String value )
420 getSelenium().isElementPresent( "xpath=//input[@name='addDSelectedRoles' and @value='" + value + "']" );
423 public void checkUserRoleWithValue( String value )
425 assertUserRoleCheckBoxPresent( value );
427 "xpath=//input[@id='addRolesToUser_addNDSelectedRoles' and @name='addNDSelectedRoles' and @value='" + value
431 public void checkResourceRoleWithValue( String value )
433 assertResourceRolesCheckBoxPresent( value );
434 getSelenium().click( "xpath=//input[@name='addDSelectedRoles' and @value='" + value + "']" );
437 public void changePassword( String oldPassword, String newPassword )
439 assertPage( "Apache Archiva \\ Change Password" );
440 setFieldValue( "existingPassword", oldPassword );
441 setFieldValue( "newPassword", newPassword );
442 setFieldValue( "newPasswordConfirm", newPassword );
443 clickButtonWithValue( "Change Password" );
446 public void assertCreateUserPage()
448 assertTextPresent( "Username" );
449 assertElementPresent( "username" );
450 assertTextPresent( "Full Name" );
451 assertElementPresent( "fullname" );
452 assertTextPresent( "Email Address" );
453 assertElementPresent( "email" );
454 assertTextPresent( "Password" );
455 assertElementPresent( "password" );
456 assertTextPresent( "Confirm Password" );
457 assertElementPresent( "confirmPassword" );
458 assertButtonWithIdPresent( "user-create-form-register-button" );
462 public void assertLeftNavMenuWithRole( String role )
464 if ( role.equals( "Guest" ) || role.equals( "Registered User" ) || role.equals( "Global Repository Observer" )
465 || role.equals( "Repository Observer - internal" ) || role.equals( "Repository Observer - snapshots" ) )
467 assertTextPresent( "Search" );
468 assertLinkPresent( "Find Artifact" );
469 assertLinkPresent( "Browse" );
470 assertLinkNotPresent( "Repositories" );
472 else if ( role.equals( "User Administrator" ) )
474 assertTextPresent( "Search" );
475 assertLinkPresent( "Find Artifact" );
476 assertLinkPresent( "Browse" );
477 assertLinkPresent( "User Management" );
478 assertLinkPresent( "User Roles" );
479 assertLinkNotPresent( "Repositories" );
481 else if ( role.equals( "Global Repository Manager" ) || role.equals( "Repository Manager - internal" )
482 || role.equals( "Repository Manager - snapshots" ) )
484 assertTextPresent( "Search" );
485 assertLinkPresent( "Find Artifact" );
486 assertLinkPresent( "Browse" );
487 assertLinkPresent( "Upload Artifact" );
488 assertLinkPresent( "Delete Artifact" );
489 assertLinkNotPresent( "Repositories" );
493 assertTextPresent( "Search" );
495 "Find Artifact,Browse,Reports,User Management,User Roles,Appearance,Upload Artifact,Delete Artifact,Repository Groups,Repositories,Proxy Connectors,Legacy Support,Network Proxies,Repository Scanning";
496 String[] arrayMenu = navMenu.split( "," );
497 for ( String navmenu : arrayMenu )
499 assertLinkPresent( navmenu );
505 public void goToFindArtifactPage()
507 getSelenium().open( "/archiva/findArtifact.action" );
508 assertFindArtifactPage();
511 public void assertFindArtifactPage()
513 //assertPage( "Apache Archiva \\ Find Artifact" );
514 assertElementPresent( "searchBox" );
515 //assertTextPresent( "Find Artifact" );
516 //assertTextPresent( "Search for:" );
517 //assertTextPresent( "Checksum:" );
518 assertElementPresent( "quickSearchBox" );
519 assertElementPresent( "checksumSearch" );
520 //assertButtonWithValuePresent( "Search" );
521 assertElementPresent( "checksumSearch_0" );
525 public void goToAppearancePage()
527 getSelenium().open( "/archiva/admin/configureAppearance.action" );
528 assertAppearancePage();
531 public void assertAppearancePage()
533 assertPage( "Apache Archiva \\ Configure Appearance" );
535 "Appearance,Organization Details,The logo in the top right of the screen is controlled by the following settings.,Organization Information,Name,URL,Logo URL";
536 String[] arrayAppearance = appearance.split( "," );
537 for ( String appear : arrayAppearance )
539 assertTextPresent( appear );
541 assertLinkPresent( "Edit" );
542 assertLinkPresent( "Change your appearance" );
545 public void addEditAppearance( String name, String url, String logoUrl, boolean wait )
547 setFieldValue( "organisationName", name );
548 setFieldValue( "organisationUrl", url );
549 setFieldValue( "organisationLogo", logoUrl );
550 clickButtonWithValue( "Save", wait );
553 public void goToHomePage()
555 getSelenium().open( baseUrl );
559 public void goToAddArtifactPage()
561 // must be logged as admin
562 getSelenium().open( "/archiva/upload.action" );
563 assertAddArtifactPage();
566 public void assertAddArtifactPage()
568 assertPage( "Apache Archiva \\ Upload Artifact" );
569 assertTextPresent( "Upload Artifact" );
572 "Upload Artifact,Group Id*:,Artifact Id*:,Version*:,Packaging*:,Classifier:,Generate Maven 2 POM,Artifact File*:,POM File:,Repository Id:";
573 String[] arrayArtifact = artifact.split( "," );
574 for ( String arrayartifact : arrayArtifact )
576 assertTextPresent( arrayartifact );
579 String artifactElements =
580 "upload_groupId,upload_artifactId,upload_version,upload_packaging,upload_classifier,upload_generatePom,upload_artifact,upload_pom,upload_repositoryId,uploadSubmit";
581 String[] arrayArtifactElements = artifactElements.split( "," );
582 for ( String artifactelements : arrayArtifactElements )
584 assertElementPresent( artifactelements );
588 public void addArtifact( String groupId, String artifactId, String version, String packaging,
589 String artifactFilePath, String repositoryId, boolean wait )
591 addArtifact( groupId, artifactId, version, packaging, true, artifactFilePath, repositoryId, wait );
594 public void addArtifact( String groupId, String artifactId, String version, String packaging, boolean generatePom,
595 String artifactFilePath, String repositoryId, boolean wait )
597 login( getProperty( "ADMIN_USERNAME" ), getProperty( "ADMIN_PASSWORD" ) );
598 goToAddArtifactPage();
599 setFieldValue( "groupId", groupId );
600 setFieldValue( "artifactId", artifactId );
601 setFieldValue( "version", version );
602 setFieldValue( "packaging", packaging );
606 checkField( "generatePom" );
610 if ( artifactFilePath != null && artifactFilePath.trim().length() > 0 )
612 File f = new File( artifactFilePath );
615 path = f.getCanonicalPath();
617 catch ( IOException e )
619 path = f.getAbsolutePath();
624 path = artifactFilePath;
627 setFieldValue( "artifact", path );
628 selectValue( "upload_repositoryId", repositoryId );
630 //clickButtonWithValue( "Submit" );
631 clickButtonWithLocator( "uploadSubmit", wait );
634 public void goToRepositoriesPage()
636 if ( !getTitle().equals( "Apache Archiva \\ Administration - Repositories" ) )
638 getSelenium().open( "/archiva/admin/repositories.action" );
640 assertRepositoriesPage();
643 public void assertRepositoriesPage()
645 assertPage( "Apache Archiva \\ Administration - Repositories" );
646 assertTextPresent( "Administration - Repositories" );
647 assertTextPresent( "Managed Repositories" );
648 assertTextPresent( "Remote Repositories" );
651 public void addManagedRepository( String identifier, String name, String directory, String indexDirectory,
652 String type, String cron, String daysOlder, String retentionCount, boolean wait )
654 // goToRepositoriesPage();
655 // clickLinkWithText( "Add" );
656 setFieldValue( "repository.id", identifier );
657 setFieldValue( "repository.name", name );
658 setFieldValue( "repository.location", directory );
659 setFieldValue( "repository.indexDirectory", indexDirectory );
660 selectValue( "repository.layout", type );
661 setFieldValue( "repository.cronExpression", cron );
662 setFieldValue( "repository.daysOlder", daysOlder );
663 setFieldValue( "repository.retentionCount", retentionCount );
665 clickButtonWithValue( "Add Repository", wait );
668 // artifact management
669 public void assertDeleteArtifactPage()
671 assertPage( "Apache Archiva \\ Delete Artifact" );
672 assertTextPresent( "Delete Artifact" );
673 assertTextPresent( "Group Id*:" );
674 assertTextPresent( "Artifact Id*:" );
675 assertTextPresent( "Version*:" );
676 assertTextPresent( "Repository Id:" );
677 assertElementPresent( "groupId" );
678 assertElementPresent( "artifactId" );
679 assertElementPresent( "version" );
680 assertElementPresent( "repositoryId" );
681 assertButtonWithValuePresent( "Submit" );
685 public void goToNetworkProxiesPage()
687 clickLinkWithText( "Network Proxies" );
688 assertNetworkProxiesPage();
691 public void assertNetworkProxiesPage()
693 assertPage( "Apache Archiva \\ Administration - Network Proxies" );
694 assertTextPresent( "Administration - Network Proxies" );
695 assertTextPresent( "Network Proxies" );
696 assertLinkPresent( "Add Network Proxy" );
699 public void addNetworkProxy( String identifier, String protocol, String hostname, String port, String username,
702 //goToNetworkProxiesPage();
703 clickLinkWithText( "Add Network Proxy" );
704 assertAddNetworkProxy();
705 setFieldValue( "proxy.id", identifier );
706 setFieldValue( "proxy.protocol", protocol );
707 setFieldValue( "proxy.host", hostname );
708 setFieldValue( "proxy.port", port );
709 setFieldValue( "proxy.username", username );
710 setFieldValue( "proxy.password", password );
711 clickButtonWithValue( "Save Network Proxy" );
714 public void assertAddNetworkProxy()
716 assertPage( "Apache Archiva \\ Admin: Add Network Proxy" );
717 assertTextPresent( "Admin: Add Network Proxy" );
718 assertTextPresent( "Add network proxy:" );
719 assertTextPresent( "Identifier*:" );
720 assertTextPresent( "Protocol*:" );
721 assertTextPresent( "Hostname*:" );
722 assertTextPresent( "Port*:" );
723 assertTextPresent( "Username:" );
724 assertTextPresent( "Password:" );
725 assertButtonWithValuePresent( "Save Network Proxy" );
729 public void goToLegacySupportPage()
731 getSelenium().open( "/archiva/admin/legacyArtifactPath.action" );
732 assertLegacySupportPage();
735 public void assertLegacySupportPage()
737 assertPage( "Apache Archiva \\ Administration - Legacy Support" );
738 assertTextPresent( "Administration - Legacy Artifact Path Resolution" );
739 assertTextPresent( "Path Mappings" );
740 assertLinkPresent( "Add" );
743 public void addLegacyArtifactPath( String path, String groupId, String artifactId, String version,
744 String classifier, String type, boolean wait )
746 assertAddLegacyArtifactPathPage();
747 setFieldValue( "legacyArtifactPath.path", path );
748 setFieldValue( "groupId", groupId );
749 setFieldValue( "artifactId", artifactId );
750 setFieldValue( "version", version );
751 setFieldValue( "classifier", classifier );
752 setFieldValue( "type", type );
753 clickButtonWithValue( "Add Legacy Artifact Path", wait );
756 public void assertAddLegacyArtifactPathPage()
758 assertPage( "Apache Archiva \\ Admin: Add Legacy Artifact Path" );
759 assertTextPresent( "Admin: Add Legacy Artifact Path" );
761 "Enter the legacy path to map to a particular artifact reference, then adjust the fields as necessary." );
763 "addLegacyArtifactPath_legacyArtifactPath_path,addLegacyArtifactPath_groupId,addLegacyArtifactPath_artifactId,addLegacyArtifactPath_version,addLegacyArtifactPath_classifier,addLegacyArtifactPath_type";
764 String[] arrayElement = element.split( "," );
765 for ( String arrayelement : arrayElement )
767 assertElementPresent( arrayelement );
769 assertButtonWithValuePresent( "Add Legacy Artifact Path" );
772 // add managed repository and its staging repository
773 public void addStagingRepository( String identifier, String name, String directory, String indexDirectory,
774 String type, String cron, String daysOlder, String retentionCount )
776 setFieldValue( "repository.id", identifier );
777 setFieldValue( "repository.name", name );
778 setFieldValue( "repository.location", directory );
779 setFieldValue( "repository.indexDirectory", indexDirectory );
780 selectValue( "repository.layout", type );
781 setFieldValue( "repository.cronExpression", cron );
782 setFieldValue( "repository.daysOlder", daysOlder );
783 setFieldValue( "repository.retentionCount", retentionCount );
784 checkField( "stageNeeded" );
786 clickButtonWithValue( "Add Repository" );
789 protected void logout()
791 clickLinkWithText( "Logout" );
792 assertTextNotPresent( "Current User:" );
793 assertLinkNotVisible( "Edit Details" );
794 assertLinkNotVisible( "Logout" );
795 assertLinkVisible( "Login" );
798 protected String getAdminUserName()
800 return getProperty( "ADMIN_FULLNAME" );