Skip to content

Instantly share code, notes, and snippets.

View santiycr's full-sized avatar
💭
Always learning

Santiago Suarez Ordoñez santiycr

💭
Always learning
View GitHub Profile
@santiycr
santiycr / Tweet.java
Created March 11, 2011 23:15
Tweet about #SeleniumConf!
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.util.concurrent.TimeUnit;
public class Tweet {
public static void goTweet() throws Exception {
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.get("http://twitter.com");
@santiycr
santiycr / gist:1003731
Created June 2, 2011 01:12
Let Sauce know about your Selenium 1 python test results with 2 lines of code!
def tearDown(self):
passed = {'passed': self._exc_info() == (None, None, None)}
self.selenium.set_context("sauce: job-info=%s" % json.dumps(passed))
self.selenium.stop()
@santiycr
santiycr / implicit_wait_selenium.py
Created July 26, 2011 17:57
Implicit wait Selenium 1
import time, re
from selenium import selenium
class implicitWaitSelenium(selenium):
"""
Extending the regular selenium class to add implicit waits
"""
def __init__(self, *args):
self.implicit_wait = 30
@santiycr
santiycr / selenium_test_case.py
Created July 26, 2011 19:24
Ignoring open failures as letting call selenium commands right from self, reporting pass/fail status automatically
class SeleniumTestCase(TestCase):
# Let us just call self.click or self.type instead of self.selenium.type
def __getattr__(self, name):
if hasattr(self, 'selenium'):
return getattr(self.selenium, name)
raise AttributeError(name)
# Ignore open commands that fail (same needs to be don for wait_for_page_to_load)
def open(self, url, ignoreResponseCode=True):
@santiycr
santiycr / selenium2_test_case.py
Created July 26, 2011 19:32
Reporting pass/fail status automatically in Selenium 2 tests
class Selenium2TestCase(TestCase):
def report_pass_fail(self):
base64string = base64.encodestring('%s:%s' % (config['username'],
config['access-key']))[:-1]
result = json.dumps({'passed': self._exc_info() == (None, None, None)})
connection = httplib.HTTPConnection(self.config['host'])
connection.request('PUT', '/rest/v1/%s/jobs/%s' % (self.config['username'],
self.driver.session_id),
result,
@santiycr
santiycr / commit-msg
Created December 18, 2012 15:07
Git commit hook to automatically add your Selenium wiki name to every commit.
#!/bin/bash
# Automatically adds your Selenium wiki name in case it's missing
# Place in selenium/.git/hooks
# chmod +x selenium/.git/hooks/commit-msg
# Append 'export SELENIUM_WIKI_NAME="YourWikiName"' to your bashrc/zshrc
echo "Checking commit message..."
if [ -z "$(grep -e "^$SELENIUM_WIKI_NAME: " $1)" ]; then
echo "Missing Wiki name in commit message, appending"
@santiycr
santiycr / gist:4489869
Last active December 10, 2015 20:38
import time declarations, nono!
In [2]: class C(object):
...: def hi(self, k, d=dict()):
...: d[k] = 1
...: print d
...:
In [3]: c = C()
In [4]: c.hi(1)
{1: 1}
@santiycr
santiycr / sauce_connect_setup.sh
Last active December 14, 2015 19:49
A small bash script to download and start Sauce Connect as part of a Travis Build.
#!/bin/bash
# Setup and start Sauce Connect for your TravisCI build
# This script requires your .travis.yml to include the following two private env variables:
# SAUCE_USERNAME
# SAUCE_ACCESS_KEY
# Follow the steps at https://saucelabs.com/opensource/travis to set that up.
#
# Curl and run this script as part of your .travis.yml before_script section:
# before_script:
@santiycr
santiycr / sauce_browsers_coordination.py
Created August 6, 2010 17:36
Coordinate multiple browsers in Sauce OnDemand using threads
from threading import Thread
from selenium import selenium
import time
try:
import json
except ImportError:
import simplejson as json
USERNAME = "USERNAME"
ACCESS_KEY = "ACCESS-KEY"
#!/usr/bin/env python
import os
import time
import subprocess
import tempfile
import zipfile
import urllib
import logging