Initial WebDriver tests (work in progress)
This commit is contained in:
parent
6574e47c62
commit
d582317a05
9 changed files with 2060 additions and 0 deletions
41
selenium/pom.xml
Normal file
41
selenium/pom.xml
Normal file
|
@ -0,0 +1,41 @@
|
|||
<project
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.vivoweb</groupId>
|
||||
<artifactId>vivo-selenium</artifactId>
|
||||
<version>1.9.0-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>VIVO Selenium Tests</name>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-install-plugin</artifactId>
|
||||
<version>2.5.2</version>
|
||||
<configuration>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.seleniumhq.selenium</groupId>
|
||||
<artifactId>selenium-java</artifactId>
|
||||
<version>2.48.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,37 @@
|
|||
package org.vivoweb.vivo.selenium;
|
||||
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.firefox.FirefoxDriver;
|
||||
|
||||
public final class DriverFactory {
|
||||
private static WebDriver driver = null;
|
||||
private static Object closeToken = null;
|
||||
|
||||
public static WebDriver getDriver() {
|
||||
if (driver == null) {
|
||||
driver = new FirefoxDriver();
|
||||
}
|
||||
|
||||
return driver;
|
||||
}
|
||||
|
||||
public static void close() {
|
||||
if (closeToken == null && driver != null) {
|
||||
driver.quit();
|
||||
driver = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void close(Object token) {
|
||||
if (closeToken == token || (closeToken != null && closeToken.equals(token))) {
|
||||
if (driver != null) {
|
||||
driver.quit();
|
||||
driver = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void setCloseToken(Object token) {
|
||||
closeToken = token;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package org.vivoweb.vivo.selenium;
|
||||
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.support.ui.ExpectedConditions;
|
||||
import org.openqa.selenium.support.ui.WebDriverWait;
|
||||
|
||||
public final class SeleniumUtils {
|
||||
private static String baseUrl = "http://localhost:8080/vivo";
|
||||
|
||||
public static void setBaseUrl(String baseUrl) {
|
||||
SeleniumUtils.baseUrl = baseUrl;
|
||||
}
|
||||
|
||||
public static String makeUrl(String urlPart) {
|
||||
if (urlPart.startsWith("/")) {
|
||||
return baseUrl + urlPart;
|
||||
} else {
|
||||
return baseUrl + "/" + urlPart;
|
||||
}
|
||||
}
|
||||
|
||||
public static void navigate(WebDriver driver, String urlPart) {
|
||||
driver.navigate().to(makeUrl(urlPart));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package org.vivoweb.vivo.selenium;
|
||||
|
||||
import org.junit.runner.Runner;
|
||||
import org.junit.runner.notification.RunNotifier;
|
||||
import org.junit.runners.Suite;
|
||||
import org.junit.runners.model.InitializationError;
|
||||
import org.junit.runners.model.RunnerBuilder;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.firefox.FirefoxDriver;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class VIVOSuite extends Suite {
|
||||
public VIVOSuite(Class<?> klass, RunnerBuilder builder) throws InitializationError {
|
||||
super(klass, builder);
|
||||
}
|
||||
|
||||
public VIVOSuite(RunnerBuilder builder, Class<?>[] classes) throws InitializationError {
|
||||
super(builder, classes);
|
||||
}
|
||||
|
||||
protected VIVOSuite(Class<?> klass, Class<?>[] suiteClasses) throws InitializationError {
|
||||
super(klass, suiteClasses);
|
||||
}
|
||||
|
||||
protected VIVOSuite(RunnerBuilder builder, Class<?> klass, Class<?>[] suiteClasses) throws InitializationError {
|
||||
super(builder, klass, suiteClasses);
|
||||
}
|
||||
|
||||
protected VIVOSuite(Class<?> klass, List<Runner> runners) throws InitializationError {
|
||||
super(klass, runners);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void runChild(Runner runner, RunNotifier notifier) {
|
||||
// Set Driver factory, can run multiple times
|
||||
super.runChild(runner, notifier);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package org.vivoweb.vivo.selenium.suites;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite.SuiteClasses;
|
||||
import org.vivoweb.vivo.selenium.DriverFactory;
|
||||
import org.vivoweb.vivo.selenium.VIVOSuite;
|
||||
import org.vivoweb.vivo.selenium.tests.CreateOrganization;
|
||||
import org.vivoweb.vivo.selenium.tests.RebuildSearchIndex;
|
||||
|
||||
@RunWith(VIVOSuite.class)
|
||||
@SuiteClasses(
|
||||
{
|
||||
RebuildSearchIndex.class,
|
||||
CreateOrganization.class
|
||||
}
|
||||
)
|
||||
public class AddNonPersonThings {
|
||||
@BeforeClass
|
||||
public static void setup() {
|
||||
DriverFactory.setCloseToken(AddNonPersonThings.class);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void shutdown() {
|
||||
DriverFactory.close(AddNonPersonThings.class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
package org.vivoweb.vivo.selenium.tests;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.firefox.FirefoxDriver;
|
||||
import org.openqa.selenium.interactions.Actions;
|
||||
import org.openqa.selenium.support.ui.ExpectedConditions;
|
||||
import org.openqa.selenium.support.ui.Select;
|
||||
import org.openqa.selenium.support.ui.WebDriverWait;
|
||||
import org.vivoweb.vivo.selenium.DriverFactory;
|
||||
import org.vivoweb.vivo.selenium.SeleniumUtils;
|
||||
|
||||
public class AbstractSeleniumTest {
|
||||
protected WebDriver driver;
|
||||
|
||||
protected void assertTitle(String title) {
|
||||
Assert.assertEquals(title, driver.getTitle());
|
||||
}
|
||||
|
||||
protected void clickAndWait(By by) {
|
||||
driver.findElement(by).click();
|
||||
}
|
||||
|
||||
protected void deleteAllVisibleCookies() {
|
||||
driver.manage().deleteAllCookies();
|
||||
}
|
||||
|
||||
protected void logIn(String email, String password) {
|
||||
clickAndWait(By.linkText("Log in")); // clickAndWait,link=Log in
|
||||
assertTitle("Log in to VIVO"); // aseertTitle,Log in to VIVO
|
||||
|
||||
type(By.id("loginName"), email); // type,id=loginName,testAdmin@cornell.edu
|
||||
type(By.id("loginPassword"), password); // type,id=loginPassword,Password
|
||||
|
||||
clickAndWait(By.name("loginForm")); // clickAndWait,name=loginForm
|
||||
assertTitle("VIVO"); // assertTitle,VIVO
|
||||
}
|
||||
|
||||
protected void logOut() {
|
||||
Actions actions = new Actions(driver);
|
||||
actions.moveToElement( driver.findElement(By.id("user-menu")) ).perform();
|
||||
driver.findElement(By.linkText("Log out")).click();
|
||||
}
|
||||
|
||||
protected void open(String urlPart) {
|
||||
SeleniumUtils.navigate(driver, urlPart);
|
||||
}
|
||||
|
||||
protected void selectByLabel(By by, String label) {
|
||||
Select select = new Select(driver.findElement(by));
|
||||
select.selectByVisibleText(label);
|
||||
|
||||
}
|
||||
|
||||
protected void type(By by, String text) {
|
||||
driver.findElement(by).sendKeys(text);
|
||||
}
|
||||
|
||||
protected void typeTinyMCE(String text) {
|
||||
// <td> tinyMCE.activeEditor.setContent('The Primate College of America is a privately-funded college for the study of primates.')</td>
|
||||
|
||||
driver.switchTo().frame("literal_ifr");
|
||||
WebElement element = driver.findElement(By.cssSelector("body"));
|
||||
element.click();
|
||||
element.sendKeys(text);
|
||||
driver.switchTo().defaultContent();
|
||||
}
|
||||
|
||||
protected void verifyTextPresent(String text) {
|
||||
Assert.assertNotNull(driver.findElement(xpathForTextPresent(text)));
|
||||
}
|
||||
|
||||
protected boolean waitForElementPresent(By by) {
|
||||
return waitForElementPresent(by, 30);
|
||||
}
|
||||
|
||||
protected boolean waitForElementPresent(By by, int timeout) {
|
||||
WebDriverWait wait = new WebDriverWait(driver, timeout);
|
||||
return wait.until(ExpectedConditions.presenceOfElementLocated(by)) != null;
|
||||
}
|
||||
|
||||
protected boolean waitForTextPresent(String text) {
|
||||
return waitForTextPresent(text, 30);
|
||||
}
|
||||
|
||||
protected boolean waitForTextPresent(String text, int timeout) {
|
||||
WebDriverWait wait = new WebDriverWait(driver, timeout);
|
||||
return wait.until(ExpectedConditions.presenceOfElementLocated(xpathForTextPresent(text))) != null;
|
||||
}
|
||||
|
||||
protected By xpathForTextPresent(String text) {
|
||||
return By.xpath("//*[text()[contains(.,'" + text + "')]]");
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
driver = DriverFactory.getDriver();
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanup() {
|
||||
DriverFactory.close();
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,39 @@
|
|||
package org.vivoweb.vivo.selenium.tests;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.interactions.Actions;
|
||||
import org.openqa.selenium.support.ui.ExpectedConditions;
|
||||
import org.openqa.selenium.support.ui.WebDriverWait;
|
||||
import org.vivoweb.vivo.selenium.DriverFactory;
|
||||
import org.vivoweb.vivo.selenium.SeleniumUtils;
|
||||
|
||||
public class RebuildSearchIndex extends AbstractSeleniumTest {
|
||||
@Test
|
||||
public void rebuildSearchIndexTest() {
|
||||
deleteAllVisibleCookies();
|
||||
|
||||
open("/");
|
||||
assertTitle("VIVO"); // assertTitle,VIVO
|
||||
|
||||
logIn("testAdmin@cornell.edu", "Password");
|
||||
|
||||
clickAndWait(By.linkText("Site Admin")); // clickAndWait,link=Site Admin
|
||||
assertTitle("VIVO Site Administration"); // assertTitle,VIVO Site Administration
|
||||
|
||||
clickAndWait(By.linkText("Rebuild search index")); // clickAndWait,link=Rebuild search index
|
||||
assertTitle("Rebuild Search Index"); // assertTitle,Rebuild Search Index
|
||||
|
||||
clickAndWait(By.name("rebuild")); // clickAndWait,name=rebuild
|
||||
assertTitle("Rebuild Search Index"); // assertTitle, Rebuild Search Index
|
||||
|
||||
waitForTextPresent("Reset the search index and re-populate it."); // waitForTextPresent,Reset the search index and re-populate it.
|
||||
|
||||
logOut(); // clickAndWait,Log out
|
||||
}
|
||||
}
|
58
selenium/test-user-model.owl
Normal file
58
selenium/test-user-model.owl
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
|
||||
xmlns:owl="http://www.w3.org/2002/07/owl#"
|
||||
xmlns:vitro="http://vitro.mannlib.cornell.edu/ns/vitro/0.7#"
|
||||
xmlns:auth="http://vitro.mannlib.cornell.edu/ns/vitro/authorization#"
|
||||
xmlns="http://vitro.mannlib.cornell.edu/ns/vitro/default#"
|
||||
xml:base="http://vitro.mannlib.cornell.edu/ns/vitro/default">
|
||||
|
||||
<auth:UserAccount rdf:about="http://vivo.mydomain.edu/individual/TestAdmin">
|
||||
<auth:emailAddress rdf:datatype="http://www.w3.org/2001/XMLSchema#string">testAdmin@cornell.edu</auth:emailAddress>
|
||||
<auth:externalAuthId rdf:datatype="http://www.w3.org/2001/XMLSchema#string">testAdmin</auth:externalAuthId>
|
||||
<auth:firstName rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Test</auth:firstName>
|
||||
<auth:lastName rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Admin</auth:lastName>
|
||||
<auth:md5password rdf:datatype="http://www.w3.org/2001/XMLSchema#string">DC647EB65E6711E155375218212B3964</auth:md5password>
|
||||
<auth:status rdf:datatype="http://www.w3.org/2001/XMLSchema#string">ACTIVE</auth:status>
|
||||
<auth:loginCount rdf:datatype="http://www.w3.org/2001/XMLSchema#int">1</auth:loginCount>
|
||||
<auth:passwordLinkExpires rdf:datatype="http://www.w3.org/2001/XMLSchema#long">0</auth:passwordLinkExpires>
|
||||
<auth:hasPermissionSet rdf:resource="http://vitro.mannlib.cornell.edu/ns/vitro/authorization#ADMIN"/>
|
||||
</auth:UserAccount>
|
||||
|
||||
<auth:UserAccount rdf:about="http://vivo.mydomain.edu/individual/JohnCurator">
|
||||
<auth:emailAddress rdf:datatype="http://www.w3.org/2001/XMLSchema#string">johnCurator@cornell.edu</auth:emailAddress>
|
||||
<auth:externalAuthId rdf:datatype="http://www.w3.org/2001/XMLSchema#string">johnCurator</auth:externalAuthId>
|
||||
<auth:firstName rdf:datatype="http://www.w3.org/2001/XMLSchema#string">John</auth:firstName>
|
||||
<auth:lastName rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Curator</auth:lastName>
|
||||
<auth:md5password rdf:datatype="http://www.w3.org/2001/XMLSchema#string">DC647EB65E6711E155375218212B3964</auth:md5password>
|
||||
<auth:status rdf:datatype="http://www.w3.org/2001/XMLSchema#string">ACTIVE</auth:status>
|
||||
<auth:loginCount rdf:datatype="http://www.w3.org/2001/XMLSchema#int">1</auth:loginCount>
|
||||
<auth:passwordLinkExpires rdf:datatype="http://www.w3.org/2001/XMLSchema#long">0</auth:passwordLinkExpires>
|
||||
<auth:hasPermissionSet rdf:resource="http://vitro.mannlib.cornell.edu/ns/vitro/authorization#CURATOR"/>
|
||||
</auth:UserAccount>
|
||||
|
||||
<auth:UserAccount rdf:about="http://vivo.mydomain.edu/individual/SallyEditor">
|
||||
<auth:emailAddress rdf:datatype="http://www.w3.org/2001/XMLSchema#string">sallyEditor@cornell.edu</auth:emailAddress>
|
||||
<auth:externalAuthId rdf:datatype="http://www.w3.org/2001/XMLSchema#string">sallyEditor</auth:externalAuthId>
|
||||
<auth:firstName rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Sally</auth:firstName>
|
||||
<auth:lastName rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Editor</auth:lastName>
|
||||
<auth:md5password rdf:datatype="http://www.w3.org/2001/XMLSchema#string">DC647EB65E6711E155375218212B3964</auth:md5password>
|
||||
<auth:status rdf:datatype="http://www.w3.org/2001/XMLSchema#string">ACTIVE</auth:status>
|
||||
<auth:loginCount rdf:datatype="http://www.w3.org/2001/XMLSchema#int">1</auth:loginCount>
|
||||
<auth:passwordLinkExpires rdf:datatype="http://www.w3.org/2001/XMLSchema#long">0</auth:passwordLinkExpires>
|
||||
<auth:hasPermissionSet rdf:resource="http://vitro.mannlib.cornell.edu/ns/vitro/authorization#EDITOR"/>
|
||||
</auth:UserAccount>
|
||||
|
||||
<auth:UserAccount rdf:about="http://vivo.mydomain.edu/individual/JoeUser">
|
||||
<auth:emailAddress rdf:datatype="http://www.w3.org/2001/XMLSchema#string">joeUser@cornell.edu</auth:emailAddress>
|
||||
<auth:externalAuthId rdf:datatype="http://www.w3.org/2001/XMLSchema#string">joeUser</auth:externalAuthId>
|
||||
<auth:firstName rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Joe</auth:firstName>
|
||||
<auth:lastName rdf:datatype="http://www.w3.org/2001/XMLSchema#string">User</auth:lastName>
|
||||
<auth:md5password rdf:datatype="http://www.w3.org/2001/XMLSchema#string">DC647EB65E6711E155375218212B3964</auth:md5password>
|
||||
<auth:status rdf:datatype="http://www.w3.org/2001/XMLSchema#string">ACTIVE</auth:status>
|
||||
<auth:loginCount rdf:datatype="http://www.w3.org/2001/XMLSchema#int">1</auth:loginCount>
|
||||
<auth:passwordLinkExpires rdf:datatype="http://www.w3.org/2001/XMLSchema#long">0</auth:passwordLinkExpires>
|
||||
<auth:hasPermissionSet rdf:resource="http://vitro.mannlib.cornell.edu/ns/vitro/authorization#SELF_EDITOR"/>
|
||||
</auth:UserAccount>
|
||||
|
||||
</rdf:RDF>
|
Loading…
Add table
Reference in a new issue