Skip to content

Instantly share code, notes, and snippets.

View fwielstra's full-sized avatar

Freek Wielstra fwielstra

View GitHub Profile
public class WebDriverSupplier {
private static final Supplier<WebDriver> FIREFOX_SUPPLIER = new Supplier<WebDriver>() {
private WebDriver firefoxDriver;
@Override
public WebDriver get() {
if (firefoxDriver == null) {
firefoxDriver = new FirefoxDriver();
}
@fwielstra
fwielstra / someIntegrationTest.java
Created May 16, 2011 09:14
An example of a Selenium WebRunner test
@Test
public void runSomeIntegrationTest() {
WebDriver driver = new FirefoxDriver()
Selenium selenium = new WebDriverBackedSelenium(driver, SharedConfiguration.BASE_URL);
selenium.open("page.html");
// wait until the table row has been loaded
SeleniumUtils.waitForElementPresent(selenium, "xpath=//tr[@id='task-TASK_001']");
// navigate to the associated details page
SeleniumUtils.clickElement(driver, By.linkText("1001"));
// the browser now opens the details.html page
@fwielstra
fwielstra / WebDriverSupplier.java
Created May 16, 2011 09:15
A WebDriverSupplier
public class WebDriverSupplier {
private static final Supplier<WebDriver> FIREFOX_SUPPLIER = new Supplier<WebDriver>() {
@Override
public WebDriver get() {
return new FirefoxDriver();
}
};
private static final Supplier<WebDriver> INTERNET_EXPLORER_SUPPLIER = new Supplier<WebDriver>() {
@fwielstra
fwielstra / SomeIntegrationTest.java
Created May 16, 2011 09:16
A Selenium WebRunner test using multiple WebRunners
@Test
public void runSomeIntegrationTest() {
for (Supplier<WebDriver> supplier : WebDriverSupplier.getWebDrivers()) {
WebDriver driver = supplier.get();
Selenium selenium = new WebDriverBackedSelenium(driver, SharedConfiguration.BASE_URL);
selenium.open("page.html");
SeleniumUtils.waitForElementPresent(selenium, "xpath=//tr[@id='task-TASK_001']");
SeleniumUtils.clickElement(driver, By.linkText("1001"));
SeleniumUtils.waitForElementPresent(selenium, "xpath=//tr[@id='wo-1001']");
assertEquals("CANCELLED", selenium.getText("xpath=//tr[@id='wo-1001']/td[3]"));
@fwielstra
fwielstra / WebDriverSupplier.java
Created May 16, 2011 09:26
Only add the Internet Explorer WebDriver instance when the running system is Windows.
if (System.getProperty("os.name").startsWith("Windows"))
suppliers.add(INTERNET_EXPLORER_SUPPLIER)
}
@fwielstra
fwielstra / WebDriverUtils.java
Created May 16, 2011 09:48
Workaround for clicking elements from a WebDriver test in Internet Explorer
public static void clickElement(WebDriver driver, By condition) {
WebElement sbutton = driver.findElement(condition);
sbutton.sendKeys("\n");
try {
sbutton = driver.findElement(condition);
sbutton.click();
} catch (NoSuchElementException e) {}
}
@fwielstra
fwielstra / app.js
Created June 13, 2011 10:21
Sammy.js - Basic application
(function($) {
var app = $.sammy('#main', function() {
this.get('#/', function(context) {
alert('index!');
});
});
$(function() {
app.run('#/');
});
@fwielstra
fwielstra / app.js
Created June 13, 2011 10:22
Sammy.js - Load data from an API
this.get('#/', function(context) {
this.load('thread')
.then( function(threads) {
$.each(threads, function(i, thread) {
context.render('templates/thread.template', {thread : thread}).appendTo(context.$element());
});
});
});
@fwielstra
fwielstra / thread.html
Created June 13, 2011 10:24
A thread display template
<pre>
<div class="thread">
<div class="thread-title">
<a href="#/thread/<%= thread.title %>"><%= thread.title %></a>
</div>
<time><%= thread.postdate %></time>
<div class="thread-author"><%= thread.author %></div>
</div>
</pre>
@fwielstra
fwielstra / app.js
Created June 13, 2011 10:24
Sammy.js - Do a POST on the back-end
this.post('#/thread', function(context) {
$.post('thread', this.params);
this.redirect('#/thread/' + this.params.title);
});