1 package org.apache.archiva.web.test.parent;
3 import org.apache.archiva.web.test.tools.ArchivaSeleniumRunner;
4 import org.junit.Before;
5 import org.junit.runner.RunWith;
8 import java.io.IOException;
11 * Licensed to the Apache Software Foundation (ASF) under one
12 * or more contributor license agreements. See the NOTICE file
13 * distributed with this work for additional information
14 * regarding copyright ownership. The ASF licenses this file
15 * to you under the Apache License, Version 2.0 (the
16 * "License"); you may not use this file except in compliance
17 * with the License. You may obtain a copy of the License at
19 * http://www.apache.org/licenses/LICENSE-2.0
21 * Unless required by applicable law or agreed to in writing,
22 * software distributed under the License is distributed on an
23 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
24 * KIND, either express or implied. See the License for the
25 * specific language governing permissions and limitations
29 @RunWith( ArchivaSeleniumRunner.class )
30 public abstract class AbstractArchivaTest
31 extends AbstractSeleniumTest
33 protected String username;
35 protected String fullname;
47 protected static String getErrorMessageText()
49 return getSelenium().getText( "//ul[@class='errorMessage']/li/span" );
52 public String getUserEmail()
54 String email = getProperty( "USERROLE_EMAIL" );
58 public String getUserRolePassword()
60 String password = getProperty( "USERROLE_PASSWORD" );
64 public String getUserRoleNewPassword()
66 String password_new = getProperty( "NEW_USERROLE_PASSWORD" );
70 public String getBasedir()
72 String basedir = System.getProperty( "basedir" );
74 if ( basedir == null )
76 basedir = new File( "" ).getAbsolutePath();
83 public void submitUserData( String username, String password, boolean rememberme, boolean success )
86 setFieldValue( "username", username );
87 setFieldValue( "password", password );
90 checkField( "rememberMe" );
96 assertUserLoggedIn( username );
105 public void goToUserManagementPage()
107 getSelenium().open( "/archiva/security/userlist.action" );
108 assertUserManagementPage();
111 public void assertUserManagementPage()
113 assertPage( "Apache Archiva \\ [Admin] User List" );
114 assertTextPresent( "[Admin] List of Users in Role: Any" );
115 assertTextPresent( "Navigation" );
116 assertImgWithAlt( "First" );
117 assertImgWithAlt( "Prev" );
118 assertImgWithAlt( "Next" );
119 assertImgWithAlt( "Last" );
120 assertTextPresent( "Display Rows" );
121 assertTextPresent( "Username" );
122 assertTextPresent( "Full Name" );
123 assertTextPresent( "Email" );
124 assertTextPresent( "Permanent" );
125 assertTextPresent( "Validated" );
126 assertTextPresent( "Locked" );
127 assertTextPresent( "Tasks" );
128 assertTextPresent( "Tools" );
129 assertTextPresent( "Tasks" );
130 assertTextPresent( "The following tools are available for administrators to manipulate the user list." );
131 assertButtonWithValuePresent( "Create New User" );
132 assertButtonWithValuePresent( "Show Users In Role" );
133 assertElementPresent( "roleName" );
134 assertTextPresent( "Reports" );
135 assertTextPresent( "Name" );
136 assertTextPresent( "Types" );
137 assertTextPresent( "User List" );
138 assertTextPresent( "Roles Matrix" );
142 * //User Role public void goToUserRolesPage() { clickLinkWithText( "User Roles" ); assertUserRolesPage(); }
145 public void assertUserRolesPage()
147 //assertPage( "Apache Archiva \\ [Admin] User Edit" );
148 //[Admin] RĂ´les de l'utilisateur
150 assertTextPresent( "[Admin] User Roles", "[Admin] R\u00F4les de l'utilisateur" );
151 assertTextPresent( "Username", "Nom d'utilisateur" );
152 assertTextPresent( "Full Name", "Nom complet" );
154 "Guest,Registered User,System Administrator,User Administrator,Global Repository Observer,Global Repository Manager,Repository Observer,Repository Manager,internal";
155 String[] arrayRole = userRoles.split( "," );
156 for ( String userroles : arrayRole )
158 assertTextPresent( userroles );
162 public void assertDeleteUserPage( String username )
164 assertTextPresent( "[Admin] User Delete", "[Admin] Suppression de l'utilisateur",
165 "L'utilisateur suivant va \u00EAtre supprim\u00E9:" );
166 assertTextPresent( "The following user will be deleted:" );
167 assertTextPresent( "Username: " + username, "Nom d'utilisateur:" + username );
168 assertButtonWithIdPresent( "userDeleteSubmit" );
171 public void createUser( String userName, String fullName, String email, String password, boolean valid )
173 createUser( userName, fullName, email, password, password, valid );
176 private void createUser( String userName, String fullName, String emailAd, String password, String confirmPassword,
180 clickLinkWithLocator( "menu-users-list-a", true );
181 clickLinkWithLocator( "users-view-tabs-li-user-edit-a", true );
183 assertCreateUserPage();
184 setFieldValue( "username", userName );
185 setFieldValue( "fullname", fullName );
186 setFieldValue( "email", emailAd );
187 setFieldValue( "password", password );
188 setFieldValue( "confirmPassword", confirmPassword );
190 clickLinkWithLocator( "user-create-form-register-button", true );
192 assertTextPresent( "User " + userName + " created." );
193 assertElementPresent( "users-grid-user-id-" + userName );
197 //String[] columnValues = { userName, fullName, emailAd };
198 //assertElementPresent( XPathExpressionUtil.getTableRow( columnValues ) );
203 assertCreateUserPage();
207 public void deleteUser( String userName, String fullName, String emailAdd )
209 deleteUser( userName, fullName, emailAdd, false, false );
212 public void deleteUser( String userName, String fullName, String emailAd, boolean validated, boolean locked )
214 clickLinkWithLocator( "menu-users-list-a", true );
215 assertTextPresent( userName );
216 assertTextPresent( fullName );
218 clickLinkWithLocator( "users-grid-delete-" + userName );
220 clickLinkWithLocator( "dialog-confirm-modal-ok" );
221 assertTextPresent( "User " + userName + " deleted." );
223 clickLinkWithLocator( "alert-message-success-close-a" );
225 assertElementNotPresent( "users-grid-user-id-" + userName );
226 assertTextNotPresent( fullName );
232 public void assertUserRoleCheckBoxPresent( String value )
234 getSelenium().isElementPresent(
235 "xpath=//input[@id='addRolesToUser_addNDSelectedRoles' and @name='addNDSelectedRoles' and @value='" + value
239 public void assertResourceRolesCheckBoxPresent( String value )
241 getSelenium().isElementPresent( "xpath=//input[@name='addDSelectedRoles' and @value='" + value + "']" );
244 public void checkUserRoleWithValue( String value )
246 assertUserRoleCheckBoxPresent( value );
248 "xpath=//input[@id='addRolesToUser_addNDSelectedRoles' and @name='addNDSelectedRoles' and @value='" + value
252 public void checkResourceRoleWithValue( String value )
254 assertResourceRolesCheckBoxPresent( value );
255 getSelenium().click( "xpath=//input[@name='addDSelectedRoles' and @value='" + value + "']" );
258 public void changePassword( String oldPassword, String newPassword )
260 assertPage( "Apache Archiva \\ Change Password" );
261 setFieldValue( "existingPassword", oldPassword );
262 setFieldValue( "newPassword", newPassword );
263 setFieldValue( "newPasswordConfirm", newPassword );
264 clickButtonWithValue( "Change Password" );
267 public void assertCreateUserPage()
269 assertTextPresent( "Username" );
270 assertElementPresent( "username" );
271 assertTextPresent( "Full Name" );
272 assertElementPresent( "fullname" );
273 assertTextPresent( "Email Address" );
274 assertElementPresent( "email" );
275 assertTextPresent( "Password" );
276 assertElementPresent( "password" );
277 assertTextPresent( "Confirm Password" );
278 assertElementPresent( "confirmPassword" );
279 assertButtonWithIdPresent( "user-create-form-register-button" );
283 public void assertLeftNavMenuWithRole( String role )
285 if ( role.equals( "Guest" ) || role.equals( "Registered User" ) || role.equals( "Global Repository Observer" )
286 || role.equals( "Repository Observer - internal" ) || role.equals( "Repository Observer - snapshots" ) )
288 assertTextPresent( "Search" );
289 assertLinkPresent( "Find Artifact" );
290 assertLinkPresent( "Browse" );
291 assertLinkNotPresent( "Repositories" );
293 else if ( role.equals( "User Administrator" ) )
295 assertTextPresent( "Search" );
296 assertLinkPresent( "Find Artifact" );
297 assertLinkPresent( "Browse" );
298 assertLinkPresent( "User Management" );
299 assertLinkPresent( "User Roles" );
300 assertLinkNotPresent( "Repositories" );
302 else if ( role.equals( "Global Repository Manager" ) || role.equals( "Repository Manager - internal" )
303 || role.equals( "Repository Manager - snapshots" ) )
305 assertTextPresent( "Search" );
306 assertLinkPresent( "Find Artifact" );
307 assertLinkPresent( "Browse" );
308 assertLinkPresent( "Upload Artifact" );
309 assertLinkPresent( "Delete Artifact" );
310 assertLinkNotPresent( "Repositories" );
314 assertTextPresent( "Search" );
316 "Find Artifact,Browse,Reports,User Management,User Roles,Appearance,Upload Artifact,Delete Artifact,Repository Groups,Repositories,Proxy Connectors,Legacy Support,Network Proxies,Repository Scanning";
317 String[] arrayMenu = navMenu.split( "," );
318 for ( String navmenu : arrayMenu )
320 assertLinkPresent( navmenu );
326 public void goToFindArtifactPage()
328 getSelenium().open( "/archiva/findArtifact.action" );
329 assertFindArtifactPage();
332 public void assertFindArtifactPage()
334 //assertPage( "Apache Archiva \\ Find Artifact" );
335 assertElementPresent( "searchBox" );
336 //assertTextPresent( "Find Artifact" );
337 //assertTextPresent( "Search for:" );
338 //assertTextPresent( "Checksum:" );
339 assertElementPresent( "quickSearchBox" );
340 assertElementPresent( "checksumSearch" );
341 //assertButtonWithValuePresent( "Search" );
342 assertElementPresent( "checksumSearch_0" );
346 public void goToAppearancePage()
348 getSelenium().open( "/archiva/admin/configureAppearance.action" );
349 assertAppearancePage();
352 public void assertAppearancePage()
354 assertPage( "Apache Archiva \\ Configure Appearance" );
356 "Appearance,Organization Details,The logo in the top right of the screen is controlled by the following settings.,Organization Information,Name,URL,Logo URL";
357 String[] arrayAppearance = appearance.split( "," );
358 for ( String appear : arrayAppearance )
360 assertTextPresent( appear );
362 assertLinkPresent( "Edit" );
363 assertLinkPresent( "Change your appearance" );
366 public void addEditAppearance( String name, String url, String logoUrl, boolean wait )
368 setFieldValue( "organisationName", name );
369 setFieldValue( "organisationUrl", url );
370 setFieldValue( "organisationLogo", logoUrl );
371 clickButtonWithValue( "Save", wait );
374 public void goToHomePage()
376 getSelenium().open( baseUrl );
380 public void goToAddArtifactPage()
382 // must be logged as admin
383 getSelenium().open( "/archiva/upload.action" );
384 assertAddArtifactPage();
387 public void assertAddArtifactPage()
389 assertPage( "Apache Archiva \\ Upload Artifact" );
390 assertTextPresent( "Upload Artifact" );
393 "Upload Artifact,Group Id*:,Artifact Id*:,Version*:,Packaging*:,Classifier:,Generate Maven 2 POM,Artifact File*:,POM File:,Repository Id:";
394 String[] arrayArtifact = artifact.split( "," );
395 for ( String arrayartifact : arrayArtifact )
397 assertTextPresent( arrayartifact );
400 String artifactElements =
401 "upload_groupId,upload_artifactId,upload_version,upload_packaging,upload_classifier,upload_generatePom,upload_artifact,upload_pom,upload_repositoryId,uploadSubmit";
402 String[] arrayArtifactElements = artifactElements.split( "," );
403 for ( String artifactelements : arrayArtifactElements )
405 assertElementPresent( artifactelements );
409 public void addArtifact( String groupId, String artifactId, String version, String packaging,
410 String artifactFilePath, String repositoryId, boolean wait )
412 addArtifact( groupId, artifactId, version, packaging, true, artifactFilePath, repositoryId, wait );
415 public void addArtifact( String groupId, String artifactId, String version, String packaging, boolean generatePom,
416 String artifactFilePath, String repositoryId, boolean wait )
418 login( getProperty( "ADMIN_USERNAME" ), getProperty( "ADMIN_PASSWORD" ) );
419 goToAddArtifactPage();
420 setFieldValue( "groupId", groupId );
421 setFieldValue( "artifactId", artifactId );
422 setFieldValue( "version", version );
423 setFieldValue( "packaging", packaging );
427 checkField( "generatePom" );
431 if ( artifactFilePath != null && artifactFilePath.trim().length() > 0 )
433 File f = new File( artifactFilePath );
436 path = f.getCanonicalPath();
438 catch ( IOException e )
440 path = f.getAbsolutePath();
445 path = artifactFilePath;
448 setFieldValue( "artifact", path );
449 selectValue( "upload_repositoryId", repositoryId );
451 //clickButtonWithValue( "Submit" );
452 clickButtonWithLocator( "uploadSubmit", wait );
455 public void goToRepositoriesPage()
457 if ( !getTitle().equals( "Apache Archiva \\ Administration - Repositories" ) )
459 getSelenium().open( "/archiva/admin/repositories.action" );
461 assertRepositoriesPage();
464 public void assertRepositoriesPage()
466 assertPage( "Apache Archiva \\ Administration - Repositories" );
467 assertTextPresent( "Administration - Repositories" );
468 assertTextPresent( "Managed Repositories" );
469 assertTextPresent( "Remote Repositories" );
472 public void addManagedRepository( String identifier, String name, String directory, String indexDirectory,
473 String type, String cron, String daysOlder, String retentionCount, boolean wait )
475 // goToRepositoriesPage();
476 // clickLinkWithText( "Add" );
477 setFieldValue( "repository.id", identifier );
478 setFieldValue( "repository.name", name );
479 setFieldValue( "repository.location", directory );
480 setFieldValue( "repository.indexDirectory", indexDirectory );
481 selectValue( "repository.layout", type );
482 setFieldValue( "repository.cronExpression", cron );
483 setFieldValue( "repository.daysOlder", daysOlder );
484 setFieldValue( "repository.retentionCount", retentionCount );
486 clickButtonWithValue( "Add Repository", wait );
489 // artifact management
490 public void assertDeleteArtifactPage()
492 assertPage( "Apache Archiva \\ Delete Artifact" );
493 assertTextPresent( "Delete Artifact" );
494 assertTextPresent( "Group Id*:" );
495 assertTextPresent( "Artifact Id*:" );
496 assertTextPresent( "Version*:" );
497 assertTextPresent( "Repository Id:" );
498 assertElementPresent( "groupId" );
499 assertElementPresent( "artifactId" );
500 assertElementPresent( "version" );
501 assertElementPresent( "repositoryId" );
502 assertButtonWithValuePresent( "Submit" );
506 public void goToNetworkProxiesPage()
508 clickLinkWithText( "Network Proxies" );
509 assertNetworkProxiesPage();
512 public void assertNetworkProxiesPage()
514 assertPage( "Apache Archiva \\ Administration - Network Proxies" );
515 assertTextPresent( "Administration - Network Proxies" );
516 assertTextPresent( "Network Proxies" );
517 assertLinkPresent( "Add Network Proxy" );
520 public void addNetworkProxy( String identifier, String protocol, String hostname, String port, String username,
523 //goToNetworkProxiesPage();
524 clickLinkWithText( "Add Network Proxy" );
525 assertAddNetworkProxy();
526 setFieldValue( "proxy.id", identifier );
527 setFieldValue( "proxy.protocol", protocol );
528 setFieldValue( "proxy.host", hostname );
529 setFieldValue( "proxy.port", port );
530 setFieldValue( "proxy.username", username );
531 setFieldValue( "proxy.password", password );
532 clickButtonWithValue( "Save Network Proxy" );
535 public void assertAddNetworkProxy()
537 assertPage( "Apache Archiva \\ Admin: Add Network Proxy" );
538 assertTextPresent( "Admin: Add Network Proxy" );
539 assertTextPresent( "Add network proxy:" );
540 assertTextPresent( "Identifier*:" );
541 assertTextPresent( "Protocol*:" );
542 assertTextPresent( "Hostname*:" );
543 assertTextPresent( "Port*:" );
544 assertTextPresent( "Username:" );
545 assertTextPresent( "Password:" );
546 assertButtonWithValuePresent( "Save Network Proxy" );
550 public void goToLegacySupportPage()
552 getSelenium().open( "/archiva/admin/legacyArtifactPath.action" );
553 assertLegacySupportPage();
556 public void assertLegacySupportPage()
558 assertPage( "Apache Archiva \\ Administration - Legacy Support" );
559 assertTextPresent( "Administration - Legacy Artifact Path Resolution" );
560 assertTextPresent( "Path Mappings" );
561 assertLinkPresent( "Add" );
564 public void addLegacyArtifactPath( String path, String groupId, String artifactId, String version,
565 String classifier, String type, boolean wait )
567 assertAddLegacyArtifactPathPage();
568 setFieldValue( "legacyArtifactPath.path", path );
569 setFieldValue( "groupId", groupId );
570 setFieldValue( "artifactId", artifactId );
571 setFieldValue( "version", version );
572 setFieldValue( "classifier", classifier );
573 setFieldValue( "type", type );
574 clickButtonWithValue( "Add Legacy Artifact Path", wait );
577 public void assertAddLegacyArtifactPathPage()
579 assertPage( "Apache Archiva \\ Admin: Add Legacy Artifact Path" );
580 assertTextPresent( "Admin: Add Legacy Artifact Path" );
582 "Enter the legacy path to map to a particular artifact reference, then adjust the fields as necessary." );
584 "addLegacyArtifactPath_legacyArtifactPath_path,addLegacyArtifactPath_groupId,addLegacyArtifactPath_artifactId,addLegacyArtifactPath_version,addLegacyArtifactPath_classifier,addLegacyArtifactPath_type";
585 String[] arrayElement = element.split( "," );
586 for ( String arrayelement : arrayElement )
588 assertElementPresent( arrayelement );
590 assertButtonWithValuePresent( "Add Legacy Artifact Path" );
593 // add managed repository and its staging repository
594 public void addStagingRepository( String identifier, String name, String directory, String indexDirectory,
595 String type, String cron, String daysOlder, String retentionCount )
597 setFieldValue( "repository.id", identifier );
598 setFieldValue( "repository.name", name );
599 setFieldValue( "repository.location", directory );
600 setFieldValue( "repository.indexDirectory", indexDirectory );
601 selectValue( "repository.layout", type );
602 setFieldValue( "repository.cronExpression", cron );
603 setFieldValue( "repository.daysOlder", daysOlder );
604 setFieldValue( "repository.retentionCount", retentionCount );
605 checkField( "stageNeeded" );
607 clickButtonWithValue( "Add Repository" );
610 protected void logout()
612 clickLinkWithText( "Logout" );
613 assertTextNotPresent( "Current User:" );
614 assertLinkNotVisible( "Edit Details" );
615 assertLinkNotVisible( "Logout" );
616 assertLinkVisible( "Login" );
619 protected String getAdminUserName()
621 return getProperty( "ADMIN_FULLNAME" );