Created
July 12, 2011 12:06
-
-
Save freynaud/1077848 to your computer and use it in GitHub Desktop.
#2037
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.openqa.grid.e2e.selenium; | |
import java.net.URL; | |
import org.openqa.grid.common.GridRole; | |
import org.openqa.grid.e2e.utils.GridTestHelper; | |
import org.openqa.grid.e2e.utils.RegistryTestHelper; | |
import org.openqa.grid.internal.utils.GridHubConfiguration; | |
import org.openqa.grid.internal.utils.SelfRegisteringRemote; | |
import org.openqa.grid.web.Hub; | |
import org.openqa.selenium.Platform; | |
import org.openqa.selenium.net.PortProber; | |
import org.openqa.selenium.remote.DesiredCapabilities; | |
import org.testng.Assert; | |
import org.testng.annotations.AfterClass; | |
import org.testng.annotations.BeforeClass; | |
import org.testng.annotations.Test; | |
import com.thoughtworks.selenium.DefaultSelenium; | |
import com.thoughtworks.selenium.Selenium; | |
/** | |
* A hub controling 1 selenium1 remote can run IE, FF or safari tests. | |
*/ | |
public class SmokeTest { | |
private Hub hub; | |
private URL hubURL; | |
@BeforeClass(alwaysRun = false) | |
public void prepare() throws Exception { | |
GridHubConfiguration config = new GridHubConfiguration(); | |
config.setPort(PortProber.findFreePort()); | |
hub = new Hub(config); | |
hubURL = hub.getUrl(); | |
hub.start(); | |
for (int i=0;i<4;i++){ | |
SelfRegisteringRemote remote = GridTestHelper.getRemoteWithoutCapabilities(hubURL, GridRole.REMOTE_CONTROL); | |
remote.addBrowser(new DesiredCapabilities("*firefox", "3.6", Platform.getCurrent()), 5); | |
remote.setTimeout(120000, 2000); | |
remote.startRemoteServer(); | |
remote.sendRegistrationRequest(); | |
} | |
RegistryTestHelper.waitForNode(hub.getRegistry(), 4); | |
} | |
@Test(invocationCount=100,threadPoolSize=10) | |
public void sel1firefox() throws InterruptedException { | |
Selenium selenium = new DefaultSelenium(hub.getHost(), hub.getPort(), "*firefox", hubURL + ""); | |
//Assert.assertEquals(hub.getRegistry().getActiveSessions().size(), 0); | |
selenium.start(); | |
selenium.setTimeout("30000"); | |
//Assert.assertEquals(hub.getRegistry().getActiveSessions().size(), 1); | |
selenium.open(hubURL + "/grid/console"); | |
Assert.assertTrue(selenium.getTitle().contains("Grid overview")); | |
selenium.stop(); | |
// cannot assume it will be 0 active session right away. selenium.stop() | |
// will trigger a session.terminate() on the grid, that runs in a | |
// different thread | |
// not to block the test. | |
/*while (hub.getRegistry().getActiveSessions().size() != 0) { | |
Thread.sleep(250); | |
}*/ | |
} | |
@AfterClass(alwaysRun = true) | |
public void stop() throws Exception { | |
hub.stop(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment