Skip to content

Instantly share code, notes, and snippets.

Freek Wielstra fwielstra

Block or report user

Report or block fwielstra

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View WebDriverSupplier.java
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
An example of a Selenium WebRunner test
View someIntegrationTest.java
@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
View WebDriverSupplier.java
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
A Selenium WebRunner test using multiple WebRunners
View SomeIntegrationTest.java
@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
Only add the Internet Explorer WebDriver instance when the running system is Windows.
View WebDriverSupplier.java
if (System.getProperty("os.name").startsWith("Windows"))
suppliers.add(INTERNET_EXPLORER_SUPPLIER)
}
@fwielstra
fwielstra / WebDriverUtils.java
Created May 16, 2011
Workaround for clicking elements from a WebDriver test in Internet Explorer
View WebDriverUtils.java
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 Jun 13, 2011
Sammy.js - Basic application
View app.js
(function($) {
var app = $.sammy('#main', function() {
this.get('#/', function(context) {
alert('index!');
});
});
$(function() {
app.run('#/');
});
@fwielstra
fwielstra / app.js
Created Jun 13, 2011
Sammy.js - Load data from an API
View app.js
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 Jun 13, 2011
A thread display template
View thread.html
<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 Jun 13, 2011
Sammy.js - Do a POST on the back-end
View app.js
this.post('#/thread', function(context) {
$.post('thread', this.params);
this.redirect('#/thread/' + this.params.title);
});
You can’t perform that action at this time.