Skip to content

Instantly share code, notes, and snippets.

View cheezy's full-sized avatar

Jeff Morgan cheezy

  • Tango
  • Toronto, ON Canada
  • X @chzy
View GitHub Profile
@cheezy
cheezy / gist:1262808
Created October 4, 2011 21:05
Example to demonstrate inability to attach to window after modal dialog
require 'rubygems'
require 'watir-webdriver'
require 'selenium-webdriver'
def wait_for_new_handle(original_handles, driver)
handles = nil
wait = Selenium::WebDriver::Wait.new(:timeout => 10)
wait.until do
handles = driver.wd.window_handles
handles.size == original_handles.size + 1
@cheezy
cheezy / gist:1265132
Created October 5, 2011 17:48
Modal dialog example that crashes ruby after close
require 'rubygems'
require 'watir-webdriver'
require 'selenium-webdriver'
def wait_for_new_handle(original_handles, driver)
handles = nil
wait = Selenium::WebDriver::Wait.new(:timeout => 10)
wait.until do
handles = driver.wd.window_handles
handles.size == original_handles.size + 1
@cheezy
cheezy / gist:1265379
Created October 5, 2011 19:18
Example of required field
Scenario: Last name is required
Given I am on the page to be tested
When I leave the last name blank
Then I should see an error message with "Last name is required"
@cheezy
cheezy / gist:1302205
Created October 20, 2011 20:12
top of stack
org.jruby.Ruby.getCacheMap()Lorg/jruby/runtime/CacheMap; (Java::JavaLang::NoSuchMethodError)
MixologyService.clearCache(MixologyService.java:116)
MixologyService.add_module(MixologyService.java:84)
@cheezy
cheezy / gist:1302241
Created October 20, 2011 20:21
Method from Mixology
protected static void clearCache(RubyModule klass, RubyModule module) {
List<String> methodNames = new ArrayList<String>(module.getMethods().keySet());
for (Iterator iter = methodNames.iterator(); iter.hasNext();) {
String methodName = (String) iter.next();
klass.getRuntime().getCacheMap().remove(klass.searchMethod(methodName));
}
}
After do |scenario|
if scenario.failed?
name = "error#{Time.now}.png"
@current_page.save_screenshot name
embed name, 'image/png'
end
# do your other stuff
end
RSpec::Matchers.define :have_element_named do |expected|
match do |page|
page.respond_to?("#{expected.to_s}_element") and page.send "#{expected.to_s}?"
end
failure_message_for_should do |page|
"Expected the page to have an element named '#{expected.to_s}'"
end
failure_message_for_should_not do |page|
@cheezy
cheezy / gist:2415279
Created April 18, 2012 17:30
Using PageObject with RSpec
# spec_helper.rb
require 'rspec'
require 'watir-webdriver'
require 'page-object'
require 'page-object/page_factory'
require 'require_all'
require_all 'lib/pages'
RSpec.configure do |config|
@cheezy
cheezy / gist:3849469
Created October 7, 2012 20:23
My ImageLoader class
package com.leandog.puppies.data;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import android.graphics.drawable.Drawable;
public class ImageLoader {
@cheezy
cheezy / gist:4990370
Created February 19, 2013 21:46
Verifying I am on a page using the title
class MyPage
include PageObject
expected_title('the title I need to look for')
def initialize_page
has_expected_title?
end
end