Skip to content

Commit

Permalink
ftest for numberguess in cluster environment
Browse files Browse the repository at this point in the history
  • Loading branch information
plenyi authored and pmuir committed Sep 23, 2010
1 parent fcd166e commit 6113c0a
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 33 deletions.
102 changes: 71 additions & 31 deletions ...a/org/jboss/weld/examples/numberguess/clustertest/selenium/NumberGuessClusteringTest.java 100755 → 100644
Expand Up @@ -33,13 +33,15 @@
import org.testng.annotations.Test;

import static org.jboss.test.selenium.locator.LocatorFactory.*;
import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.*;
import org.jboss.test.selenium.locator.Attribute;
import org.jboss.test.selenium.locator.AttributeLocator;
import org.jboss.test.selenium.locator.XpathLocator;
import org.jboss.test.selenium.encapsulated.JavaScript;
import org.jboss.test.selenium.locator.IdLocator;
import org.jboss.test.selenium.framework.AjaxSelenium;
import org.jboss.test.selenium.framework.AjaxSeleniumImpl;
import org.jboss.test.selenium.framework.AjaxSeleniumProxy;
import org.jboss.test.selenium.guard.request.RequestTypeGuardFactory;
import org.jboss.test.selenium.locator.ElementLocationStrategy;
import static org.jboss.test.selenium.encapsulated.JavaScript.fromResource;
import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
import static org.jboss.test.selenium.SystemProperties.*;

/**
* This class tests Weld numberguess example in a cluster. Two instances of JBoss AS are
Expand Down Expand Up @@ -67,7 +69,7 @@
*/
public class NumberGuessClusteringTest extends AbstractTestCase
{
protected String MAIN_PAGE = "/home.jsf";
protected String MAIN_PAGE = "home.jsf";

protected IdLocator GUESS_MESSAGES = id("numberGuess:messages");
protected XpathLocator GUESS_STATUS = xp("//div[contains(text(),'I'm thinking of ')]");
Expand All @@ -86,10 +88,8 @@ public class NumberGuessClusteringTest extends AbstractTestCase

private final String SECOND_INSTANCE_BROWSER_URL = "http://localhost:8180";
private final long JBOSS_SHUTDOWN_TIMEOUT = 20000;

String jboss = System.getProperty("JBOSS_HOME");

//private AjaxSelenium browser2;
String jbossConfig = System.getProperty("jboss.config");
private String localContextPath = "";

@BeforeMethod
public void openStartURL() throws MalformedURLException
Expand All @@ -103,13 +103,22 @@ public void guessingWithFailoverTest() throws MalformedURLException
preFailurePart();

String newAddress = getAddressForSecondInstance();

shutdownMasterJBossInstance();

/* stop and start browser -> simulate different web browser with different session */
super.finalizeBrowser();
super.initializeBrowser();
selenium.open(new URL(newAddress));
shutdownMasterJBossInstance();
initializeSecondBrowser();
super.initializeWaitTimeouts();
try
{
super.initializeExtensions();
}
catch (IOException e)
{
new RuntimeException(e.getCause());
}

selenium.open(new URL(SECOND_INSTANCE_BROWSER_URL + newAddress));

assertTrue(selenium.isTextPresent(HIGHER_MSG), "Page should contain message Higher!");
assertEquals(Integer.parseInt(selenium.getText(GUESS_SMALLEST)),4, "Page should contain smallest number equal to 4");
Expand Down Expand Up @@ -154,11 +163,15 @@ protected void postFailurePart()
selenium.deleteAllVisibleCookies();

while (isOnGuessPage())
{
/*3+8 = 11 -> even though we have 10 attempts, it is possible to enter value 11 times, but
the 11th time it is actually not guessing but only validating that 10 times has gone and the game
is finished (no 11th guessing)*/
if (i >= 8)
{
selenium.deleteAllVisibleCookies();
/*
* 3+8 = 11 -> even though we have 10 attempts, it is possible to enter
* value 11 times, but the 11th time it is actually not guessing but
* only validating that 10 times has gone and the game is finished (no
* 11th guessing)
*/
if (i >= 8)
{
fail("Game should not be longer than 7 guesses in the second selenium after failover");
}
Expand Down Expand Up @@ -206,27 +219,28 @@ public String getAddressForSecondInstance()
{
String loc = selenium.getLocation().toString();
String[] parsedStrings = loc.split("/");
localContextPath = "/" + parsedStrings[3] + "/";
StringBuilder sb = new StringBuilder();
for (int i = 3; i != parsedStrings.length; i++){
for (int i = 3; i < parsedStrings.length; i++)
{
sb.append("/").append(parsedStrings[i]);
}

String newAddress = sb.toString();
String firstPart = "";
String sid = "";

/* ---------- uncomment this when richfaces-selenium updates propagate to no-SNAPSHOT version ------
if (selenium.isCookiePresent("JSESSIONID"))
{
sid = selenium.getCookieByName("JSESSIONID").getValue();
firstPart = newAddress;
}
else
{
//get sessionid directly from browser URL if JSESSIONID cookie is not present
sid = loc.substring(loc.indexOf("jsessionid=") + "jsessionid=".length(), loc.length());
}*/

String newAddress = sb.toString();
String firstPart = newAddress.substring(0, newAddress.indexOf(";"));

{
//get sessionid directly from browser URL if JSESSIONID cookie is not present
firstPart = newAddress.substring(0, newAddress.indexOf(";"));
sid = loc.substring(loc.indexOf("jsessionid=") + "jsessionid=".length(), loc.length());
}

newAddress = firstPart + ";jsessionid=" + sid;

Expand All @@ -235,7 +249,7 @@ public String getAddressForSecondInstance()

public void shutdownMasterJBossInstance()
{
String command = jboss + "/bin/shutdown.sh -s localhost:1099 -S";
String command = jbossConfig + "/../../bin/shutdown.sh -s service:jmx:rmi:///jndi/rmi://localhost:1090/jmxrmi -S";
try
{
Process process = Runtime.getRuntime().exec(command);
Expand All @@ -250,4 +264,30 @@ public void shutdownMasterJBossInstance()
{
}
}
}

public void initializeSecondBrowser()
{
selenium = new AjaxSeleniumImpl(getSeleniumHost(), getSeleniumPort(), browser, buildUrl(SECOND_INSTANCE_BROWSER_URL, localContextPath));
AjaxSeleniumProxy.setCurrentContext(selenium);

selenium.start();

selenium.deleteAllVisibleCookies();
loadCustomLocationStrategies();

selenium.setSpeed(getSeleniumSpeed());

if (isSeleniumMaximize())
{
// focus and maximaze tested window
selenium.windowFocus();
selenium.windowMaximize();
}
}

private void loadCustomLocationStrategies()
{
JavaScript strategySource = fromResource("javascript/selenium-location-strategies/jquery-location-strategy.js");
selenium.addLocationStrategy(ElementLocationStrategy.JQUERY, strategySource);
}
}
3 changes: 1 addition & 2 deletions examples/pom.xml
Expand Up @@ -511,7 +511,6 @@
<groupId>org.codehaus.mojo</groupId>
<artifactId>failsafe-maven-plugin</artifactId>
<configuration>
<testClassesDirectory>${ftest.classes.directory}</testClassesDirectory>
<suiteXmlFiles>
<suiteXmlFile>${ftest.resources.directory}/${ftest.suite.xml}</suiteXmlFile>
</suiteXmlFiles>
Expand Down Expand Up @@ -647,7 +646,7 @@
<tasks>
<echo message="Undeploying application." />
<delete file="${jboss.master.configuration}/farm/${project.build.finalName}.${project.packaging}" />
<get taskname="selenium-shutdown" src="http://${selenium.host}:${selenium.port}/selenium-server/driver/?cmd=shutDownSeleniumServer" ignoreerrors="true" dest="${selenium.log.dir}/selenium.stop.msg" />
<get taskname="selenium-shutdown" src="http://${selenium.server.host}:${selenium.server.port}/selenium-server/driver/?cmd=shutDownSeleniumServer" ignoreerrors="true" dest="${selenium.log.dir}/selenium.stop.msg" />
<echo taskname="selenium-shutdown" message="DGF Errors during shutdown are expected." />
</tasks>
</configuration>
Expand Down

0 comments on commit 6113c0a

Please sign in to comment.