Skip to content
Snippets Groups Projects
Commit 6cb64416 authored by anttil's avatar anttil
Browse files

SWE-2 / SP-314 : Broke tests to multiple suites

SVN: 26946
parent b206e8bb
No related branches found
No related tags found
No related merge requests found
Showing
with 86 additions and 134 deletions
......@@ -21,6 +21,7 @@ import java.util.concurrent.TimeUnit;
import org.openqa.selenium.NoSuchElementException;
import ch.systemsx.cisd.openbis.uitest.infra.dsl.SeleniumTest;
import ch.systemsx.cisd.openbis.uitest.infra.uid.UidGenerator;
import ch.systemsx.cisd.openbis.uitest.infra.webdriver.PageProxy;
import ch.systemsx.cisd.openbis.uitest.page.dialog.AddExperimentTypeDialog;
......@@ -54,7 +55,6 @@ import ch.systemsx.cisd.openbis.uitest.page.tab.SampleTypeBrowser;
import ch.systemsx.cisd.openbis.uitest.page.tab.SpaceBrowser;
import ch.systemsx.cisd.openbis.uitest.page.tab.Trash;
import ch.systemsx.cisd.openbis.uitest.page.tab.VocabularyBrowser;
import ch.systemsx.cisd.openbis.uitest.suite.SeleniumTest;
import ch.systemsx.cisd.openbis.uitest.type.Browsable;
import ch.systemsx.cisd.openbis.uitest.type.DataSet;
import ch.systemsx.cisd.openbis.uitest.type.DataSetType;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package ch.systemsx.cisd.openbis.uitest.suite;
package ch.systemsx.cisd.openbis.uitest.infra.dsl;
import static org.hamcrest.CoreMatchers.not;
......@@ -30,17 +30,16 @@ import org.openqa.selenium.Dimension;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
import ch.systemsx.cisd.openbis.uitest.infra.application.ApplicationRunner;
import ch.systemsx.cisd.openbis.uitest.infra.application.GuiApplicationRunner;
import ch.systemsx.cisd.openbis.uitest.infra.application.PublicApiApplicationRunner;
import ch.systemsx.cisd.openbis.uitest.infra.dsl.DslSampleBrowser;
import ch.systemsx.cisd.openbis.uitest.infra.matcher.CellContentMatcher;
import ch.systemsx.cisd.openbis.uitest.infra.matcher.CollectionContainsMatcher;
import ch.systemsx.cisd.openbis.uitest.infra.matcher.CurrentPageMatcher;
......@@ -166,9 +165,11 @@ public abstract class SeleniumTest
driver.quit();
}
@BeforeGroups(groups = "login-admin")
@BeforeTest(groups =
{ "login-admin", "sprint-test" })
public void loginAsAdmin()
{
System.out.println("LOGIN");
this.openbis = new GuiApplicationRunner(new PageProxy(new ScreenShotter()
{
@Override
......@@ -183,9 +184,11 @@ public abstract class SeleniumTest
openbisApi.login(ADMIN_USER, ADMIN_PASSWORD);
}
@AfterGroups(groups = "login-admin")
@AfterTest(groups =
{ "login-admin", "sprint-test" })
public void logout()
{
System.out.println("LOGOUT!");
this.openbis = new GuiApplicationRunner(new PageProxy(new ScreenShotter()
{
@Override
......
......@@ -23,25 +23,27 @@ import java.lang.reflect.Method;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import ch.systemsx.cisd.openbis.uitest.suite.SeleniumTest;
import ch.systemsx.cisd.openbis.uitest.infra.dsl.SeleniumTest;
public class WebElementProxy implements InvocationHandler
public class LazyLoader implements InvocationHandler
{
private String id;
private String tag;
private WebElement element;
public static Object newInstance(String id, String tag)
{
return java.lang.reflect.Proxy.newProxyInstance(
WebElement.class.getClassLoader(),
new Class<?>[]
{ WebElement.class },
new WebElementProxy(id, tag));
new LazyLoader(id, tag));
}
private WebElementProxy(String id, String tag)
private LazyLoader(String id, String tag)
{
this.id = id;
this.tag = tag;
......@@ -52,12 +54,17 @@ public class WebElementProxy implements InvocationHandler
{
try
{
WebElement e = SeleniumTest.driver.findElement(By.id(id));
if (tag != null && !tag.equals(e.getTagName()))
if (element == null)
{
e = e.findElement(By.xpath(".//" + tag));
WebElement e = SeleniumTest.driver.findElement(By.id(id));
if (tag != null && !tag.equals(e.getTagName()))
{
e = e.findElement(By.xpath(".//" + tag));
}
element = e;
}
return m.invoke(e, args);
return m.invoke(element, args);
} catch (InvocationTargetException e)
{
throw e.getTargetException();
......
......@@ -17,18 +17,12 @@
package ch.systemsx.cisd.openbis.uitest.infra.webdriver;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import javassist.util.proxy.MethodHandler;
import javassist.util.proxy.ProxyFactory;
import org.openqa.selenium.By;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.WebElement;
import ch.systemsx.cisd.openbis.uitest.infra.dsl.SeleniumTest;
import ch.systemsx.cisd.openbis.uitest.infra.screenshot.ScreenShotter;
import ch.systemsx.cisd.openbis.uitest.suite.SeleniumTest;
import ch.systemsx.cisd.openbis.uitest.widget.AtomicWidget;
import ch.systemsx.cisd.openbis.uitest.widget.Widget;
......@@ -47,71 +41,17 @@ public class PageProxy
@SuppressWarnings("unchecked")
public <T> T get(final Class<T> clazz)
{
ProxyFactory factory = new ProxyFactory();
factory.setSuperclass(clazz);
MethodHandler handler = new MethodHandler()
{
@Override
public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args)
throws Throwable
{
try
{
return proceed.invoke(self, args);
} catch (InvocationTargetException e)
{
if (e.getTargetException() instanceof StaleElementReferenceException)
{
initLocateFields(clazz, (T) self);
return proceed.invoke(self, args);
} else
{
throw e.getTargetException();
}
}
}
};
T t;
try
{
t = (T) factory.create(new Class<?>[0], new Object[0], handler);
} catch (IllegalArgumentException ex1)
{
throw new RuntimeException(ex1);
} catch (NoSuchMethodException ex1)
{
throw new RuntimeException(ex1);
} catch (InstantiationException ex1)
{
throw new RuntimeException(ex1);
} catch (IllegalAccessException ex1)
{
throw new RuntimeException(ex1);
} catch (InvocationTargetException ex1)
{
throw new RuntimeException(ex1);
}
initLocateFields(clazz, t);
T t = clazz.newInstance();
return t;
}
@SuppressWarnings("unchecked")
private <T> void initLocateFields(Class<T> clazz, T t)
{
Class<T> pageClass = clazz;
while (pageClass != null)
{
for (Field field : pageClass.getDeclaredFields())
Class<T> pageClass = clazz;
while (pageClass != null)
{
Locate locate = field.getAnnotation(Locate.class);
if (locate != null)
for (Field field : pageClass.getDeclaredFields())
{
try
Locate locate = field.getAnnotation(Locate.class);
if (locate != null)
{
field.setAccessible(true);
Widget widget = (Widget) field.getType().newInstance();
......@@ -126,7 +66,7 @@ public class PageProxy
if (field.getAnnotation(Lazy.class) != null)
{
element =
(WebElement) WebElementProxy.newInstance(locate.value(),
(WebElement) LazyLoader.newInstance(locate.value(),
tagName);
} else
{
......@@ -139,46 +79,36 @@ public class PageProxy
widget.setContext(new WidgetContext(element, shotter));
field.set(t, widget);
} catch (IllegalArgumentException ex)
{
// TODO Auto-generated catch block
ex.printStackTrace();
throw ex;
} catch (IllegalAccessException ex)
{
ex.printStackTrace();
throw new RuntimeException(ex);
} catch (InstantiationException ex)
{
// TODO Auto-generated catch block
ex.printStackTrace();
throw new RuntimeException(ex);
}
}
Context context = field.getAnnotation(Context.class);
if (context != null)
{
field.setAccessible(true);
try
{
field.set(t, new WidgetContext(SeleniumTest.driver.findElement(By
.xpath("/html")),
shotter));
} catch (IllegalArgumentException ex)
{
ex.printStackTrace();
throw new RuntimeException(ex);
} catch (IllegalAccessException ex)
Context context = field.getAnnotation(Context.class);
if (context != null)
{
ex.printStackTrace();
throw new RuntimeException(ex);
field.setAccessible(true);
try
{
field.set(t, new WidgetContext(SeleniumTest.driver.findElement(By
.xpath("/html")),
shotter));
} catch (IllegalArgumentException ex)
{
ex.printStackTrace();
throw new RuntimeException(ex);
} catch (IllegalAccessException ex)
{
ex.printStackTrace();
throw new RuntimeException(ex);
}
}
}
pageClass = (Class<T>) pageClass.getSuperclass();
}
pageClass = (Class<T>) pageClass.getSuperclass();
return t;
} catch (Exception e)
{
throw new RuntimeException(e);
}
}
}
......@@ -25,8 +25,8 @@ import org.openqa.selenium.Point;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import ch.systemsx.cisd.openbis.uitest.infra.dsl.SeleniumTest;
import ch.systemsx.cisd.openbis.uitest.infra.screenshot.ScreenShotter;
import ch.systemsx.cisd.openbis.uitest.suite.SeleniumTest;
import ch.systemsx.cisd.openbis.uitest.widget.AtomicWidget;
/**
......
......@@ -18,9 +18,9 @@ package ch.systemsx.cisd.openbis.uitest.page.tab;
import java.util.concurrent.TimeUnit;
import ch.systemsx.cisd.openbis.uitest.infra.dsl.SeleniumTest;
import ch.systemsx.cisd.openbis.uitest.infra.webdriver.Lazy;
import ch.systemsx.cisd.openbis.uitest.infra.webdriver.Locate;
import ch.systemsx.cisd.openbis.uitest.suite.SeleniumTest;
import ch.systemsx.cisd.openbis.uitest.type.Experiment;
import ch.systemsx.cisd.openbis.uitest.type.ExperimentType;
import ch.systemsx.cisd.openbis.uitest.type.Sample;
......
package ch.systemsx.cisd.openbis.uitest.suite;
package ch.systemsx.cisd.openbis.uitest.suite.authentication;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import org.testng.annotations.Test;
import ch.systemsx.cisd.openbis.uitest.infra.dsl.SeleniumTest;
import ch.systemsx.cisd.openbis.uitest.page.dialog.InvalidPasswordDialog;
import ch.systemsx.cisd.openbis.uitest.page.menu.AdminMenu;
import ch.systemsx.cisd.openbis.uitest.page.menu.TopBar;
......@@ -12,7 +13,7 @@ import ch.systemsx.cisd.openbis.uitest.page.tab.RoleAssignmentBrowser;
@Test(groups =
{ "no-login" })
public class AuthorizationTest extends SeleniumTest
public class AuthenticationTest extends SeleniumTest
{
@Test
......
......@@ -14,10 +14,11 @@
* limitations under the License.
*/
package ch.systemsx.cisd.openbis.uitest.suite;
package ch.systemsx.cisd.openbis.uitest.suite.main;
import org.testng.annotations.Test;
import ch.systemsx.cisd.openbis.uitest.infra.dsl.SeleniumTest;
import ch.systemsx.cisd.openbis.uitest.type.DataSet;
import ch.systemsx.cisd.openbis.uitest.type.Experiment;
import ch.systemsx.cisd.openbis.uitest.type.Sample;
......
......@@ -14,12 +14,13 @@
* limitations under the License.
*/
package ch.systemsx.cisd.openbis.uitest.suite;
package ch.systemsx.cisd.openbis.uitest.suite.main;
import static org.hamcrest.MatcherAssert.assertThat;
import org.testng.annotations.Test;
import ch.systemsx.cisd.openbis.uitest.infra.dsl.SeleniumTest;
import ch.systemsx.cisd.openbis.uitest.type.Experiment;
import ch.systemsx.cisd.openbis.uitest.type.Project;
import ch.systemsx.cisd.openbis.uitest.type.Sample;
......
package ch.systemsx.cisd.openbis.uitest.suite;
package ch.systemsx.cisd.openbis.uitest.suite.main;
import static org.hamcrest.MatcherAssert.assertThat;
import org.testng.annotations.Test;
import ch.systemsx.cisd.openbis.uitest.infra.dsl.SeleniumTest;
import ch.systemsx.cisd.openbis.uitest.type.ExperimentType;
@Test(groups =
......
package ch.systemsx.cisd.openbis.uitest.suite;
package ch.systemsx.cisd.openbis.uitest.suite.main;
import static org.hamcrest.MatcherAssert.assertThat;
import org.testng.annotations.Test;
import ch.systemsx.cisd.openbis.uitest.infra.dsl.SeleniumTest;
import ch.systemsx.cisd.openbis.uitest.type.Project;
@Test(groups =
......
......@@ -14,12 +14,13 @@
* limitations under the License.
*/
package ch.systemsx.cisd.openbis.uitest.suite;
package ch.systemsx.cisd.openbis.uitest.suite.main;
import static org.hamcrest.MatcherAssert.assertThat;
import org.testng.annotations.Test;
import ch.systemsx.cisd.openbis.uitest.infra.dsl.SeleniumTest;
import ch.systemsx.cisd.openbis.uitest.type.PropertyType;
import ch.systemsx.cisd.openbis.uitest.type.PropertyTypeAssignment;
import ch.systemsx.cisd.openbis.uitest.type.Sample;
......
......@@ -14,12 +14,13 @@
* limitations under the License.
*/
package ch.systemsx.cisd.openbis.uitest.suite;
package ch.systemsx.cisd.openbis.uitest.suite.main;
import static org.hamcrest.MatcherAssert.assertThat;
import org.testng.annotations.Test;
import ch.systemsx.cisd.openbis.uitest.infra.dsl.SeleniumTest;
import ch.systemsx.cisd.openbis.uitest.type.PropertyType;
/**
......
......@@ -14,12 +14,13 @@
* limitations under the License.
*/
package ch.systemsx.cisd.openbis.uitest.suite;
package ch.systemsx.cisd.openbis.uitest.suite.main;
import static org.hamcrest.MatcherAssert.assertThat;
import org.testng.annotations.Test;
import ch.systemsx.cisd.openbis.uitest.infra.dsl.SeleniumTest;
import ch.systemsx.cisd.openbis.uitest.type.PropertyType;
import ch.systemsx.cisd.openbis.uitest.type.Sample;
import ch.systemsx.cisd.openbis.uitest.type.SampleType;
......
......@@ -14,12 +14,13 @@
* limitations under the License.
*/
package ch.systemsx.cisd.openbis.uitest.suite;
package ch.systemsx.cisd.openbis.uitest.suite.main;
import static org.hamcrest.MatcherAssert.assertThat;
import org.testng.annotations.Test;
import ch.systemsx.cisd.openbis.uitest.infra.dsl.SeleniumTest;
import ch.systemsx.cisd.openbis.uitest.page.dialog.AddSampleTypeDialog;
import ch.systemsx.cisd.openbis.uitest.type.SampleType;
......
package ch.systemsx.cisd.openbis.uitest.suite;
package ch.systemsx.cisd.openbis.uitest.suite.main;
import static org.hamcrest.MatcherAssert.assertThat;
import org.testng.annotations.Test;
import ch.systemsx.cisd.openbis.uitest.infra.dsl.SeleniumTest;
import ch.systemsx.cisd.openbis.uitest.type.Space;
@Test(groups =
......
package ch.systemsx.cisd.openbis.uitest.suite;
package ch.systemsx.cisd.openbis.uitest.suite.main;
import static org.hamcrest.MatcherAssert.assertThat;
import org.testng.annotations.Test;
import ch.systemsx.cisd.openbis.uitest.infra.dsl.SeleniumTest;
import ch.systemsx.cisd.openbis.uitest.type.Vocabulary;
@Test(groups =
......
......@@ -14,12 +14,13 @@
* limitations under the License.
*/
package ch.systemsx.cisd.openbis.uitest.suite;
package ch.systemsx.cisd.openbis.uitest.suite.sprint;
import static org.hamcrest.MatcherAssert.assertThat;
import org.testng.annotations.Test;
import ch.systemsx.cisd.openbis.uitest.infra.dsl.SeleniumTest;
import ch.systemsx.cisd.openbis.uitest.page.dialog.AddSampleTypeDialog;
import ch.systemsx.cisd.openbis.uitest.page.menu.AdminMenu;
import ch.systemsx.cisd.openbis.uitest.page.menu.TopBar;
......@@ -37,7 +38,7 @@ import ch.systemsx.cisd.openbis.uitest.type.Vocabulary;
* @author anttil
*/
@Test(groups =
{ "login-admin" })
{ "sprint-test" })
public class SprintTest extends SeleniumTest
{
......
......@@ -25,8 +25,8 @@ import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import ch.systemsx.cisd.openbis.uitest.infra.dsl.SeleniumTest;
import ch.systemsx.cisd.openbis.uitest.infra.webdriver.WidgetContext;
import ch.systemsx.cisd.openbis.uitest.suite.SeleniumTest;
/**
* @author anttil
......
......@@ -25,10 +25,10 @@ import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import ch.systemsx.cisd.openbis.uitest.infra.dsl.SeleniumTest;
import ch.systemsx.cisd.openbis.uitest.infra.webdriver.WidgetContext;
import ch.systemsx.cisd.openbis.uitest.page.tab.BrowserCell;
import ch.systemsx.cisd.openbis.uitest.page.tab.BrowserRow;
import ch.systemsx.cisd.openbis.uitest.suite.SeleniumTest;
/**
* @author anttil
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment