1 package org.apache.archiva.web.test.parent;
3 import org.testng.Assert;
6 import java.io.IOException;
9 * Licensed to the Apache Software Foundation (ASF) under one
10 * or more contributor license agreements. See the NOTICE file
11 * distributed with this work for additional information
12 * regarding copyright ownership. The ASF licenses this file
13 * to you under the Apache License, Version 2.0 (the
14 * "License"); you may not use this file except in compliance
15 * with the License. You may obtain a copy of the License at
17 * http://www.apache.org/licenses/LICENSE-2.0
19 * Unless required by applicable law or agreed to in writing,
20 * software distributed under the License is distributed on an
21 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
22 * KIND, either express or implied. See the License for the
23 * specific language governing permissions and limitations
27 public abstract class AbstractArchivaTest
28 extends AbstractSeleniumTest
30 protected String username;
32 protected String fullname;
34 protected static String getErrorMessageText()
36 return getSelenium().getText( "//ul[@class='errorMessage']/li/span" );
39 public String getUserEmail()
41 String email = getProperty( "USERROLE_EMAIL" );
45 public String getUserRolePassword()
47 String password = getProperty( "USERROLE_PASSWORD" );
51 public String getUserRoleNewPassword()
53 String password_new = getProperty( "NEW_USERROLE_PASSWORD" );
57 public String getBasedir()
59 String basedir = System.getProperty( "basedir" );
61 if ( basedir == null )
63 basedir = new File( "" ).getAbsolutePath();
69 public String getAdminUsername()
71 String adminUsername = getProperty( "ADMIN_USERNAME" );
75 public String getAdminPassword()
77 String adminPassword = getProperty( "ADMIN_PASSWORD" );
81 public void assertCreateAdmin()
83 assertElementPresent( "user-create" );
84 assertFieldValue( "admin", "username" );
85 assertElementPresent( "fullname" );
86 assertElementPresent( "password" );
87 assertElementPresent( "confirmPassword" );
88 assertElementPresent( "email" );
91 public void submitAdminData( String fullname, String email, String password )
93 setFieldValue( "fullname", fullname );
94 setFieldValue( "email", email );
95 setFieldValue( "password", password );
96 setFieldValue( "confirmPassword", password );
97 clickButtonWithLocator( "user-create-form-register-button" );
102 public void goToLoginPage()
104 getSelenium().open( baseUrl );
106 // are we already logged in ?
107 if ( isElementVisible( "logout-link" ) ) //isElementPresent( "logoutLink" ) )
110 clickLinkWithLocator( "logout-link-a", false );
111 clickLinkWithLocator( "login-link-a" );
113 else if ( isElementVisible( "login-link-a" ) )
115 clickLinkWithLocator( "login-link-a" );
120 public void submitUserData( String username, String password, boolean rememberme, boolean success )
123 setFieldValue( "username", username );
124 setFieldValue( "password", password );
127 checkField( "rememberMe" );
133 assertUserLoggedIn( username );
141 public void assertLoginModal()
143 assertElementPresent( "user-login-form" );
144 Assert.assertTrue( isElementVisible( "register-link" ) );
145 assertElementPresent( "user-login-form-username" );
146 assertElementPresent( "user-login-form-password" );
147 assertButtonWithIdPresent( "modal-login-ok" );
151 public void goToUserManagementPage()
153 getSelenium().open( "/archiva/security/userlist.action" );
154 assertUserManagementPage();
157 public void assertUserManagementPage()
159 assertPage( "Apache Archiva \\ [Admin] User List" );
160 assertTextPresent( "[Admin] List of Users in Role: Any" );
161 assertTextPresent( "Navigation" );
162 assertImgWithAlt( "First" );
163 assertImgWithAlt( "Prev" );
164 assertImgWithAlt( "Next" );
165 assertImgWithAlt( "Last" );
166 assertTextPresent( "Display Rows" );
167 assertTextPresent( "Username" );
168 assertTextPresent( "Full Name" );
169 assertTextPresent( "Email" );
170 assertTextPresent( "Permanent" );
171 assertTextPresent( "Validated" );
172 assertTextPresent( "Locked" );
173 assertTextPresent( "Tasks" );
174 assertTextPresent( "Tools" );
175 assertTextPresent( "Tasks" );
176 assertTextPresent( "The following tools are available for administrators to manipulate the user list." );
177 assertButtonWithValuePresent( "Create New User" );
178 assertButtonWithValuePresent( "Show Users In Role" );
179 assertElementPresent( "roleName" );
180 assertTextPresent( "Reports" );
181 assertTextPresent( "Name" );
182 assertTextPresent( "Types" );
183 assertTextPresent( "User List" );
184 assertTextPresent( "Roles Matrix" );
188 * //User Role public void goToUserRolesPage() { clickLinkWithText( "User Roles" ); assertUserRolesPage(); }
191 public void assertUserRolesPage()
193 //assertPage( "Apache Archiva \\ [Admin] User Edit" );
194 //[Admin] RĂ´les de l'utilisateur
196 assertTextPresent( "[Admin] User Roles", "[Admin] R\u00F4les de l'utilisateur" );
197 assertTextPresent( "Username", "Nom d'utilisateur" );
198 assertTextPresent( "Full Name", "Nom complet" );
200 "Guest,Registered User,System Administrator,User Administrator,Global Repository Observer,Global Repository Manager,Repository Observer,Repository Manager,internal";
201 String[] arrayRole = userRoles.split( "," );
202 for ( String userroles : arrayRole )
204 assertTextPresent( userroles );
208 public void assertDeleteUserPage( String username )
210 assertTextPresent( "[Admin] User Delete", "[Admin] Suppression de l'utilisateur",
211 "L'utilisateur suivant va \u00EAtre supprim\u00E9:" );
212 assertTextPresent( "The following user will be deleted:" );
213 assertTextPresent( "Username: " + username, "Nom d'utilisateur:" + username );
214 assertButtonWithIdPresent( "userDeleteSubmit" );
217 public void createUser( String userName, String fullName, String email, String password, boolean valid )
219 createUser( userName, fullName, email, password, password, valid );
222 private void createUser( String userName, String fullName, String emailAd, String password, String confirmPassword,
226 clickLinkWithLocator( "menu-users-list-a", true );
227 clickLinkWithLocator( "users-view-tabs-li-user-edit-a", true );
229 assertCreateUserPage();
230 setFieldValue( "username", userName );
231 setFieldValue( "fullname", fullName );
232 setFieldValue( "email", emailAd );
233 setFieldValue( "password", password );
234 setFieldValue( "confirmPassword", confirmPassword );
236 clickLinkWithLocator( "user-create-form-register-button", true );
238 assertTextPresent( "user created:"+userName );
239 assertElementPresent( "users-grid-user-id-"+userName );
243 //String[] columnValues = { userName, fullName, emailAd };
244 //assertElementPresent( XPathExpressionUtil.getTableRow( columnValues ) );
249 assertCreateUserPage();
253 public void deleteUser( String userName, String fullName, String emailAdd )
255 deleteUser( userName, fullName, emailAdd, false, false );
258 public void deleteUser( String userName, String fullName, String emailAd, boolean validated, boolean locked )
260 clickLinkWithLocator( "menu-users-list-a", true );
261 assertTextPresent( userName );
262 assertTextPresent( fullName );
264 clickLinkWithLocator( "users-grid-delete-" + userName );
266 clickLinkWithLocator( "dialog-confirm-modal-ok" );
268 assertTextPresent( "user " + userName + " deleted" );
270 clickLinkWithLocator( "alert-message-success-close-a" );
272 assertElementNotPresent( "users-grid-user-id-"+userName );
273 assertTextNotPresent( fullName );
278 public void login( String username, String password )
280 login( username, password, true, "Login Page" );
283 public void login( String username, String password, boolean valid, String assertReturnPage )
285 if ( isElementVisible( "login-link-a" ) )//isElementPresent( "loginLink" ) )
289 submitLoginPage( username, password, false, valid, assertReturnPage );
293 assertUserLoggedIn( username );
297 public void submitLoginPage( String username, String password )
299 submitLoginPage( username, password, false, true, "Login Page" );
302 public void submitLoginPage( String username, String password, boolean validUsernamePassword )
304 submitLoginPage( username, password, false, validUsernamePassword, "Login Page" );
307 public void submitLoginPage( String username, String password, boolean rememberMe, boolean validUsernamePassword,
308 String assertReturnPage )
310 clickLinkWithLocator( "login-link-a", false );
311 setFieldValue( "user-login-form-username", username );
312 setFieldValue( "user-login-form-password", password );
316 checkField( "rememberMe" );
319 clickButtonWithLocator( "modal-login-ok" );
320 if ( validUsernamePassword )
322 assertUserLoggedIn( username );
327 if ( "Login Page".equals( assertReturnPage ) )
333 assertPage( assertReturnPage );
338 protected void assertUserLoggedIn( String username )
340 Assert.assertFalse( isElementVisible( "login-link" ) );
341 Assert.assertTrue( isElementVisible( "logout-link" ) );
342 Assert.assertFalse( isElementVisible( "register-link" ) );
343 Assert.assertFalse( isElementVisible( "create-admin-link" ) );
347 public void assertUserRoleCheckBoxPresent( String value )
349 getSelenium().isElementPresent(
350 "xpath=//input[@id='addRolesToUser_addNDSelectedRoles' and @name='addNDSelectedRoles' and @value='" + value
354 public void assertResourceRolesCheckBoxPresent( String value )
356 getSelenium().isElementPresent( "xpath=//input[@name='addDSelectedRoles' and @value='" + value + "']" );
359 public void checkUserRoleWithValue( String value )
361 assertUserRoleCheckBoxPresent( value );
363 "xpath=//input[@id='addRolesToUser_addNDSelectedRoles' and @name='addNDSelectedRoles' and @value='" + value
367 public void checkResourceRoleWithValue( String value )
369 assertResourceRolesCheckBoxPresent( value );
370 getSelenium().click( "xpath=//input[@name='addDSelectedRoles' and @value='" + value + "']" );
373 public void changePassword( String oldPassword, String newPassword )
375 assertPage( "Apache Archiva \\ Change Password" );
376 setFieldValue( "existingPassword", oldPassword );
377 setFieldValue( "newPassword", newPassword );
378 setFieldValue( "newPasswordConfirm", newPassword );
379 clickButtonWithValue( "Change Password" );
382 public void assertCreateUserPage()
384 assertTextPresent( "Username" );
385 assertElementPresent( "username" );
386 assertTextPresent( "Full Name" );
387 assertElementPresent( "fullname" );
388 assertTextPresent( "Email Address" );
389 assertElementPresent( "email" );
390 assertTextPresent( "Password" );
391 assertElementPresent( "password" );
392 assertTextPresent( "Confirm Password" );
393 assertElementPresent( "confirmPassword" );
394 assertButtonWithIdPresent( "user-create-form-register-button" );
398 public void assertLeftNavMenuWithRole( String role )
400 if ( role.equals( "Guest" ) || role.equals( "Registered User" ) || role.equals( "Global Repository Observer" )
401 || role.equals( "Repository Observer - internal" ) || role.equals( "Repository Observer - snapshots" ) )
403 assertTextPresent( "Search" );
404 assertLinkPresent( "Find Artifact" );
405 assertLinkPresent( "Browse" );
406 assertLinkNotPresent( "Repositories" );
408 else if ( role.equals( "User Administrator" ) )
410 assertTextPresent( "Search" );
411 assertLinkPresent( "Find Artifact" );
412 assertLinkPresent( "Browse" );
413 assertLinkPresent( "User Management" );
414 assertLinkPresent( "User Roles" );
415 assertLinkNotPresent( "Repositories" );
417 else if ( role.equals( "Global Repository Manager" ) || role.equals( "Repository Manager - internal" )
418 || role.equals( "Repository Manager - snapshots" ) )
420 assertTextPresent( "Search" );
421 assertLinkPresent( "Find Artifact" );
422 assertLinkPresent( "Browse" );
423 assertLinkPresent( "Upload Artifact" );
424 assertLinkPresent( "Delete Artifact" );
425 assertLinkNotPresent( "Repositories" );
429 assertTextPresent( "Search" );
431 "Find Artifact,Browse,Reports,User Management,User Roles,Appearance,Upload Artifact,Delete Artifact,Repository Groups,Repositories,Proxy Connectors,Legacy Support,Network Proxies,Repository Scanning";
432 String[] arrayMenu = navMenu.split( "," );
433 for ( String navmenu : arrayMenu )
435 assertLinkPresent( navmenu );
441 public void goToFindArtifactPage()
443 getSelenium().open( "/archiva/findArtifact.action" );
444 assertFindArtifactPage();
447 public void assertFindArtifactPage()
449 //assertPage( "Apache Archiva \\ Find Artifact" );
450 assertElementPresent( "searchBox" );
451 //assertTextPresent( "Find Artifact" );
452 //assertTextPresent( "Search for:" );
453 //assertTextPresent( "Checksum:" );
454 assertElementPresent( "quickSearchBox" );
455 assertElementPresent( "checksumSearch" );
456 //assertButtonWithValuePresent( "Search" );
457 assertElementPresent( "checksumSearch_0" );
461 public void goToAppearancePage()
463 getSelenium().open( "/archiva/admin/configureAppearance.action" );
464 assertAppearancePage();
467 public void assertAppearancePage()
469 assertPage( "Apache Archiva \\ Configure Appearance" );
471 "Appearance,Organization Details,The logo in the top right of the screen is controlled by the following settings.,Organization Information,Name,URL,Logo URL";
472 String[] arrayAppearance = appearance.split( "," );
473 for ( String appear : arrayAppearance )
475 assertTextPresent( appear );
477 assertLinkPresent( "Edit" );
478 assertLinkPresent( "Change your appearance" );
481 public void addEditAppearance( String name, String url, String logoUrl, boolean wait )
483 setFieldValue( "organisationName", name );
484 setFieldValue( "organisationUrl", url );
485 setFieldValue( "organisationLogo", logoUrl );
486 clickButtonWithValue( "Save", wait );
489 public void goToHomePage()
491 getSelenium().open( "" );
495 public void goToAddArtifactPage()
497 // must be logged as admin
498 getSelenium().open( "/archiva/upload.action" );
499 assertAddArtifactPage();
502 public void assertAddArtifactPage()
504 assertPage( "Apache Archiva \\ Upload Artifact" );
505 assertTextPresent( "Upload Artifact" );
508 "Upload Artifact,Group Id*:,Artifact Id*:,Version*:,Packaging*:,Classifier:,Generate Maven 2 POM,Artifact File*:,POM File:,Repository Id:";
509 String[] arrayArtifact = artifact.split( "," );
510 for ( String arrayartifact : arrayArtifact )
512 assertTextPresent( arrayartifact );
515 String artifactElements =
516 "upload_groupId,upload_artifactId,upload_version,upload_packaging,upload_classifier,upload_generatePom,upload_artifact,upload_pom,upload_repositoryId,uploadSubmit";
517 String[] arrayArtifactElements = artifactElements.split( "," );
518 for ( String artifactelements : arrayArtifactElements )
520 assertElementPresent( artifactelements );
524 public void addArtifact( String groupId, String artifactId, String version, String packaging,
525 String artifactFilePath, String repositoryId, boolean wait )
527 addArtifact( groupId, artifactId, version, packaging, true, artifactFilePath, repositoryId, wait );
530 public void addArtifact( String groupId, String artifactId, String version, String packaging, boolean generatePom,
531 String artifactFilePath, String repositoryId, boolean wait )
533 login( getProperty( "ADMIN_USERNAME" ), getProperty( "ADMIN_PASSWORD" ) );
534 goToAddArtifactPage();
535 setFieldValue( "groupId", groupId );
536 setFieldValue( "artifactId", artifactId );
537 setFieldValue( "version", version );
538 setFieldValue( "packaging", packaging );
542 checkField( "generatePom" );
546 if ( artifactFilePath != null && artifactFilePath.trim().length() > 0 )
548 File f = new File( artifactFilePath );
551 path = f.getCanonicalPath();
553 catch ( IOException e )
555 path = f.getAbsolutePath();
560 path = artifactFilePath;
563 setFieldValue( "artifact", path );
564 selectValue( "upload_repositoryId", repositoryId );
566 //clickButtonWithValue( "Submit" );
567 clickButtonWithLocator( "uploadSubmit", wait );
570 public void goToRepositoriesPage()
572 if ( !getTitle().equals( "Apache Archiva \\ Administration - Repositories" ) )
574 getSelenium().open( "/archiva/admin/repositories.action" );
576 assertRepositoriesPage();
579 public void assertRepositoriesPage()
581 assertPage( "Apache Archiva \\ Administration - Repositories" );
582 assertTextPresent( "Administration - Repositories" );
583 assertTextPresent( "Managed Repositories" );
584 assertTextPresent( "Remote Repositories" );
587 public void addManagedRepository( String identifier, String name, String directory, String indexDirectory,
588 String type, String cron, String daysOlder, String retentionCount, boolean wait )
590 // goToRepositoriesPage();
591 // clickLinkWithText( "Add" );
592 setFieldValue( "repository.id", identifier );
593 setFieldValue( "repository.name", name );
594 setFieldValue( "repository.location", directory );
595 setFieldValue( "repository.indexDirectory", indexDirectory );
596 selectValue( "repository.layout", type );
597 setFieldValue( "repository.cronExpression", cron );
598 setFieldValue( "repository.daysOlder", daysOlder );
599 setFieldValue( "repository.retentionCount", retentionCount );
601 clickButtonWithValue( "Add Repository", wait );
604 // artifact management
605 public void assertDeleteArtifactPage()
607 assertPage( "Apache Archiva \\ Delete Artifact" );
608 assertTextPresent( "Delete Artifact" );
609 assertTextPresent( "Group Id*:" );
610 assertTextPresent( "Artifact Id*:" );
611 assertTextPresent( "Version*:" );
612 assertTextPresent( "Repository Id:" );
613 assertElementPresent( "groupId" );
614 assertElementPresent( "artifactId" );
615 assertElementPresent( "version" );
616 assertElementPresent( "repositoryId" );
617 assertButtonWithValuePresent( "Submit" );
621 public void goToNetworkProxiesPage()
623 clickLinkWithText( "Network Proxies" );
624 assertNetworkProxiesPage();
627 public void assertNetworkProxiesPage()
629 assertPage( "Apache Archiva \\ Administration - Network Proxies" );
630 assertTextPresent( "Administration - Network Proxies" );
631 assertTextPresent( "Network Proxies" );
632 assertLinkPresent( "Add Network Proxy" );
635 public void addNetworkProxy( String identifier, String protocol, String hostname, String port, String username,
638 //goToNetworkProxiesPage();
639 clickLinkWithText( "Add Network Proxy" );
640 assertAddNetworkProxy();
641 setFieldValue( "proxy.id", identifier );
642 setFieldValue( "proxy.protocol", protocol );
643 setFieldValue( "proxy.host", hostname );
644 setFieldValue( "proxy.port", port );
645 setFieldValue( "proxy.username", username );
646 setFieldValue( "proxy.password", password );
647 clickButtonWithValue( "Save Network Proxy" );
650 public void assertAddNetworkProxy()
652 assertPage( "Apache Archiva \\ Admin: Add Network Proxy" );
653 assertTextPresent( "Admin: Add Network Proxy" );
654 assertTextPresent( "Add network proxy:" );
655 assertTextPresent( "Identifier*:" );
656 assertTextPresent( "Protocol*:" );
657 assertTextPresent( "Hostname*:" );
658 assertTextPresent( "Port*:" );
659 assertTextPresent( "Username:" );
660 assertTextPresent( "Password:" );
661 assertButtonWithValuePresent( "Save Network Proxy" );
665 public void goToLegacySupportPage()
667 getSelenium().open( "/archiva/admin/legacyArtifactPath.action" );
668 assertLegacySupportPage();
671 public void assertLegacySupportPage()
673 assertPage( "Apache Archiva \\ Administration - Legacy Support" );
674 assertTextPresent( "Administration - Legacy Artifact Path Resolution" );
675 assertTextPresent( "Path Mappings" );
676 assertLinkPresent( "Add" );
679 public void addLegacyArtifactPath( String path, String groupId, String artifactId, String version,
680 String classifier, String type, boolean wait )
682 assertAddLegacyArtifactPathPage();
683 setFieldValue( "legacyArtifactPath.path", path );
684 setFieldValue( "groupId", groupId );
685 setFieldValue( "artifactId", artifactId );
686 setFieldValue( "version", version );
687 setFieldValue( "classifier", classifier );
688 setFieldValue( "type", type );
689 clickButtonWithValue( "Add Legacy Artifact Path", wait );
692 public void assertAddLegacyArtifactPathPage()
694 assertPage( "Apache Archiva \\ Admin: Add Legacy Artifact Path" );
695 assertTextPresent( "Admin: Add Legacy Artifact Path" );
697 "Enter the legacy path to map to a particular artifact reference, then adjust the fields as necessary." );
699 "addLegacyArtifactPath_legacyArtifactPath_path,addLegacyArtifactPath_groupId,addLegacyArtifactPath_artifactId,addLegacyArtifactPath_version,addLegacyArtifactPath_classifier,addLegacyArtifactPath_type";
700 String[] arrayElement = element.split( "," );
701 for ( String arrayelement : arrayElement )
703 assertElementPresent( arrayelement );
705 assertButtonWithValuePresent( "Add Legacy Artifact Path" );
708 // add managed repository and its staging repository
709 public void addStagingRepository( String identifier, String name, String directory, String indexDirectory,
710 String type, String cron, String daysOlder, String retentionCount )
712 setFieldValue( "repository.id", identifier );
713 setFieldValue( "repository.name", name );
714 setFieldValue( "repository.location", directory );
715 setFieldValue( "repository.indexDirectory", indexDirectory );
716 selectValue( "repository.layout", type );
717 setFieldValue( "repository.cronExpression", cron );
718 setFieldValue( "repository.daysOlder", daysOlder );
719 setFieldValue( "repository.retentionCount", retentionCount );
720 checkField( "stageNeeded" );
722 clickButtonWithValue( "Add Repository" );
725 protected void logout()
727 clickLinkWithText( "Logout" );
728 assertTextNotPresent( "Current User:" );
729 assertLinkNotVisible( "Edit Details" );
730 assertLinkNotVisible( "Logout" );
731 assertLinkVisible( "Login" );