Last active
November 4, 2021 10:20
-
-
Save dgageot/4718233 to your computer and use it in GitHub Desktop.
FluentLenium, PhantomJs, GhostDriver
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 net.gageot; | |
import org.junit.Test; | |
import static org.fest.assertions.Assertions.assertThat; | |
public class CodeStoryStatusTest extends PhantomJsTest { | |
@Override | |
public String defaultUrl() { | |
return "http://status.code-story.net"; | |
} | |
@Test | |
public void should_list_participants() { | |
goTo("/"); | |
click(findFirst("th")); | |
assertThat(text("h3")).contains("Liste des 135 participants"); | |
assertThat(find("table tr", 1).getText()).contains("a14n 35 / 35 10000 / 10000 il y a 9 jours"); | |
assertThat(find("table tr", 135).getText()).contains("ypetit 33 / 35 1000 / 10000 il y a 9 jours"); | |
} | |
} |
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 net.gageot; | |
import org.fluentlenium.core.FluentAdapter; | |
import org.junit.Rule; | |
import org.junit.rules.TestWatcher; | |
import org.junit.runner.Description; | |
import org.openqa.selenium.Capabilities; | |
import org.openqa.selenium.Dimension; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.phantomjs.PhantomJSDriver; | |
import org.openqa.selenium.phantomjs.PhantomJSDriverService; | |
import org.openqa.selenium.remote.DesiredCapabilities; | |
import org.openqa.selenium.remote.service.DriverService; | |
import java.io.File; | |
public abstract class PhantomJsTest extends FluentAdapter { | |
private static final Dimension DEFAULT_WINDOW_SIZE = new Dimension(1024, 768); | |
private static WebDriver driver; | |
@Rule | |
public TestWatcher lifecycle = new TestWatcher() { | |
@Override | |
protected void starting(Description description) { | |
if (null == driver) { | |
Runtime.getRuntime().addShutdownHook(new Thread() { | |
@Override | |
public void run() { | |
if (driver != null) { | |
driver.quit(); | |
} | |
} | |
}); | |
Capabilities capabilities = new DesiredCapabilities(); | |
DriverService service = PhantomJSDriverService.createDefaultService(capabilities); | |
driver = new PhantomJSDriver(service, capabilities); | |
} | |
driver.manage().deleteAllCookies(); | |
driver.manage().window().setSize(DEFAULT_WINDOW_SIZE); | |
initFluent(driver).withDefaultUrl(defaultUrl()); | |
} | |
@Override | |
protected void succeeded(Description description) { | |
snapshotFile(description).delete(); | |
} | |
@Override | |
protected void failed(Throwable e, Description description) { | |
takeScreenShot(snapshotFile(description).getAbsolutePath()); | |
} | |
private File snapshotFile(Description description) { | |
return new File("snapshots", description.getMethodName() + ".png"); | |
} | |
}; | |
public String defaultUrl() { | |
return ""; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment