Test.java
Tag Archive for test
Automated UI test with Selenium-RC, WWW::Selenium and Test::More
use WWW::Selenium;
use Test::More tests => 2; #update to reflect the number of tests to be run
my $sel = WWW::Selenium->new( host => "localhost",
port => 4444,
browser => "*iexplore", # *iehta has more cross-domain privileges than *iexplore
browser_url => "http://mysite.com",
);
$sel->start();
$sel->open("http://mysite.com/testpopup.html");
diag("Check whether the popup is hidden.");
my $canSeePopup = $sel->is_visible("modalWindow");
ok ($canSeePopup == 0, "Popup is not visible.");
diag("Check whether the magic is hidden.");
ok(
$sel->is_visible("modalWindowMagicLayer") == 0,
"CSS magic is hidden... for now."
);
$sel->stop();;
Category: Uncategorized |
Tags: automation, behavior, commandline, environment, interaction, markup, qa, selenium, selenium-rc, test, ui, ux, web, work
Dada main
public class Dada {
public static void main(String[] args) {
System.out.println("Post your snippets with snipplr4e.");
}
}
Does an object have a specific property?
if ("foo" in myObject) {}
Does an element exist?
<div id="bar" />
<script>
if (document.getElementById('foo') == null) {
alert('foo is missing!');
}
//or:
if ( ! document.getElementById('bar')) {
alert('bar is missing!');
}
</script>
Initialize cart test helper
# CHANGED: Initialize cart. def initialize_cart @cart = @request.session[:cart] ||= Cart.create end
assert_difference
module AssertHelper
# Author:: <a href="http://blog.caboo.se/articles/2006/06/13/a-better-assert_difference" >http://blog.caboo.se/articles/2006/06/13/a-better-assert_difference</a>
#
# == Examples
# assert_difference Group, :count do
# post :create, :group => { :name => 'monkeys' }
# end
#
# assert_difference [ User, Group ], :count do
# Membership.create(:user_id => 1, :group_id => 5)
# end
#
# assert_difference User, :name, nil do
# post :update, :id => 5, { :name => 'monkeys' }
# end
def assert_difference(objects, method = nil, difference = 1)
objects = [objects].flatten
initial_values = objects.inject([]) { |sum,obj| sum << obj.send(method) }
yield
if difference.nil?
objects.each_with_index { |obj,i|
assert_not_equal initial_values[i], obj.send(method), "#{obj}##{method}"
}
else
objects.each_with_index { |obj,i|
assert_equal initial_values[i] + difference, obj.send(method), "#{obj}##{method}"
}
end
end
def assert_no_difference_in_size(object, methods = nil, &block)
assert_difference_in_size object, methods, 0, &block
end
end
Test for a valid email address and MX records
// Tests for a valid email address and optionally tests for valid MX records, too.
function is_valid_email($email, $test_mx = false)
{
if(eregi("^([_a-z0-9-]+)(.[_a-z0-9-]+)*@([a-z0-9-]+)(.[a-z0-9-]+)*(.[a-z]{2,4})$", $email))
if($test_mx)
{
list($username, $domain) = split("@", $email);
return getmxrr($domain, $mxrecords);
}
else
return true;
else
return false;
}
Hit Test v1.0
/**************************************
* Jonas Raoni Soares Silva
* <a href="http://www.joninhas.ath.cx" >http://www.joninhas.ath.cx</a>
**************************************/
hitTest = function(o, l){
function getOffset(o){
for(var r = {l: o.offsetLeft, t: o.offsetTop, r: o.offsetWidth, b: o.offsetHeight};
o = o.offsetParent; r.l += o.offsetLeft, r.t += o.offsetTop);
return r.r += r.l, r.b += r.t, r;
}
for(var b, s, r = [], a = getOffset(o), j = isNaN(l.length), i = (j ? l = [l] : l).length; i;
b = getOffset(l[--i]), (a.l == b.l || (a.l > b.l ? a.l <= b.r : b.l <= a.r))
&& (a.t == b.t || (a.t > b.t ? a.t <= b.b : b.t <= a.b)) && (r[r.length] = l[i]));
return j ? !!r.length : r;
};