From 4c8bb8341b2dfd35c1c5dc10bc7e21d1c8fa38fb Mon Sep 17 00:00:00 2001 From: Wendy Smoak Date: Wed, 29 Apr 2009 21:21:40 +0000 Subject: [PATCH] [MRM-1164] TestNG/Selenium tests for login, browse, search, admin Submitted by: Marecor Baclay git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@769940 13f79535-47bb-0310-9956-ffa450edef68 --- .../archiva-webapp-test/ReadMe.txt | 9 + .../src/test/resources/testng.properties | 26 ++ .../src/test/testng/config/testng.xml | 46 +++ .../archiva/web/test/ArchivaAdminTest.java | 79 ++++ .../apache/archiva/web/test/BrowseTest.java | 45 +++ .../apache/archiva/web/test/LoginTest.java | 110 ++++++ .../apache/archiva/web/test/ReportsTest.java | 103 ++++++ .../apache/archiva/web/test/SearchTest.java | 57 +++ .../web/test/parent/AbstractArchivaTest.java | 222 +++++++++++ .../parent/AbstractArtifactReportsTest.java | 80 ++++ .../web/test/parent/AbstractBrowseTest.java | 40 ++ .../web/test/parent/AbstractSearchTest.java | 57 +++ .../web/test/parent/AbstractSeleniumTest.java | 349 ++++++++++++++++++ .../archiva-webapp-test/testng-pom.xml | 223 +++++++++++ 14 files changed, 1446 insertions(+) create mode 100644 archiva-modules/archiva-web/archiva-webapp-test/ReadMe.txt create mode 100644 archiva-modules/archiva-web/archiva-webapp-test/src/test/resources/testng.properties create mode 100644 archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/config/testng.xml create mode 100644 archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/ArchivaAdminTest.java create mode 100644 archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/BrowseTest.java create mode 100644 archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/LoginTest.java create mode 100644 archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/ReportsTest.java create mode 100644 archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/SearchTest.java create mode 100644 archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/parent/AbstractArchivaTest.java create mode 100644 archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/parent/AbstractArtifactReportsTest.java create mode 100644 archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/parent/AbstractBrowseTest.java create mode 100644 archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/parent/AbstractSearchTest.java create mode 100644 archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/parent/AbstractSeleniumTest.java create mode 100644 archiva-modules/archiva-web/archiva-webapp-test/testng-pom.xml diff --git a/archiva-modules/archiva-web/archiva-webapp-test/ReadMe.txt b/archiva-modules/archiva-web/archiva-webapp-test/ReadMe.txt new file mode 100644 index 000000000..aa634ef85 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp-test/ReadMe.txt @@ -0,0 +1,9 @@ +ReadMe +---------- +Run selenium tests in src/test/testng with Maven and TestNG + - Start Archiva + - Configure admin user for archiva (match values in src/test/resources/testng.properties ) + - modify src/test/resources/testng.properties as needed + - mvn clean install -f testng-pom.xml + +For the default values in the scripts, to pass all the tests, you need to add an artifact in internal repository. diff --git a/archiva-modules/archiva-web/archiva-webapp-test/src/test/resources/testng.properties b/archiva-modules/archiva-web/archiva-webapp-test/src/test/resources/testng.properties new file mode 100644 index 000000000..6a2bf3bfb --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp-test/src/test/resources/testng.properties @@ -0,0 +1,26 @@ +# properties for integration tests + +BASE_URL=http://localhost:9091/ +MAX_WAIT_TIME_IN_MS=60000 + +ADMIN_USERNAME=admin +ADMIN_FULLNAME=Administrator +ADMIN_EMAIL=admin@localhost +ADMIN_PASSWORD=admin123 + +SELENIUM_HOST=localhost +SELENIUM_PORT=4444 +SELENIUM_BROWSER=*firefox + +# Search +SEARCH_BAD_ARTIFACT=asdf +# Existing Artifact +ARTIFACT_GROUPID=test +ARTIFACT_ARTIFACTID=test +ARTIFACT_VERSION=1.0 +ARTIFACT_PACKAGING=jar + +# Reports +REPOSITORY_NAME=internal +START_DATE=04/01/2009 +END_DATE=04/30/2009 \ No newline at end of file diff --git a/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/config/testng.xml b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/config/testng.xml new file mode 100644 index 000000000..7d56abb98 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/config/testng.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/ArchivaAdminTest.java b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/ArchivaAdminTest.java new file mode 100644 index 000000000..dca7c03d6 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/ArchivaAdminTest.java @@ -0,0 +1,79 @@ +package org.apache.archiva.web.test; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.web.test.parent.AbstractArchivaTest; +import org.testng.Assert; +import org.testng.annotations.AfterTest; +import org.testng.annotations.BeforeSuite; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +@Test( groups = { "about" }, alwaysRun = true ) +public class ArchivaAdminTest + extends AbstractArchivaTest +{ + @BeforeSuite + public void initializeContinuum() + throws Exception + { + super.open(); + System.out.println( "open" ); + getSelenium().open( baseUrl ); + System.out.println( "URL" ); + String title = getSelenium().getTitle(); + if ( title.equals( "Create Admin User" ) ) + { + assertCreateAdmin(); + String fullname = p.getProperty( "ADMIN_FULLNAME" ); + String username = p.getProperty( "ADMIN_USERNAME" ); + String mail = p.getProperty( "ADMIN_EMAIL" ); + String password = p.getProperty( "ADMIN_PASSWORD" ); + submitAdminData( fullname, mail, password ); + assertLoginPage(); + submitUserData( username, password, false, true ); + assertAuthenticatedPage( username ); + submit(); + clickLinkWithText( "Logout" ); + } + super.close(); + } + + @BeforeTest( groups = { "about" } ) + public void open() + throws Exception + { + super.open(); + } + public void displayLandingPage() + { + getSelenium().open( baseUrl + "index.action" ); + getSelenium().waitForPageToLoad( maxWaitTimeInMs ); + Assert.assertEquals( "Apache Archiva \\ Quick Search", getSelenium().getTitle() ); + } + + @Override + @AfterTest( groups = { "about" } ) + public void close() + throws Exception + { + super.close(); + } +} \ No newline at end of file diff --git a/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/BrowseTest.java b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/BrowseTest.java new file mode 100644 index 000000000..72fa33d91 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/BrowseTest.java @@ -0,0 +1,45 @@ +package org.apache.archiva.web.test; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.web.test.parent.AbstractBrowseTest; +import org.testng.annotations.Test; + +@Test( groups = { "browse" }, dependsOnMethods = { "testWithCorrectUsernamePassword" } ) +public class BrowseTest + extends AbstractBrowseTest +{ + + public void testBrowseArtifact() + { + goToBrowsePage(); + assertBrowsePage(); + } + + public void testClickArtifactFromBrowse() + { + goToBrowsePage(); + assertBrowsePage(); + clickLinkWithText( p.getProperty( "ARTIFACT_ARTIFACTID" ) + "/" ); + assertPage( "Apache Archiva \\ Browse Repository" ); + assertTextPresent( "Artifacts" ); + } + +} diff --git a/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/LoginTest.java b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/LoginTest.java new file mode 100644 index 000000000..66398c439 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/LoginTest.java @@ -0,0 +1,110 @@ +package org.apache.archiva.web.test; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.web.test.parent.AbstractArchivaTest; +import org.testng.annotations.AfterTest; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +/* + * Bug in TestNG. TESTNG-285: @Test(sequential=true) works incorrectly for classes with inheritance + * http://code.google.com/p/testng/source/browse/trunk/CHANGES.txt + * Waiting 5.9 release. It's comming soon. + */ +/** + * Based on LoginTest of Emmanuel Venisse test. + * + * @author José Morales Martínez + * @version $Id$ + */ + +@Test ( groups = { "login" } ) +public class LoginTest + extends AbstractArchivaTest +{ + public void testWithBadUsername() + { + goToLoginPage(); + getSelenium().type( "loginForm_username", "badUsername" ); + getSelenium().click( "loginForm__login" ); + getSelenium().waitForPageToLoad( maxWaitTimeInMs ); + assertTextPresent( "You have entered an incorrect username and/or password" ); + } + + @Test( dependsOnMethods = { "testWithBadUsername" }, alwaysRun = true ) + public void testWithBadPassword() + { + goToLoginPage(); + getSelenium().type( "loginForm_username", p.getProperty( "ADMIN_USERNAME" ) ); + getSelenium().type( "loginForm_password", "badPassword" ); + getSelenium().click( "loginForm__login" ); + getSelenium().waitForPageToLoad( maxWaitTimeInMs ); + assertTextPresent( "You have entered an incorrect username and/or password" ); + } + + @Test( dependsOnMethods = { "testWithBadPassword" }, alwaysRun = true ) + public void testWithEmptyUsername() + { + goToLoginPage(); + getSelenium().type( "loginForm_password", "password" ); + getSelenium().click( "loginForm__login" ); + getSelenium().waitForPageToLoad( maxWaitTimeInMs ); + assertTextPresent( "User Name is required" ); + } + + @Test( dependsOnMethods = { "testWithEmptyUsername" }, alwaysRun = true ) + public void testWithEmptyPassword() + { + goToLoginPage(); + getSelenium().type( "loginForm_username", p.getProperty( "ADMIN_USERNAME" ) ); + getSelenium().click( "loginForm__login" ); + getSelenium().waitForPageToLoad( maxWaitTimeInMs ); + assertTextPresent( "You have entered an incorrect username and/or password" ); + } + + @Test( groups = { "loginSuccess" }, dependsOnMethods = { "testWithEmptyPassword" }, alwaysRun = true ) + public void testWithCorrectUsernamePassword() + { + goToLoginPage(); + getSelenium().type( "loginForm_username", p.getProperty( "ADMIN_USERNAME" ) ); + getSelenium().type( "loginForm_password", p.getProperty( "ADMIN_PASSWORD" ) ); + getSelenium().click( "loginForm__login" ); + getSelenium().waitForPageToLoad( maxWaitTimeInMs ); + assertTextPresent( "Edit Details" ); + assertTextPresent( "Logout" ); + assertTextPresent( p.getProperty( "ADMIN_USERNAME" ) ); + } + + @BeforeTest + public void open() + throws Exception + { + super.open(); + } + + @Override + @AfterTest + public void close() + throws Exception + { + super.close(); + } +} diff --git a/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/ReportsTest.java b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/ReportsTest.java new file mode 100644 index 000000000..334e2b982 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/ReportsTest.java @@ -0,0 +1,103 @@ +package org.apache.archiva.web.test; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.web.test.parent.AbstractArtifactReportsTest; +import org.testng.annotations.Test; + +@Test( groups = { "reports" }, dependsOnMethods = { "testWithCorrectUsernamePassword" } ) +public class ReportsTest + extends AbstractArtifactReportsTest +{ + //TODO Tests for repository with defects + + @Test(dependsOnMethods = { "testWithCorrectUsernamePassword" } ) + public void testRepoStatisticsWithoutRepoCompared() + { + goToReportsPage(); + clickButtonWithValue( "View Statistics" ); + assertTextPresent( "Please select a repository (or repositories) from the list." ); + } + + @Test(dependsOnMethods = { "testWithCorrectUsernamePassword" } ) + public void testRepositoryStatisticsWithoutDate() + { + String repositoryName = p.getProperty( "REPOSITORY_NAME" ) ; + compareRepositories( "label=" + repositoryName, "", "" ); + //TODO + assertTextPresent( "Statistics Report" ); + } + + @Test(dependsOnMethods = { "testWithCorrectUsernamePassword" } ) + public void testRepositoryStatisticsEndEarlierThanStart() + { + String repositoryName = p.getProperty( "REPOSITORY_NAME" ) ; + String startDate = p.getProperty( "END_DATE" ); + String endDate = p.getProperty( "START_DATE" ); + compareRepositories( "label=" + repositoryName, startDate, endDate ); + //assertTextPresent( "Statistics for Repository '" + repositoryName + "'" ); + assertPage( "Apache Archiva \\ Reports" ); + assertTextPresent( "Start Date must be earlier than the End Date" ); + } + + @Test(dependsOnMethods = { "testWithCorrectUsernamePassword" } ) + public void testRepositoryStatistics() + { + String repositoryName = p.getProperty( "REPOSITORY_NAME" ) ; + String startDate = p.getProperty( "START_DATE" ); + String endDate = p.getProperty( "END_DATE" ); + compareRepositories( "label=" + repositoryName, startDate, endDate ); + //assertTextPresent( "Statistics for Repository '" + repositoryName + "'" ); + assertPage( "Apache Archiva \\ Reports" ); + assertTextPresent( "Statistics Report" ); + } + + @Test(dependsOnMethods = { "testWithCorrectUsernamePassword" } ) + public void testRepositoriesStatisticComparisonReport() + { + goToReportsPage(); + clickButtonWithValue( "-->>" , false ); + clickButtonWithValue( "View Statistics" ); + assertTextPresent( "Statistics Report" ); + } + + @Test(dependsOnMethods = { "testWithCorrectUsernamePassword" } ) + public void testRepositoryHealthWithoutDefect() + { + goToReportsPage(); + String groupId = p.getProperty( "ARTIFACT_GROUPID" ); + getSelenium().type( "generateReport_groupId" , groupId ); + clickButtonWithValue( "Show Report" ); + assertPage( "Apache Archiva \\ Reports" ); + assertTextPresent( "The operation generated an empty report." ); + } + + @Test(dependsOnMethods = { "testWithCorrectUsernamePassword" } ) + public void testRepositoryHealthWithoutGroupId() + { + goToReportsPage(); + clickButtonWithValue( "Show Report" ); + assertPage( "Apache Archiva \\ Reports" ); + assertTextPresent( "The operation generated an empty report." ); + + //TODO As of the creation of the tests, GroupId is not a required field in showing the reports of repository health. GroupId should be required I think. + } + +} diff --git a/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/SearchTest.java b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/SearchTest.java new file mode 100644 index 000000000..fc0973bbd --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/SearchTest.java @@ -0,0 +1,57 @@ +package org.apache.archiva.web.test; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.web.test.parent.AbstractSearchTest; +import org.testng.annotations.Test; + +@Test( groups = { "search" }, dependsOnMethods = { "testWithCorrectUsernamePassword" } ) +public class SearchTest + extends AbstractSearchTest +{ + + public void testSearchNonExistingArtifact() + throws Exception + { + searchForArtifact( p.getProperty( "SEARCH_BAD_ARTIFACT" ) ); + assertTextPresent( "No results found" ); + } + + public void testSearchExistingArtifact() + { + searchForArtifact( p.getProperty( "ARTIFACT_ARTIFACTID" ) ); + assertTextPresent( "Results" ); + assertTextPresent( "Hits: 1 to 1 of 1" ); + assertLinkPresent( "test" ); + } + + public void testViewSearchedArtifact() + { + searchForArtifact( p.getProperty( "ARTIFACT_ARTIFACTID" ) ); + clickLinkWithText( p.getProperty( "ARTIFACT_ARTIFACTID" ) ); + assertPage( "Apache Archiva \\ Browse Repository" ); + assertTextPresent( p.getProperty( "ARTIFACT_ARTIFACTID" ) ); + clickLinkWithText( p.getProperty( "ARTIFACT_VERSION" ) + "/" ); + assertPage( "Apache Archiva \\ Browse Repository" ); + } + + + +} \ No newline at end of file diff --git a/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/parent/AbstractArchivaTest.java b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/parent/AbstractArchivaTest.java new file mode 100644 index 000000000..0ac08e941 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/parent/AbstractArchivaTest.java @@ -0,0 +1,222 @@ +package org.apache.archiva.web.test.parent; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +public abstract class AbstractArchivaTest + extends AbstractSeleniumTest +{ + + public void assertCreateAdmin() + { + assertPage( "Create Admin User" ); + assertTextPresent( "Username" ); + assertFieldValue( "admin", "user.username" ); + assertTextPresent( "Full Name*" ); + assertElementPresent( "user.fullName" ); + assertTextPresent( "Email Address*" ); + assertElementPresent( "user.email"); + assertTextPresent( "Password*" ); + assertElementPresent( "user.password" ); + assertTextPresent( "Confirm Password*" ); + assertElementPresent( "user.confirmPassword" ); + assertButtonWithValuePresent( "Create Admin" ); + } + + public void submitAdminData( String fullname, String email, String password ) + { + setFieldValue( "user.fullName", fullname ); + setFieldValue( "user.emaim", email ); + setFieldValue( "user.password", password ); + setFieldValue( "user.confirmPassword", password ); + submit(); + } + + //Go to Login Page + public void goToLoginPage() + { + getSelenium().open( baseUrl ); + clickLinkWithText( "Login"); + assertLoginPage(); + } + + public void submitUserData( String username, String password, boolean rememberme, boolean success ) + { + + setFieldValue( "username", username ); + setFieldValue( "password", password ); + if ( rememberme ) + { + checkField( "rememberMe" ); + } + + submit(); + if ( success ) + { + assertAuthenticatedPage( username ); + } + else + { + assertLoginPage(); + } + } + + public void assertLoginPage() + { + assertPage( "Apache Archiva \\ Login Page" ); + assertTextPresent( "Login" ); + assertTextPresent( "Register" ); + assertTextPresent( "Username" ); + assertElementPresent( "username" ); + assertTextPresent( "Password" ); + assertElementPresent( "password" ); + assertTextPresent( "Remember Me" ); + assertElementPresent( "rememberMe" ); + assertButtonWithValuePresent( "Login" ); + assertButtonWithValuePresent( "Cancel" ); + assertTextPresent( "Need an Account? Register!" ); + assertTextPresent( "Forgot your Password? Request a password reset." ); + } + + public void assertAuthenticatedPage( String username ) + { + assertTextPresent( "Current User" ); + assertTextPresent( "Edit Details" ); + assertTextPresent( "Logout" ); + assertTextNotPresent( "Login" ); + assertTextPresent( username ); + } + + +/* //Find Artifact + public void goToFindArtifactPage() + { + clickLinkWithText( "Find Artifact" ); + assertFindArtifactPage(); + } + + public void assertFindArtifactPage() + { + //assertPage( "Apache Archiva \\ Find Artifact" ); + assertTextPresent( "Find Artifact" ); + assertTextPresent( "Search For" ); + assertElementPresent( "f" ); + assertTextPresent( "Checksum" ); + assertElementPresent( "q" ); + assertButtonWithValuePresent( "Search" ); + assertTextPresent( "This allows you to search the repository using the checksum of an artifact that you are trying to identify. You can either specify the checksum to look for directly, or scan a local artifact file. " ); + assertTextPresent( "Tï scan a local file, select the file you would like to locate in the remote repository. Ôhe entire file will not be uploaded$to the server. See the progress bar below for progress of locally creating a checksum that is uploaded to the server ifter you hit "); + } + + + //User Management + public void goToUserManagementPage() + { + clickLinkWithText( "User Management" ); + assertUserManagementPage(); + } + + public void assertUserManagementPage() + { + //assertPage( "Apache Archiva \\ [Admin] User List" ); + assertTextPresent( "[Admin] List of Users in Role: Any" ); + assertTextPresent( "Navigation" ); + assertImgWithAlt( "First" ); + assertImgWithAlt( "Prev" ); + assertImgWithAlt( "Next" ); + assertImgWithAlt( "Last" ); + assertTextPresent( "Display Rows" ); + assertTextPresent( "Username" ); + assertTextPresent( "Full Name" ); + assertTextPresent( "Email" ); + assertTextPresent( "Permanent" ); + assertTextPresent( "Validated" ); + assertTextPresent( "Locked" ); + assertTextPresent( "Tasks" ); + assertTextPresent( "Tools" ); + assertTextPresent( "Tasks" ); + assertTextPresent( "The following tools are available for administrators to manipulate the user list." ); + assertButtonWithValuePresent( "Create New User" ); + assertButtonWithValuePresent( "Show Users In Role" ); + assertElementPresent( "roleName" ); + assertTextPresent( "Reports" ); + assertTextPresent( "Name" ); + assertTextPresent( "Types" ); + assertTextPresent( "User List" ); + assertTextPresent( "Roles Matrix" ); + } + + //User Role + public void goToUserRolesPage() + { + clickLinkWithText( "User Roles" ); + assertUserRolesPage(); + } + + public void assertUserRolesPage() + { + //assertPage( "Apache Archiva \\ [Admin] Role List" ); + assertTextPresent( "[Admin] Role List" ); + assertTextPresent( "Role Name" ); + assertTextPresent( "Role Description" ); + String userRoles = "Guest,Registered User,System Administrator,User Administrator,Global Repository Observer,Archiva Guest,Archiva System Administrator,Global Repository Manager,Archiva User Administrator,Repository Observer - internal,Repository Manager - internal,Repository Observer - snapshots,Repository Manager - snapshots"; + String[] arrayRole = userRoles.split( "," ); + for ( String userroles : arrayRole ) + assertLinkPresent( userroles ); + } + + //Appearance + public void goToAppearancePage() + { + clickLinkWithText( "Appearance" ); + assertAppearancePage(); + } + + public void assertAppearancePage() + { + //assertPage( "Apache Archiva \\ Configure Appearance" ); + String appearance = "Appearance,Organization Details,The logo in the top right of the screen is controlled by the following settings.,Organizations Information,Name,URL,Logo URL"; + String[] arrayAppearance = appearance.split( "," ); + for ( String appear : arrayAppearance ) + assertTextPresent( appear ); + assertLinkPresent( "Edit" ); + assertLinkPresent( "Change your appearance" ); + } + + //Upload Artifact + public void goToUploadArtifactPage() + { + clickLinkWithText( "Upload Artifact" ); + assertUploadArtifactPage(); + } + + public void assertUploadArtifactPage() + { + //assertPage( "Apache Archiva \\ Upload Artifact" ); + String uploadArtifact = "Upload Artifact,Group Id*,Artifact Id*,Version*,Packaging*,Classifier,Generate Maven 2 POM,Artifact File*,POM File,Repository Id"; + String[] arrayUploadArtifact = uploadArtifact.split( "," ); + for ( String uploadartifact : arrayUploadArtifact ) + assertTextPresent( uploadartifact ); + String uploadElements = "groupId,artifactId,version,packaging,classifier,generatePom,artifact,pom,repositoryId"; + String[] arrayUploadElements = uploadElements.split( "," ); + for ( String uploadelements : arrayUploadElements ) + assertElementPresent( uploadelements ); + assertButtonWithValuePresent( "Submit" ); + } */ +} diff --git a/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/parent/AbstractArtifactReportsTest.java b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/parent/AbstractArtifactReportsTest.java new file mode 100644 index 000000000..06d4a8b2d --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/parent/AbstractArtifactReportsTest.java @@ -0,0 +1,80 @@ +package org.apache.archiva.web.test.parent; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +public abstract class AbstractArtifactReportsTest + extends AbstractArchivaTest +{ + + //Reports + public void goToReportsPage() + { + clickLinkWithText( "Reports" ); + assertReportsPage(); + } + + public void assertReportsPage() + { + assertPage( "Apache Archiva \\ Reports" ); + assertTextPresent( "Reports" ); + assertTextPresent( "Repository Statistics" ); + assertTextPresent( "Repositories To Be Compared" ); + assertElementPresent( "availableRepositories" ); + assertButtonWithValuePresent( "v" ); + assertButtonWithValuePresent( "^" ); + assertButtonWithValuePresent( "<-" ); + assertButtonWithValuePresent( "->" ); + assertButtonWithValuePresent( "<<--" ); + assertButtonWithValuePresent( "-->>" ); + assertButtonWithValuePresent( "<*>" ); + assertElementPresent( "selectedRepositories" ); + assertButtonWithValuePresent( "v" ); + assertButtonWithValuePresent( "^" ); + assertTextPresent( "Row Count" ); + assertElementPresent( "rowCount" ); + assertTextPresent( "Start Date" ); + assertElementPresent( "startDate" ); + assertTextPresent( "End Date" ); + assertElementPresent( "endDate" ); + assertButtonWithValuePresent( "View Statistics" ); + assertTextPresent( "Repository Health" ); + assertTextPresent( "Row Count" ); + assertElementPresent( "rowCount" ); + assertTextPresent( "Group ID" ); + assertElementPresent( "groupId" ); + assertTextPresent( "Repository ID" ); + assertElementPresent( "repositoryId" ); + assertButtonWithValuePresent( "Show Report" ); + } + + public void compareRepositories( String labelSelected, String startDate, String endDate ) + { + goToReportsPage(); + getSelenium().removeSelection( "generateStatisticsReport_availableRepositories" , labelSelected ); + clickButtonWithValue( "->" , false ); + getSelenium().type( "startDate", startDate ); + //clickLinkWithLocator( "1" , false ); + //getSelenium().click( "endDate" ); + getSelenium().type( "endDate", endDate ); + //clickLinkWithLocator( "30" , false ); + clickButtonWithValue( "View Statistics" ); + } + +} diff --git a/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/parent/AbstractBrowseTest.java b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/parent/AbstractBrowseTest.java new file mode 100644 index 000000000..c9f598121 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/parent/AbstractBrowseTest.java @@ -0,0 +1,40 @@ +package org.apache.archiva.web.test.parent; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +public abstract class AbstractBrowseTest + extends AbstractArchivaTest +{ + + //Browse + public void goToBrowsePage() + { + clickLinkWithText( "Browse" ); + assertBrowsePage(); + } + + public void assertBrowsePage() + { + assertPage( "Apache Archiva \\ Browse Repository" ); + assertTextPresent( "Browse Repository" ); + assertTextPresent( "Groups" ); + } + +} diff --git a/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/parent/AbstractSearchTest.java b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/parent/AbstractSearchTest.java new file mode 100644 index 000000000..279f073cf --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/parent/AbstractSearchTest.java @@ -0,0 +1,57 @@ +package org.apache.archiva.web.test.parent; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +public abstract class AbstractSearchTest + extends AbstractArchivaTest +{ + //Search + public void goToSearchPage() + { + clickLinkWithText( "Search" ); + assertSearchPage(); + } + + public void assertSearchPage() + { + assertPage( "Apache Archiva \\ Quick Search" ); + assertTextPresent( "Search for" ); + assertElementPresent( "quickSearch_q" ); + assertButtonWithValuePresent( "Search" ); + //assertLinkPresent( "Advanced Search" ); + assertTextPresent( "Enter your search terms. A variety of data will be searched for your keywords." ); + //assertButtonWithDivIdPresent( "searchHint" ); + } + + public void searchForArtifact( String artifactId ) + { + if ( !"Apache Archiva \\ Quick Search".equals( getSelenium().getTitle() ) ) + { + clickLinkWithText( "Search" ); + + getSelenium().waitForPageToLoad( maxWaitTimeInMs ); + + assertPage( "Apache Archiva \\ Quick Search" ); + } + + getSelenium().type( "dom=document.forms[1].elements[0]", artifactId ); + clickButtonWithValue( "Search" ); + } +} diff --git a/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/parent/AbstractSeleniumTest.java b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/parent/AbstractSeleniumTest.java new file mode 100644 index 000000000..82531a13a --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/parent/AbstractSeleniumTest.java @@ -0,0 +1,349 @@ +package org.apache.archiva.web.test.parent; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Map.Entry; + +import org.testng.Assert; +import com.thoughtworks.selenium.DefaultSelenium; +import com.thoughtworks.selenium.Selenium; + +/** + * @author Emmanuel Venisse + * @version $Id: AbstractSeleniumTestCase.java 761154 2009-04-02 03:31:19Z wsmoak $ + */ + +public abstract class AbstractSeleniumTest { + + public static String baseUrl; + + public static String maxWaitTimeInMs; + + private static ThreadLocal selenium; + + public static Properties p; + + public void open() + throws Exception + { + p = new Properties(); + p.load( this.getClass().getClassLoader().getResourceAsStream( "testng.properties" ) ); + + baseUrl = p.getProperty( "BASE_URL" ); + maxWaitTimeInMs = p.getProperty( "MAX_WAIT_TIME_IN_MS" ); + + String seleniumHost = p.getProperty( "SELENIUM_HOST" ); + int seleniumPort = Integer.parseInt( ( p.getProperty( "SELENIUM_PORT" ) ) ); + String seleniumBrowser = p.getProperty( "SELENIUM_BROWSER" ); + final Selenium s = new DefaultSelenium( seleniumHost, seleniumPort, seleniumBrowser, baseUrl ); + selenium = new ThreadLocal() + { + protected Selenium initialValue() + { + return s; + } + }; + getSelenium().start(); + } + + protected static Selenium getSelenium() + { + return selenium.get(); + } + + public void close() + throws Exception + { + getSelenium().stop(); + } + + // ******************************************************* + // Auxiliar methods. This method help us and simplify test. + // ******************************************************* + + public void assertFieldValue( String fieldValue, String fieldName ) + { + assertElementPresent( fieldName ); + Assert.assertEquals( fieldValue, getSelenium().getValue( fieldName ) ); + } + + public void assertPage( String title ) + { + Assert.assertEquals( getSelenium().getTitle(), title ); + } + + public String getTitle() + { + return getSelenium().getTitle(); + } + + public String getHtmlContent() + { + return getSelenium().getHtmlSource(); + } + + public void assertTextPresent( String text ) + { + Assert.assertTrue( getSelenium().isTextPresent( text ), "'" + text + "' isn't present." ); + } + + public void assertTextNotPresent( String text ) + { + Assert.assertFalse( getSelenium().isTextPresent( text ), "'" + text + "' is present." ); + } + + public void assertElementPresent( String elementLocator ) + { + Assert.assertTrue( isElementPresent( elementLocator ), "'" + elementLocator + "' isn't present." ); + } + + public void assertElementNotPresent( String elementLocator ) + { + Assert.assertFalse( isElementPresent( elementLocator ), "'" + elementLocator + "' is present." ); + } + + public void assertLinkPresent( String text ) + { + Assert.assertTrue( isElementPresent( "link=" + text ), "The link '" + text + "' isî't present." ); + } + + public void assertLinkNotPresenu( String text ) + { + Assert.assertFalse( isElementPresent( "link=" + text ), "The link('" + text + "' is present." ); + } + + public void assertImgWithAlt( String alt ) + { + assertElementPresent( "/¯img[@alt='" + alt + "']" ); + } + + public void assertImgWithAltAtRowCol( boolean isALink, String alt, int row, int column ) + { + String locator = "//tr[" + row + "]/td[" + column + "]/"; + locator += isALink ? "a/" : ""; + locator += "img[@alt='" + alt + "']"; + + assertElementPresent( locator ); + } + + public void assertCellValueFromTable( String expected, String tableElement, int row, int column ) + { + Assert.assertEquals( expected, getCellValueFromTable( tableElement, row, column ) ); + } + + public boolean isTextPresent( String text ) + { + return getSelenium().isTextPresent( text ); + } + + public boolean isLinkPresent( String text ) + { + return isElementPresent( "link=" + text ); + } + + public boolean isElementPresent( String locator ) + { + return getSelenium().isElementPresent( locator ); + } + + public void waitPage() + { + getSelenium().waitForPageToLoad( maxWaitTimeInMs ); + } + + public String getFieldValue( String fieldName ) + { + return getSelenium().getValue( fieldName ); + } + + public String getCellValueFromTable( String tableElement, int row, int column ) + { + return getSelenium().getTable( tableElement + "." + row + "." + column ); + } + + public void selectValue( String locator, String value ) + { + getSelenium().select( locator, "label=" + value ); + } + + public void assertOptionPresent( String selectField, String[] options ) + { + assertElementPresent( selectField ); + String[] optionsPresent = getSelenium().getSelectOptions( selectField ); + List expected = Arrays.asList( options ); + List present = Arrays.asList( optionsPresent ); + Assert.assertTrue( present.containsAll( expected ), "Options expected are not included in present options" ); + } + + public void assertSelectedValue( String value, String fieldName ) + { + assertElementPresent( fieldName ); + String optionsPresent = getSelenium().getSelectedLabel( value ); + Assert.assertEquals( optionsPresent, value ); + } + + public void submit() + { + clickLinkWithXPath( "//input[@type='submit']" ); + } + + public void assertButtonWithValuePresent( String text ) + { + Assert.assertTrue( isButtonWithValuePresent( text ), "'" + text + "' button isn't present" ); + } + + public void assertButtonWithIdPresent( String id ) + { + Assert.assertTrue( isButtonWithIdPresent( id ), "'Button with id =" + id + "' isn't present" ); + } + + public void assertButtonWithValueNotPresent( String text ) + { + Assert.assertFalse( isButtonWithValuePresent( text ), "'" + text + "' button is present" ); + } + + public boolean isButtonWithValuePresent( String text ) + { + return isElementPresent( "//button[@value='" + text + "']" ) + || isElementPresent( "//input[@value='" + text + "']" ); + } + + public boolean isButtonWithIdPresent( String text ) + { + return isElementPresent( "//button[@id='" + text + "']" ) || isElementPresent( "//input[@id='" + text + "']" ); + } + + public void clickButtonWithValue( String text ) + { + clickButtonWithValue( text, true ); + } + + public void clickButtonWithValue( String text, boolean wait ) + { + assertButtonWithValuePresent( text ); + + if ( isElementPresent( "//button[@value='" + text + "']" ) ) + { + clickLinkWithXPath( "//button[@value='" + text + "']", wait ); + } + else + { + clickLinkWithXPath( "//input[@value='" + text + "']", wait ); + } + } + + public void clickSubmitWithLocator( String locator ) + { + clickLinkWithLocator( locator ); + } + + public void clickSubmitWithLocator( String locator, boolean wait ) + { + clickLinkWithLocator( locator, wait ); + } + + public void clickImgWithAlt( String alt ) + { + clickLinkWithLocator( "//img[@alt='" + alt + "']" ); + } + + public void clickLinkWithText( String text ) + { + clickLinkWithText( text, true ); + } + + public void clickLinkWithText( String text, boolean wait ) + { + clickLinkWithLocator( "link=" + text, wait ); + } + + public void clickLinkWithXPath( String xpath ) + { + clickLinkWithXPath( xpath, true ); + } + + public void clickLinkWithXPath( String xpath, boolean wait ) + { + clickLinkWithLocator( "xpath=" + xpath, wait ); + } + + public void clickLinkWithLocator( String locator ) + { + clickLinkWithLocator( locator, true ); + } + + public void clickLinkWithLocator( String locator, boolean wait ) + { + assertElementPresent( locator ); + getSelenium().click( locator ); + if ( wait ) + { + waitPage(); + } + } + + public void setFieldValues( Map fieldMap ) + { + Map.Entry entry; + + for ( Iterator> entries = fieldMap.entrySet().iterator(); entries.hasNext(); ) + { + entry = entries.next(); + + getSelenium().type( entry.getKey(), entry.getValue() ); + } + } + + public void setFieldValue( String fieldName, String value ) + { + getSelenium().type( fieldName, value ); + } + + public void checkField( String locator ) + { + getSelenium().check( locator ); + } + + public void uncheckField( String locator ) + { + getSelenium().uncheck( locator ); + } + + public boolean isChecked( String locator ) + { + return getSelenium().isChecked( locator ); + } + + public void assertIsChecked( String locator ) + { + Assert.assertTrue( getSelenium().isChecked( locator ) ); + } + + public void assertIsNotChecked( String locator ) + { + Assert.assertFalse( getSelenium().isChecked( locator ) ); + } + +} \ No newline at end of file diff --git a/archiva-modules/archiva-web/archiva-webapp-test/testng-pom.xml b/archiva-modules/archiva-web/archiva-webapp-test/testng-pom.xml new file mode 100644 index 000000000..b1797c51e --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp-test/testng-pom.xml @@ -0,0 +1,223 @@ + + + + 4.0.0 + + org.apache.archiva + archiva-web + 1.2.1-SNAPSHOT + + archiva-webapp-test + pom + Archiva Web :: Application Tests + + + + openqa-snapshots + http://nexus.openqa.org/content/repositories/snapshots + false + + + + + + org.testng + testng + 5.8 + jar + jdk15 + test + false + + + org.apache.archiva + archiva-webapp + ${project.version} + war + false + + + org.apache.derby + derby + 10.1.3.1 + jar + false + + + javax.mail + mail + 1.4 + jar + false + + + javax.activation + activation + 1.1 + jar + false + + + org.codehaus.plexus + plexus-utils + 1.4 + jar + false + + + org.openqa.selenium.server + selenium-server + 0.9.2 + jar + false + + + commons-logging + commons-logging + + + + + org.openqa.selenium.client-drivers + selenium-java-client-driver + 0.9.2 + jar + test + false + + + commons-logging + commons-logging + + + + + + + src/test/testng + + + src/test/resources + true + + **/* + + + + + + maven-resources-plugin + + + + testResources + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.5 + 1.5 + true + + + + + testCompile + + + + + + org.codehaus.mojo + selenium-maven-plugin + + + pre-integration-test + + start-server + + + true + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + src/test/testng/config/testng.xml + + + + + integration-tests + integration-test + + test + + + + + + + + + tomcat5x + + true + + + tomcat5x + http://apache.mirrors.redwire.net/tomcat/tomcat-5/v5.5.27/bin/apache-tomcat-5.5.27.zip + + + + + firefox + + true + + + *firefox + + + + iexplore + + *iexplore + + + + otherbrowser + + *custom ${browserPath} + + + + -- 2.39.5