1 package org.apache.archiva.web.test.parent;
3 import org.junit.runner.RunWith;
4 import org.junit.runners.BlockJUnit4ClassRunner;
5 import org.openqa.selenium.By;
6 import org.openqa.selenium.WebElement;
7 import org.openqa.selenium.support.ui.ExpectedConditions;
8 import org.openqa.selenium.support.ui.WebDriverWait;
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 @RunWith( BlockJUnit4ClassRunner.class )
33 public abstract class AbstractArchivaTest
34 extends AbstractSeleniumTest
37 protected String username;
39 protected String fullname;
41 public String getUserEmail()
43 String email = getProperty( "USERROLE_EMAIL" );
47 public String getUserRolePassword()
49 String password = getProperty( "USERROLE_PASSWORD" );
53 public String getUserRoleNewPassword()
55 String password_new = getProperty( "NEW_USERROLE_PASSWORD" );
59 public String getBasedir()
61 String basedir = System.getProperty( "basedir" );
63 if ( basedir == null )
65 basedir = new File( "" ).getAbsolutePath();
72 public void submitUserData( String username, String password, boolean rememberme, boolean success )
75 setFieldValue( "username", username );
76 setFieldValue( "password", password );
79 checkField( "rememberMe" );
85 assertUserLoggedIn( username );
95 public void createUser( String userName, String fullName, String email, String password, boolean valid )
97 createUser( userName, fullName, email, password, password, valid );
100 private void createUser( String userName, String fullName, String emailAd, String password, String confirmPassword,
103 login( getAdminUsername(), getAdminPassword() );
104 WebDriverWait wait = new WebDriverWait(getWebDriver(), 10);
105 WebElement el = wait.until(ExpectedConditions.elementToBeClickable( By.id("menu-users-list-a") ));
106 el = tryClick(el, ExpectedConditions.elementToBeClickable(By.id("users-view-tabs-li-user-edit-a")), "User List not available");
107 el = tryClick(el, ExpectedConditions.elementToBeClickable(By.id("users-view-tabs-li-user-edit-a")),"User Edit View not available");
108 el = tryClick(el, ExpectedConditions.elementToBeClickable(By.id("user-create-form-register-button")),
109 "Register Form not available");
110 assertCreateUserPage();
111 setFieldValue( "username", userName );
112 setFieldValue( "fullname", fullName );
113 setFieldValue( "email", emailAd );
114 setFieldValue( "password", password );
115 setFieldValue( "confirmPassword", confirmPassword );
119 wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("user-messages"),"User " + userName + " created." ));
120 assertElementPresent( "users-grid-user-id-" + userName );
124 //String[] columnValues = { userName, fullName, emailAd };
125 //assertElementPresent( XPathExpressionUtil.getTableRow( columnValues ) );
130 assertCreateUserPage();
134 public void deleteUser( String userName, String fullName, String emailAdd )
136 deleteUser( userName, fullName, emailAdd, false, false );
139 public void deleteUser( String userName, String fullName, String emailAd, boolean validated, boolean locked )
141 clickLinkWithLocator( "menu-users-list-a");
142 WebDriverWait wait = new WebDriverWait(getWebDriver(),10);
143 wait.until(ExpectedConditions.elementToBeClickable(By.id("users-grid-delete-" + userName)));
144 assertTextPresent( userName );
145 assertTextPresent( fullName );
147 clickLinkWithLocator( "users-grid-delete-" + userName );
148 wait.until(ExpectedConditions.elementToBeClickable(By.id("dialog-confirm-modal-ok")));
150 clickLinkWithLocator( "dialog-confirm-modal-ok" );
151 wait.until(ExpectedConditions.elementToBeClickable(By.id("alert-message-success-close-a" )));
152 assertTextPresent( "User " + userName + " deleted." );
154 clickLinkWithLocator( "alert-message-success-close-a" );
156 assertElementNotPresent( "users-grid-user-id-" + userName );
157 assertTextNotPresent( fullName );
165 public void assertCreateUserPage()
167 assertTextPresent( "Username" );
168 assertElementPresent( "username" );
169 assertTextPresent( "Full Name" );
170 assertElementPresent( "fullname" );
171 assertTextPresent( "Email Address" );
172 assertElementPresent( "email" );
173 assertTextPresent( "Password" );
174 assertElementPresent( "password" );
175 assertTextPresent( "Confirm Password" );
176 assertElementPresent( "confirmPassword" );
177 assertButtonWithIdPresent( "user-create-form-register-button" );
181 public void goToHomePage()
183 getWebDriver().get( baseUrl );
186 protected void logout()
188 clickLinkWithLocator( "logout-link-a" );
189 WebDriverWait wait = new WebDriverWait(getWebDriver(), 10);
190 wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[text()='Login']//ancestor::a")));
191 assertTextNotPresent( "Current User:" );
192 assertLinkNotVisible( "Edit Details" );
193 assertLinkNotVisible( "Logout" );
194 assertLinkVisible( "Login" );
197 protected String getAdminUserName()
199 return getProperty( "ADMIN_FULLNAME" );