1 package org.apache.archiva.web.test.parent;
3 import org.testng.Assert;
4 import org.testng.annotations.AfterTest;
5 import org.testng.annotations.BeforeSuite;
6 import org.testng.annotations.BeforeTest;
7 import org.testng.annotations.Optional;
8 import org.testng.annotations.Parameters;
11 import java.io.IOException;
14 * Licensed to the Apache Software Foundation (ASF) under one
15 * or more contributor license agreements. See the NOTICE file
16 * distributed with this work for additional information
17 * regarding copyright ownership. The ASF licenses this file
18 * to you under the Apache License, Version 2.0 (the
19 * "License"); you may not use this file except in compliance
20 * with the License. You may obtain a copy of the License at
22 * http://www.apache.org/licenses/LICENSE-2.0
24 * Unless required by applicable law or agreed to in writing,
25 * software distributed under the License is distributed on an
26 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
27 * KIND, either express or implied. See the License for the
28 * specific language governing permissions and limitations
32 public abstract class AbstractArchivaTest
33 extends AbstractSeleniumTest
35 protected String username;
37 protected String fullname;
55 public void assertAdminCreated()
58 initializeArchiva( System.getProperty( "baseUrl" ), System.getProperty( "browser" ),
59 Integer.getInteger( "maxWaitTimeInMs" ), System.getProperty( "seleniumHost" ),
60 Integer.getInteger( "seleniumPort" ) );
64 @Parameters( { "baseUrl", "browser", "maxWaitTimeInMs", "seleniumHost", "seleniumPort" } )
65 public void initializeArchiva( String baseUrl, String browser, int maxWaitTimeInMs,
66 @Optional( "localhost" ) String seleniumHost, @Optional( "4444" ) int seleniumPort )
70 super.open( baseUrl, browser, seleniumHost, seleniumPort, Integer.toString( maxWaitTimeInMs ) );
72 getSelenium().open( baseUrl );
76 // if not admin user created create one
77 if ( isElementVisible( "create-admin-link" ) )
79 Assert.assertFalse( getSelenium().isVisible( "login-link-a" ) );
80 Assert.assertFalse( getSelenium().isVisible( "register-link-a" ) );
81 clickLinkWithLocator( "create-admin-link-a", false );
83 String fullname = getProperty( "ADMIN_FULLNAME" );
84 String username = getAdminUsername();
85 String mail = getProperty( "ADMIN_EMAIL" );
86 String password = getProperty( "ADMIN_PASSWORD" );
87 submitAdminData( fullname, mail, password );
88 assertUserLoggedIn( username );
89 clickLinkWithLocator( "logout-link-a" );
93 Assert.assertTrue( getSelenium().isVisible( "login-link-a" ) );
94 Assert.assertTrue( getSelenium().isVisible( "register-link-a" ) );
95 login( getAdminUsername(), getAdminPassword() );
100 protected static String getErrorMessageText()
102 return getSelenium().getText( "//ul[@class='errorMessage']/li/span" );
105 public String getUserEmail()
107 String email = getProperty( "USERROLE_EMAIL" );
111 public String getUserRolePassword()
113 String password = getProperty( "USERROLE_PASSWORD" );
117 public String getUserRoleNewPassword()
119 String password_new = getProperty( "NEW_USERROLE_PASSWORD" );
123 public String getBasedir()
125 String basedir = System.getProperty( "basedir" );
127 if ( basedir == null )
129 basedir = new File( "" ).getAbsolutePath();
135 public String getAdminUsername()
137 String adminUsername = getProperty( "ADMIN_USERNAME" );
138 return adminUsername;
141 public String getAdminPassword()
143 String adminPassword = getProperty( "ADMIN_PASSWORD" );
144 return adminPassword;
147 public void assertCreateAdmin()
149 assertElementPresent( "user-create" );
150 assertFieldValue( "admin", "username" );
151 assertElementPresent( "fullname" );
152 assertElementPresent( "password" );
153 assertElementPresent( "confirmPassword" );
154 assertElementPresent( "email" );
157 public void submitAdminData( String fullname, String email, String password )
159 setFieldValue( "fullname", fullname );
160 setFieldValue( "email", email );
161 setFieldValue( "password", password );
162 setFieldValue( "confirmPassword", password );
163 clickButtonWithLocator( "user-create-form-register-button" );
168 public void goToLoginPage()
170 getSelenium().open( baseUrl );
172 // are we already logged in ?
173 if ( isElementVisible( "logout-link" ) ) //isElementPresent( "logoutLink" ) )
176 clickLinkWithLocator( "logout-link-a", false );
177 clickLinkWithLocator( "login-link-a" );
179 else if ( isElementVisible( "login-link-a" ) )
181 clickLinkWithLocator( "login-link-a" );
186 public void submitUserData( String username, String password, boolean rememberme, boolean success )
189 setFieldValue( "username", username );
190 setFieldValue( "password", password );
193 checkField( "rememberMe" );
199 assertUserLoggedIn( username );
207 public void assertLoginModal()
209 assertElementPresent( "user-login-form" );
210 Assert.assertTrue( isElementVisible( "register-link" ) );
211 assertElementPresent( "user-login-form-username" );
212 assertElementPresent( "user-login-form-password" );
213 assertButtonWithIdPresent( "modal-login-ok" );
217 public void goToUserManagementPage()
219 getSelenium().open( "/archiva/security/userlist.action" );
220 assertUserManagementPage();
223 public void assertUserManagementPage()
225 assertPage( "Apache Archiva \\ [Admin] User List" );
226 assertTextPresent( "[Admin] List of Users in Role: Any" );
227 assertTextPresent( "Navigation" );
228 assertImgWithAlt( "First" );
229 assertImgWithAlt( "Prev" );
230 assertImgWithAlt( "Next" );
231 assertImgWithAlt( "Last" );
232 assertTextPresent( "Display Rows" );
233 assertTextPresent( "Username" );
234 assertTextPresent( "Full Name" );
235 assertTextPresent( "Email" );
236 assertTextPresent( "Permanent" );
237 assertTextPresent( "Validated" );
238 assertTextPresent( "Locked" );
239 assertTextPresent( "Tasks" );
240 assertTextPresent( "Tools" );
241 assertTextPresent( "Tasks" );
242 assertTextPresent( "The following tools are available for administrators to manipulate the user list." );
243 assertButtonWithValuePresent( "Create New User" );
244 assertButtonWithValuePresent( "Show Users In Role" );
245 assertElementPresent( "roleName" );
246 assertTextPresent( "Reports" );
247 assertTextPresent( "Name" );
248 assertTextPresent( "Types" );
249 assertTextPresent( "User List" );
250 assertTextPresent( "Roles Matrix" );
254 * //User Role public void goToUserRolesPage() { clickLinkWithText( "User Roles" ); assertUserRolesPage(); }
257 public void assertUserRolesPage()
259 //assertPage( "Apache Archiva \\ [Admin] User Edit" );
260 //[Admin] RĂ´les de l'utilisateur
262 assertTextPresent( "[Admin] User Roles", "[Admin] R\u00F4les de l'utilisateur" );
263 assertTextPresent( "Username", "Nom d'utilisateur" );
264 assertTextPresent( "Full Name", "Nom complet" );
266 "Guest,Registered User,System Administrator,User Administrator,Global Repository Observer,Global Repository Manager,Repository Observer,Repository Manager,internal";
267 String[] arrayRole = userRoles.split( "," );
268 for ( String userroles : arrayRole )
270 assertTextPresent( userroles );
274 public void assertDeleteUserPage( String username )
276 assertTextPresent( "[Admin] User Delete", "[Admin] Suppression de l'utilisateur",
277 "L'utilisateur suivant va \u00EAtre supprim\u00E9:" );
278 assertTextPresent( "The following user will be deleted:" );
279 assertTextPresent( "Username: " + username, "Nom d'utilisateur:" + username );
280 assertButtonWithIdPresent( "userDeleteSubmit" );
283 public void createUser( String userName, String fullName, String email, String password, boolean valid )
285 createUser( userName, fullName, email, password, password, valid );
288 private void createUser( String userName, String fullName, String emailAd, String password, String confirmPassword,
292 clickLinkWithLocator( "menu-users-list-a", true );
293 clickLinkWithLocator( "users-view-tabs-li-user-edit-a", true );
295 assertCreateUserPage();
296 setFieldValue( "username", userName );
297 setFieldValue( "fullname", fullName );
298 setFieldValue( "email", emailAd );
299 setFieldValue( "password", password );
300 setFieldValue( "confirmPassword", confirmPassword );
302 clickLinkWithLocator( "user-create-form-register-button", true );
304 assertTextPresent( "User " + userName + " created." );
305 assertElementPresent( "users-grid-user-id-" + userName );
309 //String[] columnValues = { userName, fullName, emailAd };
310 //assertElementPresent( XPathExpressionUtil.getTableRow( columnValues ) );
315 assertCreateUserPage();
319 public void deleteUser( String userName, String fullName, String emailAdd )
321 deleteUser( userName, fullName, emailAdd, false, false );
324 public void deleteUser( String userName, String fullName, String emailAd, boolean validated, boolean locked )
326 clickLinkWithLocator( "menu-users-list-a", true );
327 assertTextPresent( userName );
328 assertTextPresent( fullName );
330 clickLinkWithLocator( "users-grid-delete-" + userName );
332 clickLinkWithLocator( "dialog-confirm-modal-ok" );
333 assertTextPresent( "User " + userName + " deleted." );
335 clickLinkWithLocator( "alert-message-success-close-a" );
337 assertElementNotPresent( "users-grid-user-id-" + userName );
338 assertTextNotPresent( fullName );
343 public void login( String username, String password )
345 login( username, password, true, "Login Page" );
348 public void login( String username, String password, boolean valid, String assertReturnPage )
350 if ( isElementVisible( "login-link-a" ) )//isElementPresent( "loginLink" ) )
354 submitLoginPage( username, password, false, valid, assertReturnPage );
358 assertUserLoggedIn( username );
362 public void submitLoginPage( String username, String password )
364 submitLoginPage( username, password, false, true, "Login Page" );
367 public void submitLoginPage( String username, String password, boolean validUsernamePassword )
369 submitLoginPage( username, password, false, validUsernamePassword, "Login Page" );
372 public void submitLoginPage( String username, String password, boolean rememberMe, boolean validUsernamePassword,
373 String assertReturnPage )
375 clickLinkWithLocator( "login-link-a", false );
376 setFieldValue( "user-login-form-username", username );
377 setFieldValue( "user-login-form-password", password );
381 checkField( "rememberMe" );
384 clickButtonWithLocator( "modal-login-ok" );
385 if ( validUsernamePassword )
387 assertUserLoggedIn( username );
392 if ( "Login Page".equals( assertReturnPage ) )
398 assertPage( assertReturnPage );
403 protected void assertUserLoggedIn( String username )
405 Assert.assertFalse( isElementVisible( "login-link" ) );
406 Assert.assertTrue( isElementVisible( "logout-link" ) );
407 Assert.assertFalse( isElementVisible( "register-link" ) );
408 Assert.assertFalse( isElementVisible( "create-admin-link" ) );
412 public void assertUserRoleCheckBoxPresent( String value )
414 getSelenium().isElementPresent(
415 "xpath=//input[@id='addRolesToUser_addNDSelectedRoles' and @name='addNDSelectedRoles' and @value='" + value
419 public void assertResourceRolesCheckBoxPresent( String value )
421 getSelenium().isElementPresent( "xpath=//input[@name='addDSelectedRoles' and @value='" + value + "']" );
424 public void checkUserRoleWithValue( String value )
426 assertUserRoleCheckBoxPresent( value );
428 "xpath=//input[@id='addRolesToUser_addNDSelectedRoles' and @name='addNDSelectedRoles' and @value='" + value
432 public void checkResourceRoleWithValue( String value )
434 assertResourceRolesCheckBoxPresent( value );
435 getSelenium().click( "xpath=//input[@name='addDSelectedRoles' and @value='" + value + "']" );
438 public void changePassword( String oldPassword, String newPassword )
440 assertPage( "Apache Archiva \\ Change Password" );
441 setFieldValue( "existingPassword", oldPassword );
442 setFieldValue( "newPassword", newPassword );
443 setFieldValue( "newPasswordConfirm", newPassword );
444 clickButtonWithValue( "Change Password" );
447 public void assertCreateUserPage()
449 assertTextPresent( "Username" );
450 assertElementPresent( "username" );
451 assertTextPresent( "Full Name" );
452 assertElementPresent( "fullname" );
453 assertTextPresent( "Email Address" );
454 assertElementPresent( "email" );
455 assertTextPresent( "Password" );
456 assertElementPresent( "password" );
457 assertTextPresent( "Confirm Password" );
458 assertElementPresent( "confirmPassword" );
459 assertButtonWithIdPresent( "user-create-form-register-button" );
463 public void assertLeftNavMenuWithRole( String role )
465 if ( role.equals( "Guest" ) || role.equals( "Registered User" ) || role.equals( "Global Repository Observer" )
466 || role.equals( "Repository Observer - internal" ) || role.equals( "Repository Observer - snapshots" ) )
468 assertTextPresent( "Search" );
469 assertLinkPresent( "Find Artifact" );
470 assertLinkPresent( "Browse" );
471 assertLinkNotPresent( "Repositories" );
473 else if ( role.equals( "User Administrator" ) )
475 assertTextPresent( "Search" );
476 assertLinkPresent( "Find Artifact" );
477 assertLinkPresent( "Browse" );
478 assertLinkPresent( "User Management" );
479 assertLinkPresent( "User Roles" );
480 assertLinkNotPresent( "Repositories" );
482 else if ( role.equals( "Global Repository Manager" ) || role.equals( "Repository Manager - internal" )
483 || role.equals( "Repository Manager - snapshots" ) )
485 assertTextPresent( "Search" );
486 assertLinkPresent( "Find Artifact" );
487 assertLinkPresent( "Browse" );
488 assertLinkPresent( "Upload Artifact" );
489 assertLinkPresent( "Delete Artifact" );
490 assertLinkNotPresent( "Repositories" );
494 assertTextPresent( "Search" );
496 "Find Artifact,Browse,Reports,User Management,User Roles,Appearance,Upload Artifact,Delete Artifact,Repository Groups,Repositories,Proxy Connectors,Legacy Support,Network Proxies,Repository Scanning";
497 String[] arrayMenu = navMenu.split( "," );
498 for ( String navmenu : arrayMenu )
500 assertLinkPresent( navmenu );
506 public void goToFindArtifactPage()
508 getSelenium().open( "/archiva/findArtifact.action" );
509 assertFindArtifactPage();
512 public void assertFindArtifactPage()
514 //assertPage( "Apache Archiva \\ Find Artifact" );
515 assertElementPresent( "searchBox" );
516 //assertTextPresent( "Find Artifact" );
517 //assertTextPresent( "Search for:" );
518 //assertTextPresent( "Checksum:" );
519 assertElementPresent( "quickSearchBox" );
520 assertElementPresent( "checksumSearch" );
521 //assertButtonWithValuePresent( "Search" );
522 assertElementPresent( "checksumSearch_0" );
526 public void goToAppearancePage()
528 getSelenium().open( "/archiva/admin/configureAppearance.action" );
529 assertAppearancePage();
532 public void assertAppearancePage()
534 assertPage( "Apache Archiva \\ Configure Appearance" );
536 "Appearance,Organization Details,The logo in the top right of the screen is controlled by the following settings.,Organization Information,Name,URL,Logo URL";
537 String[] arrayAppearance = appearance.split( "," );
538 for ( String appear : arrayAppearance )
540 assertTextPresent( appear );
542 assertLinkPresent( "Edit" );
543 assertLinkPresent( "Change your appearance" );
546 public void addEditAppearance( String name, String url, String logoUrl, boolean wait )
548 setFieldValue( "organisationName", name );
549 setFieldValue( "organisationUrl", url );
550 setFieldValue( "organisationLogo", logoUrl );
551 clickButtonWithValue( "Save", wait );
554 public void goToHomePage()
556 getSelenium().open( baseUrl );
560 public void goToAddArtifactPage()
562 // must be logged as admin
563 getSelenium().open( "/archiva/upload.action" );
564 assertAddArtifactPage();
567 public void assertAddArtifactPage()
569 assertPage( "Apache Archiva \\ Upload Artifact" );
570 assertTextPresent( "Upload Artifact" );
573 "Upload Artifact,Group Id*:,Artifact Id*:,Version*:,Packaging*:,Classifier:,Generate Maven 2 POM,Artifact File*:,POM File:,Repository Id:";
574 String[] arrayArtifact = artifact.split( "," );
575 for ( String arrayartifact : arrayArtifact )
577 assertTextPresent( arrayartifact );
580 String artifactElements =
581 "upload_groupId,upload_artifactId,upload_version,upload_packaging,upload_classifier,upload_generatePom,upload_artifact,upload_pom,upload_repositoryId,uploadSubmit";
582 String[] arrayArtifactElements = artifactElements.split( "," );
583 for ( String artifactelements : arrayArtifactElements )
585 assertElementPresent( artifactelements );
589 public void addArtifact( String groupId, String artifactId, String version, String packaging,
590 String artifactFilePath, String repositoryId, boolean wait )
592 addArtifact( groupId, artifactId, version, packaging, true, artifactFilePath, repositoryId, wait );
595 public void addArtifact( String groupId, String artifactId, String version, String packaging, boolean generatePom,
596 String artifactFilePath, String repositoryId, boolean wait )
598 login( getProperty( "ADMIN_USERNAME" ), getProperty( "ADMIN_PASSWORD" ) );
599 goToAddArtifactPage();
600 setFieldValue( "groupId", groupId );
601 setFieldValue( "artifactId", artifactId );
602 setFieldValue( "version", version );
603 setFieldValue( "packaging", packaging );
607 checkField( "generatePom" );
611 if ( artifactFilePath != null && artifactFilePath.trim().length() > 0 )
613 File f = new File( artifactFilePath );
616 path = f.getCanonicalPath();
618 catch ( IOException e )
620 path = f.getAbsolutePath();
625 path = artifactFilePath;
628 setFieldValue( "artifact", path );
629 selectValue( "upload_repositoryId", repositoryId );
631 //clickButtonWithValue( "Submit" );
632 clickButtonWithLocator( "uploadSubmit", wait );
635 public void goToRepositoriesPage()
637 if ( !getTitle().equals( "Apache Archiva \\ Administration - Repositories" ) )
639 getSelenium().open( "/archiva/admin/repositories.action" );
641 assertRepositoriesPage();
644 public void assertRepositoriesPage()
646 assertPage( "Apache Archiva \\ Administration - Repositories" );
647 assertTextPresent( "Administration - Repositories" );
648 assertTextPresent( "Managed Repositories" );
649 assertTextPresent( "Remote Repositories" );
652 public void addManagedRepository( String identifier, String name, String directory, String indexDirectory,
653 String type, String cron, String daysOlder, String retentionCount, boolean wait )
655 // goToRepositoriesPage();
656 // clickLinkWithText( "Add" );
657 setFieldValue( "repository.id", identifier );
658 setFieldValue( "repository.name", name );
659 setFieldValue( "repository.location", directory );
660 setFieldValue( "repository.indexDirectory", indexDirectory );
661 selectValue( "repository.layout", type );
662 setFieldValue( "repository.cronExpression", cron );
663 setFieldValue( "repository.daysOlder", daysOlder );
664 setFieldValue( "repository.retentionCount", retentionCount );
666 clickButtonWithValue( "Add Repository", wait );
669 // artifact management
670 public void assertDeleteArtifactPage()
672 assertPage( "Apache Archiva \\ Delete Artifact" );
673 assertTextPresent( "Delete Artifact" );
674 assertTextPresent( "Group Id*:" );
675 assertTextPresent( "Artifact Id*:" );
676 assertTextPresent( "Version*:" );
677 assertTextPresent( "Repository Id:" );
678 assertElementPresent( "groupId" );
679 assertElementPresent( "artifactId" );
680 assertElementPresent( "version" );
681 assertElementPresent( "repositoryId" );
682 assertButtonWithValuePresent( "Submit" );
686 public void goToNetworkProxiesPage()
688 clickLinkWithText( "Network Proxies" );
689 assertNetworkProxiesPage();
692 public void assertNetworkProxiesPage()
694 assertPage( "Apache Archiva \\ Administration - Network Proxies" );
695 assertTextPresent( "Administration - Network Proxies" );
696 assertTextPresent( "Network Proxies" );
697 assertLinkPresent( "Add Network Proxy" );
700 public void addNetworkProxy( String identifier, String protocol, String hostname, String port, String username,
703 //goToNetworkProxiesPage();
704 clickLinkWithText( "Add Network Proxy" );
705 assertAddNetworkProxy();
706 setFieldValue( "proxy.id", identifier );
707 setFieldValue( "proxy.protocol", protocol );
708 setFieldValue( "proxy.host", hostname );
709 setFieldValue( "proxy.port", port );
710 setFieldValue( "proxy.username", username );
711 setFieldValue( "proxy.password", password );
712 clickButtonWithValue( "Save Network Proxy" );
715 public void assertAddNetworkProxy()
717 assertPage( "Apache Archiva \\ Admin: Add Network Proxy" );
718 assertTextPresent( "Admin: Add Network Proxy" );
719 assertTextPresent( "Add network proxy:" );
720 assertTextPresent( "Identifier*:" );
721 assertTextPresent( "Protocol*:" );
722 assertTextPresent( "Hostname*:" );
723 assertTextPresent( "Port*:" );
724 assertTextPresent( "Username:" );
725 assertTextPresent( "Password:" );
726 assertButtonWithValuePresent( "Save Network Proxy" );
730 public void goToLegacySupportPage()
732 getSelenium().open( "/archiva/admin/legacyArtifactPath.action" );
733 assertLegacySupportPage();
736 public void assertLegacySupportPage()
738 assertPage( "Apache Archiva \\ Administration - Legacy Support" );
739 assertTextPresent( "Administration - Legacy Artifact Path Resolution" );
740 assertTextPresent( "Path Mappings" );
741 assertLinkPresent( "Add" );
744 public void addLegacyArtifactPath( String path, String groupId, String artifactId, String version,
745 String classifier, String type, boolean wait )
747 assertAddLegacyArtifactPathPage();
748 setFieldValue( "legacyArtifactPath.path", path );
749 setFieldValue( "groupId", groupId );
750 setFieldValue( "artifactId", artifactId );
751 setFieldValue( "version", version );
752 setFieldValue( "classifier", classifier );
753 setFieldValue( "type", type );
754 clickButtonWithValue( "Add Legacy Artifact Path", wait );
757 public void assertAddLegacyArtifactPathPage()
759 assertPage( "Apache Archiva \\ Admin: Add Legacy Artifact Path" );
760 assertTextPresent( "Admin: Add Legacy Artifact Path" );
762 "Enter the legacy path to map to a particular artifact reference, then adjust the fields as necessary." );
764 "addLegacyArtifactPath_legacyArtifactPath_path,addLegacyArtifactPath_groupId,addLegacyArtifactPath_artifactId,addLegacyArtifactPath_version,addLegacyArtifactPath_classifier,addLegacyArtifactPath_type";
765 String[] arrayElement = element.split( "," );
766 for ( String arrayelement : arrayElement )
768 assertElementPresent( arrayelement );
770 assertButtonWithValuePresent( "Add Legacy Artifact Path" );
773 // add managed repository and its staging repository
774 public void addStagingRepository( String identifier, String name, String directory, String indexDirectory,
775 String type, String cron, String daysOlder, String retentionCount )
777 setFieldValue( "repository.id", identifier );
778 setFieldValue( "repository.name", name );
779 setFieldValue( "repository.location", directory );
780 setFieldValue( "repository.indexDirectory", indexDirectory );
781 selectValue( "repository.layout", type );
782 setFieldValue( "repository.cronExpression", cron );
783 setFieldValue( "repository.daysOlder", daysOlder );
784 setFieldValue( "repository.retentionCount", retentionCount );
785 checkField( "stageNeeded" );
787 clickButtonWithValue( "Add Repository" );
790 protected void logout()
792 clickLinkWithText( "Logout" );
793 assertTextNotPresent( "Current User:" );
794 assertLinkNotVisible( "Edit Details" );
795 assertLinkNotVisible( "Logout" );
796 assertLinkVisible( "Login" );
799 protected String getAdminUserName()
801 return getProperty( "ADMIN_FULLNAME" );