added selenium test case for authentication

This commit is contained in:
Sebastian Sdorra
2012-06-23 16:41:47 +02:00
parent ef00ad320b
commit 1a062efc3e
4 changed files with 451 additions and 0 deletions

View File

@@ -231,6 +231,20 @@
</exclusions> </exclusions>
</dependency> </dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.24.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>2.24.1</version>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>com.jcraft</groupId> <groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId> <artifactId>jsch</artifactId>
@@ -435,6 +449,11 @@
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId> <artifactId>maven-failsafe-plugin</artifactId>
<version>2.12</version> <version>2.12</version>
<configuration>
<includes>
<include>sonia/scm/it/*ITCase.java</include>
</includes>
</configuration>
<executions> <executions>
<execution> <execution>
<id>integration-test</id> <id>integration-test</id>
@@ -499,6 +518,110 @@
</profile> </profile>
<profile>
<id>selenium</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.12</version>
<configuration>
<includes>
<include>sonia/scm/selenium/*ITCase.java</include>
</includes>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.26</version>
<configuration>
<stopPort>8086</stopPort>
<stopKey>STOP</stopKey>
<systemProperties>
<systemProperty>
<name>scm.home</name>
<value>target/scm-it</value>
</systemProperty>
</systemProperties>
<connectors>
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>8082</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
<source>${project.build.javaLevel}</source>
<target>${project.build.javaLevel}</target>
<encoding>${project.build.sourceEncoding}</encoding>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>deploy-war</goal>
</goals>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>selenium-maven-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>start-selenium-server</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start-server</goal>
</goals>
<configuration>
<background>true</background>
</configuration>
</execution>
<execution>
<id>stop-selenium-server</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop-server</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile> <profile>
<id>doc</id> <id>doc</id>

View File

@@ -82,6 +82,7 @@ Sonia.login.Form = Ext.extend(Ext.FormPanel,{
scope: this, scope: this,
handler: this.cancel handler: this.cancel
},{ },{
id: 'loginButton',
text: this.loginText, text: this.loginText,
formBind: true, formBind: true,
scope: this, scope: this,

View File

@@ -0,0 +1,57 @@
/**
* Copyright (c) 2010, Sebastian Sdorra All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. 2. Redistributions in
* binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. 3. Neither the name of SCM-Manager;
* nor the names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.selenium;
//~--- non-JDK imports --------------------------------------------------------
import org.junit.Test;
/**
*
* @author Sebastian Sdorra
*/
public class AuthenticationITCase extends SeleniumTestBase
{
/**
* Method description
*
*
* @throws Exception
*/
@Test
public void testAuthentication() throws Exception
{
authenticate("scmadmin", "scmadmin");
logout();
}
}

View File

@@ -0,0 +1,270 @@
/**
* Copyright (c) 2010, Sebastian Sdorra All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. 2. Redistributions in
* binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. 3. Neither the name of SCM-Manager;
* nor the names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.selenium;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.io.Files;
import org.junit.After;
import org.junit.Before;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.junit.Assert.*;
//~--- JDK imports ------------------------------------------------------------
import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
/**
*
* @author Sebastian Sdorra
*/
public class SeleniumTestBase
{
/**
* the logger for SeleniumTestBase
*/
private static final Logger logger =
LoggerFactory.getLogger(SeleniumTestBase.class);
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @throws Exception
*/
@After
public void tearDown() throws Exception
{
driver.quit();
}
//~--- set methods ----------------------------------------------------------
/**
* Method description
*
*
* @throws Exception
*/
@Before
public void setUp() throws Exception
{
driver = new FirefoxDriver();
baseUrl = "http://localhost:8082/scm/";
open("index.html");
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param username
* @param password
*/
protected void authenticate(String username, String password)
{
type("input[name=username]", username);
type("input[name=password]", password);
waitAndClick("#loginButton button");
String ue = waitForPresence("#scm-userinfo-tip").getText();
assertEquals(username, ue);
}
/**
* Method description
*
*/
protected void logout()
{
waitAndClick("#navLogout a");
}
/**
* Method description
*
*
* @param url
*/
protected void open(String url)
{
driver.get(baseUrl + url);
pause(500, TimeUnit.MILLISECONDS);
}
/**
* Method description
*
*
* @param value
* @param unit
*/
protected void pause(int value, TimeUnit unit)
{
driver.manage().timeouts().implicitlyWait(value, unit);
}
/**
* Method description
*
*
* @param target
*/
protected void screenshot(String target)
{
screenshot(new File(target));
}
/**
* Method description
*
*
* @param target
*/
protected void screenshot(File target)
{
try
{
File scrFile =
((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
Files.copy(scrFile, target);
}
catch (IOException ex)
{
logger.error("could not create screenshot", ex);
}
}
/**
* Method description
*
*
* @param cssSelector
*
* @return
*/
protected WebElement select(String cssSelector)
{
WebElement element = driver.findElement(By.cssSelector(cssSelector));
assertNotNull(element);
return element;
}
/**
* Method description
*
*
* @param cssLocator
* @param value
*/
protected void type(String cssLocator, String value)
{
select(cssLocator).clear();
select(cssLocator).sendKeys(value);
}
/**
* Method description
*
*
* @param query
*/
protected void waitAndClick(String query)
{
waitToBeClickable(query).click();
}
/**
* Method description
*
*
* @param query
*
* @return
*/
protected WebElement waitForPresence(String query)
{
WebDriverWait wait = new WebDriverWait(driver, 2);
return wait.until(
ExpectedConditions.presenceOfElementLocated(By.cssSelector(query)));
}
/**
* Method description
*
*
* @param query
*
* @return
*/
protected WebElement waitToBeClickable(String query)
{
WebDriverWait wait = new WebDriverWait(driver, 2);
return wait.until(
ExpectedConditions.elementToBeClickable(By.cssSelector(query)));
}
//~--- fields ---------------------------------------------------------------
/** Field description */
protected WebDriver driver;
/** Field description */
private String baseUrl;
}