Skip to content

Instantly share code, notes, and snippets.

@avuori
avuori / SignupTest.java
Last active August 29, 2015 14:22
SignupTest
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.util.UUID;
public class SignupTest {
public static void main(String[] args) {
GLOBALS.token = document.querySelector("#email_content").textContent.match(/Token: \w+/)[0].split(" ")[1];
callback(true); // Signal that the Javascript step is done
document.querySelector("#token").value = GLOBALS.token;
callback(true); // Signal that the Javascript step is done
def set_range(el, val):
driver.execute_javascript("arguments[0].value = arguments[1];", el, val);
def set_range(el, val):
minval = float(el.get_attribute("min") or 0)
maxval = float(el.get_attribute("max") or 100)
v = max(0, min(1, (float(val) - minval) / (maxval - minval)))
width = el.size["width"]
target = float(width) * v
ac = ActionChains(driver)
ac.move_to_element_with_offset(el, target, 1)
ac.click()
ac.perform()
def set_range(el, val):
# The adjustment helper to drag the slider thumb
def adjust(deltax):
if deltax < 0:
deltax = int(math.floor(min(-1, deltax)))
else:
deltax = int(math.ceil(max(1, deltax)))
ac = ActionChains(driver)
ac.click_and_hold(None)
ac.move_by_offset(deltax, 0)
(function(jqueryUrl, callback) {
if (typeof jqueryUrl != 'string') {
jqueryUrl = 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js';
}
if (typeof jQuery == 'undefined') {
var script = document.createElement('script');
var head = document.getElementsByTagName('head')[0];
var done = false;
script.onload = script.onreadystatechange = (function() {
if (!done && (!this.readyState || this.readyState == 'loaded'
if (!GLOBALS.poll_time) {
var poll_timeout_seconds = 3;
} else {
var poll_timeout_seconds = GLOBALS.poll_time;
}
var element = "iframe.locator";
var element_text = "Text to check";
var poll_frequency_ms = 500;
// For checking that a URL contains something, create a javascript step and write the following:
// You control what to find from the URL by changing the value of the "find" variable.
var find = "foo";
if (window.location.href.indexOf(find) >= 0) {
return callback(true);
} else {
return callback("URL does not contain: " + find);
}