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 " + userName + " created." );
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" );
267 assertTextPresent( "User " + userName + " deleted." );
269 clickLinkWithLocator( "alert-message-success-close-a" );
271 assertElementNotPresent( "users-grid-user-id-" + userName );
272 assertTextNotPresent( fullName );
277 public void login( String username, String password )
279 login( username, password, true, "Login Page" );
282 public void login( String username, String password, boolean valid, String assertReturnPage )
284 if ( isElementVisible( "login-link-a" ) )//isElementPresent( "loginLink" ) )
288 submitLoginPage( username, password, false, valid, assertReturnPage );
292 assertUserLoggedIn( username );
296 public void submitLoginPage( String username, String password )
298 submitLoginPage( username, password, false, true, "Login Page" );
301 public void submitLoginPage( String username, String password, boolean validUsernamePassword )
303 submitLoginPage( username, password, false, validUsernamePassword, "Login Page" );
306 public void submitLoginPage( String username, String password, boolean rememberMe, boolean validUsernamePassword,
307 String assertReturnPage )
309 clickLinkWithLocator( "login-link-a", false );
310 setFieldValue( "user-login-form-username", username );
311 setFieldValue( "user-login-form-password", password );
315 checkField( "rememberMe" );
318 clickButtonWithLocator( "modal-login-ok" );
319 if ( validUsernamePassword )
321 assertUserLoggedIn( username );
326 if ( "Login Page".equals( assertReturnPage ) )
332 assertPage( assertReturnPage );
337 protected void assertUserLoggedIn( String username )
339 Assert.assertFalse( isElementVisible( "login-link" ) );
340 Assert.assertTrue( isElementVisible( "logout-link" ) );
341 Assert.assertFalse( isElementVisible( "register-link" ) );
342 Assert.assertFalse( isElementVisible( "create-admin-link" ) );
346 public void assertUserRoleCheckBoxPresent( String value )
348 getSelenium().isElementPresent(
349 "xpath=//input[@id='addRolesToUser_addNDSelectedRoles' and @name='addNDSelectedRoles' and @value='" + value
353 public void assertResourceRolesCheckBoxPresent( String value )
355 getSelenium().isElementPresent( "xpath=//input[@name='addDSelectedRoles' and @value='" + value + "']" );
358 public void checkUserRoleWithValue( String value )
360 assertUserRoleCheckBoxPresent( value );
362 "xpath=//input[@id='addRolesToUser_addNDSelectedRoles' and @name='addNDSelectedRoles' and @value='" + value
366 public void checkResourceRoleWithValue( String value )
368 assertResourceRolesCheckBoxPresent( value );
369 getSelenium().click( "xpath=//input[@name='addDSelectedRoles' and @value='" + value + "']" );
372 public void changePassword( String oldPassword, String newPassword )
374 assertPage( "Apache Archiva \\ Change Password" );
375 setFieldValue( "existingPassword", oldPassword );
376 setFieldValue( "newPassword", newPassword );
377 setFieldValue( "newPasswordConfirm", newPassword );
378 clickButtonWithValue( "Change Password" );
381 public void assertCreateUserPage()
383 assertTextPresent( "Username" );
384 assertElementPresent( "username" );
385 assertTextPresent( "Full Name" );
386 assertElementPresent( "fullname" );
387 assertTextPresent( "Email Address" );
388 assertElementPresent( "email" );
389 assertTextPresent( "Password" );
390 assertElementPresent( "password" );
391 assertTextPresent( "Confirm Password" );
392 assertElementPresent( "confirmPassword" );
393 assertButtonWithIdPresent( "user-create-form-register-button" );
397 public void assertLeftNavMenuWithRole( String role )
399 if ( role.equals( "Guest" ) || role.equals( "Registered User" ) || role.equals( "Global Repository Observer" )
400 || role.equals( "Repository Observer - internal" ) || role.equals( "Repository Observer - snapshots" ) )
402 assertTextPresent( "Search" );
403 assertLinkPresent( "Find Artifact" );
404 assertLinkPresent( "Browse" );
405 assertLinkNotPresent( "Repositories" );
407 else if ( role.equals( "User Administrator" ) )
409 assertTextPresent( "Search" );
410 assertLinkPresent( "Find Artifact" );
411 assertLinkPresent( "Browse" );
412 assertLinkPresent( "User Management" );
413 assertLinkPresent( "User Roles" );
414 assertLinkNotPresent( "Repositories" );
416 else if ( role.equals( "Global Repository Manager" ) || role.equals( "Repository Manager - internal" )
417 || role.equals( "Repository Manager - snapshots" ) )
419 assertTextPresent( "Search" );
420 assertLinkPresent( "Find Artifact" );
421 assertLinkPresent( "Browse" );
422 assertLinkPresent( "Upload Artifact" );
423 assertLinkPresent( "Delete Artifact" );
424 assertLinkNotPresent( "Repositories" );
428 assertTextPresent( "Search" );
430 "Find Artifact,Browse,Reports,User Management,User Roles,Appearance,Upload Artifact,Delete Artifact,Repository Groups,Repositories,Proxy Connectors,Legacy Support,Network Proxies,Repository Scanning";
431 String[] arrayMenu = navMenu.split( "," );
432 for ( String navmenu : arrayMenu )
434 assertLinkPresent( navmenu );
440 public void goToFindArtifactPage()
442 getSelenium().open( "/archiva/findArtifact.action" );
443 assertFindArtifactPage();
446 public void assertFindArtifactPage()
448 //assertPage( "Apache Archiva \\ Find Artifact" );
449 assertElementPresent( "searchBox" );
450 //assertTextPresent( "Find Artifact" );
451 //assertTextPresent( "Search for:" );
452 //assertTextPresent( "Checksum:" );
453 assertElementPresent( "quickSearchBox" );
454 assertElementPresent( "checksumSearch" );
455 //assertButtonWithValuePresent( "Search" );
456 assertElementPresent( "checksumSearch_0" );
460 public void goToAppearancePage()
462 getSelenium().open( "/archiva/admin/configureAppearance.action" );
463 assertAppearancePage();
466 public void assertAppearancePage()
468 assertPage( "Apache Archiva \\ Configure Appearance" );
470 "Appearance,Organization Details,The logo in the top right of the screen is controlled by the following settings.,Organization Information,Name,URL,Logo URL";
471 String[] arrayAppearance = appearance.split( "," );
472 for ( String appear : arrayAppearance )
474 assertTextPresent( appear );
476 assertLinkPresent( "Edit" );
477 assertLinkPresent( "Change your appearance" );
480 public void addEditAppearance( String name, String url, String logoUrl, boolean wait )
482 setFieldValue( "organisationName", name );
483 setFieldValue( "organisationUrl", url );
484 setFieldValue( "organisationLogo", logoUrl );
485 clickButtonWithValue( "Save", wait );
488 public void goToHomePage()
490 getSelenium().open( "" );
494 public void goToAddArtifactPage()
496 // must be logged as admin
497 getSelenium().open( "/archiva/upload.action" );
498 assertAddArtifactPage();
501 public void assertAddArtifactPage()
503 assertPage( "Apache Archiva \\ Upload Artifact" );
504 assertTextPresent( "Upload Artifact" );
507 "Upload Artifact,Group Id*:,Artifact Id*:,Version*:,Packaging*:,Classifier:,Generate Maven 2 POM,Artifact File*:,POM File:,Repository Id:";
508 String[] arrayArtifact = artifact.split( "," );
509 for ( String arrayartifact : arrayArtifact )
511 assertTextPresent( arrayartifact );
514 String artifactElements =
515 "upload_groupId,upload_artifactId,upload_version,upload_packaging,upload_classifier,upload_generatePom,upload_artifact,upload_pom,upload_repositoryId,uploadSubmit";
516 String[] arrayArtifactElements = artifactElements.split( "," );
517 for ( String artifactelements : arrayArtifactElements )
519 assertElementPresent( artifactelements );
523 public void addArtifact( String groupId, String artifactId, String version, String packaging,
524 String artifactFilePath, String repositoryId, boolean wait )
526 addArtifact( groupId, artifactId, version, packaging, true, artifactFilePath, repositoryId, wait );
529 public void addArtifact( String groupId, String artifactId, String version, String packaging, boolean generatePom,
530 String artifactFilePath, String repositoryId, boolean wait )
532 login( getProperty( "ADMIN_USERNAME" ), getProperty( "ADMIN_PASSWORD" ) );
533 goToAddArtifactPage();
534 setFieldValue( "groupId", groupId );
535 setFieldValue( "artifactId", artifactId );
536 setFieldValue( "version", version );
537 setFieldValue( "packaging", packaging );
541 checkField( "generatePom" );
545 if ( artifactFilePath != null && artifactFilePath.trim().length() > 0 )
547 File f = new File( artifactFilePath );
550 path = f.getCanonicalPath();
552 catch ( IOException e )
554 path = f.getAbsolutePath();
559 path = artifactFilePath;
562 setFieldValue( "artifact", path );
563 selectValue( "upload_repositoryId", repositoryId );
565 //clickButtonWithValue( "Submit" );
566 clickButtonWithLocator( "uploadSubmit", wait );
569 public void goToRepositoriesPage()
571 if ( !getTitle().equals( "Apache Archiva \\ Administration - Repositories" ) )
573 getSelenium().open( "/archiva/admin/repositories.action" );
575 assertRepositoriesPage();
578 public void assertRepositoriesPage()
580 assertPage( "Apache Archiva \\ Administration - Repositories" );
581 assertTextPresent( "Administration - Repositories" );
582 assertTextPresent( "Managed Repositories" );
583 assertTextPresent( "Remote Repositories" );
586 public void addManagedRepository( String identifier, String name, String directory, String indexDirectory,
587 String type, String cron, String daysOlder, String retentionCount, boolean wait )
589 // goToRepositoriesPage();
590 // clickLinkWithText( "Add" );
591 setFieldValue( "repository.id", identifier );
592 setFieldValue( "repository.name", name );
593 setFieldValue( "repository.location", directory );
594 setFieldValue( "repository.indexDirectory", indexDirectory );
595 selectValue( "repository.layout", type );
596 setFieldValue( "repository.cronExpression", cron );
597 setFieldValue( "repository.daysOlder", daysOlder );
598 setFieldValue( "repository.retentionCount", retentionCount );
600 clickButtonWithValue( "Add Repository", wait );
603 // artifact management
604 public void assertDeleteArtifactPage()
606 assertPage( "Apache Archiva \\ Delete Artifact" );
607 assertTextPresent( "Delete Artifact" );
608 assertTextPresent( "Group Id*:" );
609 assertTextPresent( "Artifact Id*:" );
610 assertTextPresent( "Version*:" );
611 assertTextPresent( "Repository Id:" );
612 assertElementPresent( "groupId" );
613 assertElementPresent( "artifactId" );
614 assertElementPresent( "version" );
615 assertElementPresent( "repositoryId" );
616 assertButtonWithValuePresent( "Submit" );
620 public void goToNetworkProxiesPage()
622 clickLinkWithText( "Network Proxies" );
623 assertNetworkProxiesPage();
626 public void assertNetworkProxiesPage()
628 assertPage( "Apache Archiva \\ Administration - Network Proxies" );
629 assertTextPresent( "Administration - Network Proxies" );
630 assertTextPresent( "Network Proxies" );
631 assertLinkPresent( "Add Network Proxy" );
634 public void addNetworkProxy( String identifier, String protocol, String hostname, String port, String username,
637 //goToNetworkProxiesPage();
638 clickLinkWithText( "Add Network Proxy" );
639 assertAddNetworkProxy();
640 setFieldValue( "proxy.id", identifier );
641 setFieldValue( "proxy.protocol", protocol );
642 setFieldValue( "proxy.host", hostname );
643 setFieldValue( "proxy.port", port );
644 setFieldValue( "proxy.username", username );
645 setFieldValue( "proxy.password", password );
646 clickButtonWithValue( "Save Network Proxy" );
649 public void assertAddNetworkProxy()
651 assertPage( "Apache Archiva \\ Admin: Add Network Proxy" );
652 assertTextPresent( "Admin: Add Network Proxy" );
653 assertTextPresent( "Add network proxy:" );
654 assertTextPresent( "Identifier*:" );
655 assertTextPresent( "Protocol*:" );
656 assertTextPresent( "Hostname*:" );
657 assertTextPresent( "Port*:" );
658 assertTextPresent( "Username:" );
659 assertTextPresent( "Password:" );
660 assertButtonWithValuePresent( "Save Network Proxy" );
664 public void goToLegacySupportPage()
666 getSelenium().open( "/archiva/admin/legacyArtifactPath.action" );
667 assertLegacySupportPage();
670 public void assertLegacySupportPage()
672 assertPage( "Apache Archiva \\ Administration - Legacy Support" );
673 assertTextPresent( "Administration - Legacy Artifact Path Resolution" );
674 assertTextPresent( "Path Mappings" );
675 assertLinkPresent( "Add" );
678 public void addLegacyArtifactPath( String path, String groupId, String artifactId, String version,
679 String classifier, String type, boolean wait )
681 assertAddLegacyArtifactPathPage();
682 setFieldValue( "legacyArtifactPath.path", path );
683 setFieldValue( "groupId", groupId );
684 setFieldValue( "artifactId", artifactId );
685 setFieldValue( "version", version );
686 setFieldValue( "classifier", classifier );
687 setFieldValue( "type", type );
688 clickButtonWithValue( "Add Legacy Artifact Path", wait );
691 public void assertAddLegacyArtifactPathPage()
693 assertPage( "Apache Archiva \\ Admin: Add Legacy Artifact Path" );
694 assertTextPresent( "Admin: Add Legacy Artifact Path" );
696 "Enter the legacy path to map to a particular artifact reference, then adjust the fields as necessary." );
698 "addLegacyArtifactPath_legacyArtifactPath_path,addLegacyArtifactPath_groupId,addLegacyArtifactPath_artifactId,addLegacyArtifactPath_version,addLegacyArtifactPath_classifier,addLegacyArtifactPath_type";
699 String[] arrayElement = element.split( "," );
700 for ( String arrayelement : arrayElement )
702 assertElementPresent( arrayelement );
704 assertButtonWithValuePresent( "Add Legacy Artifact Path" );
707 // add managed repository and its staging repository
708 public void addStagingRepository( String identifier, String name, String directory, String indexDirectory,
709 String type, String cron, String daysOlder, String retentionCount )
711 setFieldValue( "repository.id", identifier );
712 setFieldValue( "repository.name", name );
713 setFieldValue( "repository.location", directory );
714 setFieldValue( "repository.indexDirectory", indexDirectory );
715 selectValue( "repository.layout", type );
716 setFieldValue( "repository.cronExpression", cron );
717 setFieldValue( "repository.daysOlder", daysOlder );
718 setFieldValue( "repository.retentionCount", retentionCount );
719 checkField( "stageNeeded" );
721 clickButtonWithValue( "Add Repository" );
724 protected void logout()
726 clickLinkWithText( "Logout" );
727 assertTextNotPresent( "Current User:" );
728 assertLinkNotVisible( "Edit Details" );
729 assertLinkNotVisible( "Logout" );
730 assertLinkVisible( "Login" );