Skip to content
Snippets Groups Projects
Commit 2a82238d authored by Christoph Thelen's avatar Christoph Thelen
Browse files

Selenium integration tests

parent fa0d319f
Branches
Tags
No related merge requests found
......@@ -2,3 +2,4 @@
.classpath
.settings/*
target/*
chromedriver.log
......@@ -222,7 +222,13 @@
<groupId>couchdb4j</groupId>
<artifactId>couchdb4j</artifactId>
<version>0.3.0-i386-1</version>
<exclusions>
<!-- Exclude httpclient: Selenium loads a more current version -->
<exclusion>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.sf.ezmorph</groupId>
......@@ -295,6 +301,11 @@
<artifactId>spring-aspects</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.25.0</version>
</dependency>
</dependencies>
<build>
<plugins>
......@@ -305,7 +316,7 @@
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
......@@ -330,6 +341,9 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.2</version>
<configuration>
<excludes>
<exclude>**/Selenium*.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
......@@ -356,6 +370,78 @@
<configLocation>ARSnova-checkstyle-checker.xml</configLocation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<url>http://localhost:8080/manager/text</url>
<server>arsnova</server>
<path>/arsnova-war</path>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<includes>
<include>**/Selenium*.java</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.2.0</version>
<configuration>
<container>
<containerId>tomcat7x</containerId>
<zipUrlInstaller>
<url>http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.16/bin/apache-tomcat-7.0.16.zip
</url>
<downloadDir>${project.build.directory}/downloads</downloadDir>
<extractDir>${project.build.directory}/extracts</extractDir>
</zipUrlInstaller>
</container>
<configuration>
<deployables>
<deployable>
<groupId>de.thm.arsnova</groupId>
<artifactId>arsnova-war</artifactId>
<type>war</type>
<properties>
<context>arsnova-war</context>
</properties>
</deployable>
</deployables>
</configuration>
</configuration>
<executions>
<execution>
<id>start-tomcat</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-tomcat</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
......
......@@ -105,6 +105,14 @@ public class CouchDBDao implements IDatabaseDao {
logger.info(databaseName);
this.databaseName = databaseName;
}
public void setSessionService(ISessionService sessionService) {
this.sessionService = sessionService;
}
public void setUserService(IUserService userService) {
this.userService = userService;
}
/**
* This method cleans up old feedback votes at the scheduled interval.
......
/*
* Copyright (C) 2012 THM webMedia
*
* This file is part of ARSnova.
*
* ARSnova is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ARSnova is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.thm.arsnova;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.html5.*;
import org.openqa.selenium.remote.html5.*;
public class ARSnovaChromeDriver extends ChromeDriver implements WebStorage {
public LocalStorage getLocalStorage() {
return new RemoteLocalStorage(this.getExecuteMethod());
}
@Override
public SessionStorage getSessionStorage() {
return new RemoteSessionStorage(this.getExecuteMethod());
}
}
package de.thm.arsnova;
import static org.junit.Assert.*;
import java.io.IOException;
import java.util.Properties;
import org.junit.*;
import org.openqa.selenium.*;
import org.openqa.selenium.html5.LocalStorage;
import org.openqa.selenium.support.ui.*;
import org.springframework.core.io.*;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import de.thm.arsnova.dao.CouchDBDao;
import de.thm.arsnova.entities.Session;
import de.thm.arsnova.services.*;
public class Selenium2Test {
ARSnovaChromeDriver driver;
Properties properties;
CouchDBDao couchdbDao;
SessionService sessionService;
StubUserService userService;
@Before
public void setUp() throws IOException {
Resource resource = new FileSystemResource("/etc/arsnova/arsnova.properties");
properties = PropertiesLoaderUtils.loadProperties(resource);
userService = new StubUserService();
userService.setUserAuthenticated(true);
couchdbDao = new CouchDBDao();
couchdbDao.setDatabaseHost(properties.getProperty("couchdb.host", "localhost"));
couchdbDao.setDatabasePort(properties.getProperty("couchdb.port", "5984"));
couchdbDao.setDatabaseName(properties.getProperty("couchdb.name", "arsnova"));
sessionService = new SessionService();
couchdbDao.setSessionService(sessionService);
couchdbDao.setUserService(userService);
sessionService.setDatabaseDao(couchdbDao);
this.driver = new ARSnovaChromeDriver();
driver.get(properties.getProperty("security.arsnova-url", "http://localhost:8080/arsnova-war/"));
LocalStorage localStorage = this.driver.getLocalStorage();
localStorage.setItem("html5 info read", "");
}
@After
public void tearDown() {
driver.close();
driver.quit();
}
@Test
public void studentGuestShouldBeAbleToJoinSession() {
Session session = new Session();
session.setName("selenium test session");
session.setShortName("selenium");
session = couchdbDao.saveSession(session);
WebElement studentRoleButton = waitForElement(By.id("ext-gen1047"));
studentRoleButton.click();
WebElement guestLoginButton = waitForElement(By.id("ext-gen1016"));
guestLoginButton.click();
WebElement sessionKeywordField = waitForElement(By.name("keyword"));
sessionKeywordField.sendKeys(session.getKeyword());
WebElement joinSessionButton = waitForElement(By.id("ext-gen1138"));
joinSessionButton.click();
WebElement feedbackGoodButton = waitForElement(By.className("feedbackGood"));
assertTrue(feedbackGoodButton.isDisplayed());
}
private WebElement waitForElement(final By by) {
(new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
return d.findElement(by) != null;
}
});
return driver.findElement(by);
}
}
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment