1 package org.apache.archiva.web.test.parent;
3 import org.apache.archiva.web.test.tools.ScreenshotCaptureRule;
5 import org.junit.runner.RunWith;
6 import org.junit.runners.BlockJUnit4ClassRunner;
9 import java.io.IOException;
12 * Licensed to the Apache Software Foundation (ASF) under one
13 * or more contributor license agreements. See the NOTICE file
14 * distributed with this work for additional information
15 * regarding copyright ownership. The ASF licenses this file
16 * to you under the Apache License, Version 2.0 (the
17 * "License"); you may not use this file except in compliance
18 * with the License. You may obtain a copy of the License at
20 * http://www.apache.org/licenses/LICENSE-2.0
22 * Unless required by applicable law or agreed to in writing,
23 * software distributed under the License is distributed on an
24 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
25 * KIND, either express or implied. See the License for the
26 * specific language governing permissions and limitations
30 @RunWith( BlockJUnit4ClassRunner.class )
31 public abstract class AbstractArchivaTest
32 extends AbstractSeleniumTest
35 protected String username;
37 protected String fullname;
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();
70 public void submitUserData( String username, String password, boolean rememberme, boolean success )
73 setFieldValue( "username", username );
74 setFieldValue( "password", password );
77 checkField( "rememberMe" );
83 assertUserLoggedIn( username );
92 public void goToUserManagementPage()
94 getSelenium().open( "/archiva/security/userlist.action" );
95 assertUserManagementPage();
98 public void assertUserManagementPage()
100 assertPage( "Apache Archiva \\ [Admin] User List" );
101 assertTextPresent( "[Admin] List of Users in Role: Any" );
102 assertTextPresent( "Navigation" );
103 assertImgWithAlt( "First" );
104 assertImgWithAlt( "Prev" );
105 assertImgWithAlt( "Next" );
106 assertImgWithAlt( "Last" );
107 assertTextPresent( "Display Rows" );
108 assertTextPresent( "Username" );
109 assertTextPresent( "Full Name" );
110 assertTextPresent( "Email" );
111 assertTextPresent( "Permanent" );
112 assertTextPresent( "Validated" );
113 assertTextPresent( "Locked" );
114 assertTextPresent( "Tasks" );
115 assertTextPresent( "Tools" );
116 assertTextPresent( "Tasks" );
117 assertTextPresent( "The following tools are available for administrators to manipulate the user list." );
118 assertButtonWithValuePresent( "Create New User" );
119 assertButtonWithValuePresent( "Show Users In Role" );
120 assertElementPresent( "roleName" );
121 assertTextPresent( "Reports" );
122 assertTextPresent( "Name" );
123 assertTextPresent( "Types" );
124 assertTextPresent( "User List" );
125 assertTextPresent( "Roles Matrix" );
129 * //User Role public void goToUserRolesPage() { clickLinkWithText( "User Roles" ); assertUserRolesPage(); }
132 public void assertUserRolesPage()
134 //assertPage( "Apache Archiva \\ [Admin] User Edit" );
135 //[Admin] RĂ´les de l'utilisateur
137 assertTextPresent( "[Admin] User Roles", "[Admin] R\u00F4les de l'utilisateur" );
138 assertTextPresent( "Username", "Nom d'utilisateur" );
139 assertTextPresent( "Full Name", "Nom complet" );
141 "Guest,Registered User,System Administrator,User Administrator,Global Repository Observer,Global Repository Manager,Repository Observer,Repository Manager,internal";
142 String[] arrayRole = userRoles.split( "," );
143 for ( String userroles : arrayRole )
145 assertTextPresent( userroles );
149 public void assertDeleteUserPage( String username )
151 assertTextPresent( "[Admin] User Delete", "[Admin] Suppression de l'utilisateur",
152 "L'utilisateur suivant va \u00EAtre supprim\u00E9:" );
153 assertTextPresent( "The following user will be deleted:" );
154 assertTextPresent( "Username: " + username, "Nom d'utilisateur:" + username );
155 assertButtonWithIdPresent( "userDeleteSubmit" );
158 public void createUser( String userName, String fullName, String email, String password, boolean valid )
160 createUser( userName, fullName, email, password, password, valid );
163 private void createUser( String userName, String fullName, String emailAd, String password, String confirmPassword,
167 clickLinkWithLocator( "menu-users-list-a", true );
168 clickLinkWithLocator( "users-view-tabs-li-user-edit-a", true );
170 assertCreateUserPage();
171 setFieldValue( "username", userName );
172 setFieldValue( "fullname", fullName );
173 setFieldValue( "email", emailAd );
174 setFieldValue( "password", password );
175 setFieldValue( "confirmPassword", confirmPassword );
177 clickLinkWithLocator( "user-create-form-register-button", true );
179 assertTextPresent( "User " + userName + " created." );
180 assertElementPresent( "users-grid-user-id-" + userName );
184 //String[] columnValues = { userName, fullName, emailAd };
185 //assertElementPresent( XPathExpressionUtil.getTableRow( columnValues ) );
190 assertCreateUserPage();
194 public void deleteUser( String userName, String fullName, String emailAdd )
196 deleteUser( userName, fullName, emailAdd, false, false );
199 public void deleteUser( String userName, String fullName, String emailAd, boolean validated, boolean locked )
201 clickLinkWithLocator( "menu-users-list-a", true );
202 assertTextPresent( userName );
203 assertTextPresent( fullName );
205 clickLinkWithLocator( "users-grid-delete-" + userName );
207 clickLinkWithLocator( "dialog-confirm-modal-ok" );
208 assertTextPresent( "User " + userName + " deleted." );
210 clickLinkWithLocator( "alert-message-success-close-a" );
212 assertElementNotPresent( "users-grid-user-id-" + userName );
213 assertTextNotPresent( fullName );
219 public void assertUserRoleCheckBoxPresent( String value )
221 getSelenium().isElementPresent(
222 "xpath=//input[@id='addRolesToUser_addNDSelectedRoles' and @name='addNDSelectedRoles' and @value='" + value
226 public void assertResourceRolesCheckBoxPresent( String value )
228 getSelenium().isElementPresent( "xpath=//input[@name='addDSelectedRoles' and @value='" + value + "']" );
231 public void checkUserRoleWithValue( String value )
233 assertUserRoleCheckBoxPresent( value );
235 "xpath=//input[@id='addRolesToUser_addNDSelectedRoles' and @name='addNDSelectedRoles' and @value='" + value
239 public void checkResourceRoleWithValue( String value )
241 assertResourceRolesCheckBoxPresent( value );
242 getSelenium().click( "xpath=//input[@name='addDSelectedRoles' and @value='" + value + "']" );
245 public void changePassword( String oldPassword, String newPassword )
247 assertPage( "Apache Archiva \\ Change Password" );
248 setFieldValue( "existingPassword", oldPassword );
249 setFieldValue( "newPassword", newPassword );
250 setFieldValue( "newPasswordConfirm", newPassword );
251 clickButtonWithValue( "Change Password" );
254 public void assertCreateUserPage()
256 assertTextPresent( "Username" );
257 assertElementPresent( "username" );
258 assertTextPresent( "Full Name" );
259 assertElementPresent( "fullname" );
260 assertTextPresent( "Email Address" );
261 assertElementPresent( "email" );
262 assertTextPresent( "Password" );
263 assertElementPresent( "password" );
264 assertTextPresent( "Confirm Password" );
265 assertElementPresent( "confirmPassword" );
266 assertButtonWithIdPresent( "user-create-form-register-button" );
270 public void assertLeftNavMenuWithRole( String role )
272 if ( role.equals( "Guest" ) || role.equals( "Registered User" ) || role.equals( "Global Repository Observer" )
273 || role.equals( "Repository Observer - internal" ) || role.equals( "Repository Observer - snapshots" ) )
275 assertTextPresent( "Search" );
276 assertLinkPresent( "Find Artifact" );
277 assertLinkPresent( "Browse" );
278 assertLinkNotPresent( "Repositories" );
280 else if ( role.equals( "User Administrator" ) )
282 assertTextPresent( "Search" );
283 assertLinkPresent( "Find Artifact" );
284 assertLinkPresent( "Browse" );
285 assertLinkPresent( "User Management" );
286 assertLinkPresent( "User Roles" );
287 assertLinkNotPresent( "Repositories" );
289 else if ( role.equals( "Global Repository Manager" ) || role.equals( "Repository Manager - internal" )
290 || role.equals( "Repository Manager - snapshots" ) )
292 assertTextPresent( "Search" );
293 assertLinkPresent( "Find Artifact" );
294 assertLinkPresent( "Browse" );
295 assertLinkPresent( "Upload Artifact" );
296 assertLinkPresent( "Delete Artifact" );
297 assertLinkNotPresent( "Repositories" );
301 assertTextPresent( "Search" );
303 "Find Artifact,Browse,Reports,User Management,User Roles,Appearance,Upload Artifact,Delete Artifact,Repository Groups,Repositories,Proxy Connectors,Legacy Support,Network Proxies,Repository Scanning";
304 String[] arrayMenu = navMenu.split( "," );
305 for ( String navmenu : arrayMenu )
307 assertLinkPresent( navmenu );
313 public void goToFindArtifactPage()
315 getSelenium().open( "/archiva/findArtifact.action" );
316 assertFindArtifactPage();
319 public void assertFindArtifactPage()
321 //assertPage( "Apache Archiva \\ Find Artifact" );
322 assertElementPresent( "searchBox" );
323 //assertTextPresent( "Find Artifact" );
324 //assertTextPresent( "Search for:" );
325 //assertTextPresent( "Checksum:" );
326 assertElementPresent( "quickSearchBox" );
327 assertElementPresent( "checksumSearch" );
328 //assertButtonWithValuePresent( "Search" );
329 assertElementPresent( "checksumSearch_0" );
333 public void goToAppearancePage()
335 getSelenium().open( "/archiva/admin/configureAppearance.action" );
336 assertAppearancePage();
339 public void assertAppearancePage()
341 assertPage( "Apache Archiva \\ Configure Appearance" );
343 "Appearance,Organization Details,The logo in the top right of the screen is controlled by the following settings.,Organization Information,Name,URL,Logo URL";
344 String[] arrayAppearance = appearance.split( "," );
345 for ( String appear : arrayAppearance )
347 assertTextPresent( appear );
349 assertLinkPresent( "Edit" );
350 assertLinkPresent( "Change your appearance" );
353 public void addEditAppearance( String name, String url, String logoUrl, boolean wait )
355 setFieldValue( "organisationName", name );
356 setFieldValue( "organisationUrl", url );
357 setFieldValue( "organisationLogo", logoUrl );
358 clickButtonWithValue( "Save", wait );
361 public void goToHomePage()
363 getSelenium().open( baseUrl );
367 public void goToAddArtifactPage()
369 // must be logged as admin
370 getSelenium().open( "/archiva/upload.action" );
371 assertAddArtifactPage();
374 public void assertAddArtifactPage()
376 assertPage( "Apache Archiva \\ Upload Artifact" );
377 assertTextPresent( "Upload Artifact" );
380 "Upload Artifact,Group Id*:,Artifact Id*:,Version*:,Packaging*:,Classifier:,Generate Maven 2 POM,Artifact File*:,POM File:,Repository Id:";
381 String[] arrayArtifact = artifact.split( "," );
382 for ( String arrayartifact : arrayArtifact )
384 assertTextPresent( arrayartifact );
387 String artifactElements =
388 "upload_groupId,upload_artifactId,upload_version,upload_packaging,upload_classifier,upload_generatePom,upload_artifact,upload_pom,upload_repositoryId,uploadSubmit";
389 String[] arrayArtifactElements = artifactElements.split( "," );
390 for ( String artifactelements : arrayArtifactElements )
392 assertElementPresent( artifactelements );
396 public void addArtifact( String groupId, String artifactId, String version, String packaging,
397 String artifactFilePath, String repositoryId, boolean wait )
399 addArtifact( groupId, artifactId, version, packaging, true, artifactFilePath, repositoryId, wait );
402 public void addArtifact( String groupId, String artifactId, String version, String packaging, boolean generatePom,
403 String artifactFilePath, String repositoryId, boolean wait )
405 login( getProperty( "ADMIN_USERNAME" ), getProperty( "ADMIN_PASSWORD" ) );
406 goToAddArtifactPage();
407 setFieldValue( "groupId", groupId );
408 setFieldValue( "artifactId", artifactId );
409 setFieldValue( "version", version );
410 setFieldValue( "packaging", packaging );
414 checkField( "generatePom" );
418 if ( artifactFilePath != null && artifactFilePath.trim().length() > 0 )
420 File f = new File( artifactFilePath );
423 path = f.getCanonicalPath();
425 catch ( IOException e )
427 path = f.getAbsolutePath();
432 path = artifactFilePath;
435 setFieldValue( "artifact", path );
436 selectValue( "upload_repositoryId", repositoryId );
438 //clickButtonWithValue( "Submit" );
439 clickButtonWithLocator( "uploadSubmit", wait );
442 public void goToRepositoriesPage()
444 if ( !getTitle().equals( "Apache Archiva \\ Administration - Repositories" ) )
446 getSelenium().open( "/archiva/admin/repositories.action" );
448 assertRepositoriesPage();
451 public void assertRepositoriesPage()
453 assertPage( "Apache Archiva \\ Administration - Repositories" );
454 assertTextPresent( "Administration - Repositories" );
455 assertTextPresent( "Managed Repositories" );
456 assertTextPresent( "Remote Repositories" );
459 public void addManagedRepository( String identifier, String name, String directory, String indexDirectory,
460 String type, String cron, String daysOlder, String retentionCount, boolean wait )
462 // goToRepositoriesPage();
463 // clickLinkWithText( "Add" );
464 setFieldValue( "repository.id", identifier );
465 setFieldValue( "repository.name", name );
466 setFieldValue( "repository.location", directory );
467 setFieldValue( "repository.indexDirectory", indexDirectory );
468 selectValue( "repository.layout", type );
469 setFieldValue( "repository.cronExpression", cron );
470 setFieldValue( "repository.daysOlder", daysOlder );
471 setFieldValue( "repository.retentionCount", retentionCount );
473 clickButtonWithValue( "Add Repository", wait );
476 // artifact management
477 public void assertDeleteArtifactPage()
479 assertPage( "Apache Archiva \\ Delete Artifact" );
480 assertTextPresent( "Delete Artifact" );
481 assertTextPresent( "Group Id*:" );
482 assertTextPresent( "Artifact Id*:" );
483 assertTextPresent( "Version*:" );
484 assertTextPresent( "Repository Id:" );
485 assertElementPresent( "groupId" );
486 assertElementPresent( "artifactId" );
487 assertElementPresent( "version" );
488 assertElementPresent( "repositoryId" );
489 assertButtonWithValuePresent( "Submit" );
493 public void goToNetworkProxiesPage()
495 clickLinkWithText( "Network Proxies" );
496 assertNetworkProxiesPage();
499 public void assertNetworkProxiesPage()
501 assertPage( "Apache Archiva \\ Administration - Network Proxies" );
502 assertTextPresent( "Administration - Network Proxies" );
503 assertTextPresent( "Network Proxies" );
504 assertLinkPresent( "Add Network Proxy" );
507 public void addNetworkProxy( String identifier, String protocol, String hostname, String port, String username,
510 //goToNetworkProxiesPage();
511 clickLinkWithText( "Add Network Proxy" );
512 assertAddNetworkProxy();
513 setFieldValue( "proxy.id", identifier );
514 setFieldValue( "proxy.protocol", protocol );
515 setFieldValue( "proxy.host", hostname );
516 setFieldValue( "proxy.port", port );
517 setFieldValue( "proxy.username", username );
518 setFieldValue( "proxy.password", password );
519 clickButtonWithValue( "Save Network Proxy" );
522 public void assertAddNetworkProxy()
524 assertPage( "Apache Archiva \\ Admin: Add Network Proxy" );
525 assertTextPresent( "Admin: Add Network Proxy" );
526 assertTextPresent( "Add network proxy:" );
527 assertTextPresent( "Identifier*:" );
528 assertTextPresent( "Protocol*:" );
529 assertTextPresent( "Hostname*:" );
530 assertTextPresent( "Port*:" );
531 assertTextPresent( "Username:" );
532 assertTextPresent( "Password:" );
533 assertButtonWithValuePresent( "Save Network Proxy" );
537 public void goToLegacySupportPage()
539 getSelenium().open( "/archiva/admin/legacyArtifactPath.action" );
540 assertLegacySupportPage();
543 public void assertLegacySupportPage()
545 assertPage( "Apache Archiva \\ Administration - Legacy Support" );
546 assertTextPresent( "Administration - Legacy Artifact Path Resolution" );
547 assertTextPresent( "Path Mappings" );
548 assertLinkPresent( "Add" );
551 public void addLegacyArtifactPath( String path, String groupId, String artifactId, String version,
552 String classifier, String type, boolean wait )
554 assertAddLegacyArtifactPathPage();
555 setFieldValue( "legacyArtifactPath.path", path );
556 setFieldValue( "groupId", groupId );
557 setFieldValue( "artifactId", artifactId );
558 setFieldValue( "version", version );
559 setFieldValue( "classifier", classifier );
560 setFieldValue( "type", type );
561 clickButtonWithValue( "Add Legacy Artifact Path", wait );
564 public void assertAddLegacyArtifactPathPage()
566 assertPage( "Apache Archiva \\ Admin: Add Legacy Artifact Path" );
567 assertTextPresent( "Admin: Add Legacy Artifact Path" );
569 "Enter the legacy path to map to a particular artifact reference, then adjust the fields as necessary." );
571 "addLegacyArtifactPath_legacyArtifactPath_path,addLegacyArtifactPath_groupId,addLegacyArtifactPath_artifactId,addLegacyArtifactPath_version,addLegacyArtifactPath_classifier,addLegacyArtifactPath_type";
572 String[] arrayElement = element.split( "," );
573 for ( String arrayelement : arrayElement )
575 assertElementPresent( arrayelement );
577 assertButtonWithValuePresent( "Add Legacy Artifact Path" );
580 // add managed repository and its staging repository
581 public void addStagingRepository( String identifier, String name, String directory, String indexDirectory,
582 String type, String cron, String daysOlder, String retentionCount )
584 setFieldValue( "repository.id", identifier );
585 setFieldValue( "repository.name", name );
586 setFieldValue( "repository.location", directory );
587 setFieldValue( "repository.indexDirectory", indexDirectory );
588 selectValue( "repository.layout", type );
589 setFieldValue( "repository.cronExpression", cron );
590 setFieldValue( "repository.daysOlder", daysOlder );
591 setFieldValue( "repository.retentionCount", retentionCount );
592 checkField( "stageNeeded" );
594 clickButtonWithValue( "Add Repository" );
597 protected void logout()
599 clickLinkWithText( "Logout" );
600 assertTextNotPresent( "Current User:" );
601 assertLinkNotVisible( "Edit Details" );
602 assertLinkNotVisible( "Logout" );
603 assertLinkVisible( "Login" );
606 protected String getAdminUserName()
608 return getProperty( "ADMIN_FULLNAME" );