Replace character using Ruby/Watir

by barbarat on April 25, 2009

Read in data from a file and replace the text using /replacetext./

urlfile= “C:\\printservers\\printurls.txt”
i=1
servermax = 4

File.open(urlfile, ‘r’) do |f1|
while line = f1.gets
result = {}
server,product1,durl,product2,lurl,product3,curl,product4,murl,product5,surl,product6,mpurl=

line.split(”,”)

while i <= servermax
server1 = server.gsub!(/print01-0./, “print01-0″+ “#{i}”)
f.puts “1. First verify server is up #{server1}”

$ie.goto(server1)
i= i+1
end

end

end

{ 0 comments }

How to verify image properties using Ruby/Watir

by barbarat on April 25, 2009

An example to grab the first image loaded on a page and return the width and height.

$ie.goto(url)

width = $ie.image(:index,1).width
widthnum =  Integer(width) #Convert to integer.  #
if widthnum >50
f.puts “- SUCCESS: Width of image loaded: #{widthnum}”
else
f.puts “!!!!! WARNING: Did not find width for image on page !!!!!”
end

height = $ie.image(:index,1).height
heightnum = Integer(height) #Convert string to integer. #
if heightnum > 50 #height != nil (pixel version) #
f.puts “- SUCCESS: Height of image loaded: #{heightnum}”
else
f.puts “!!!!! WARNING: Did not find height for image on page !!!!!”
end

{ 0 comments }

Edit Cookies in Your Browser

by barbarat on November 12, 2008

Testing a site that contains values that target certain users or simply trying to figure out which is the best approach via A/B tests? To modify your browser cookies, there are some simple tools to make this happen.

Firefox

1. Install Firebug 1.2.X:
- Go to the web page you wish to view or set cookie
- Go to Firefox -> Tools Menu-> Open Firebug
- Inspect -> Cookies
- Right click to Edit

2. Another option is to install the add-on Web Developer for Firefox.
- Firefox -> Tools->Web Developer -> Cookies -> View cookies
- Edit cookie
- Go to page again
- Tools -> Web Developer -> Cookies -> View cookies
- You can also delete and refresh cookies

Firefox Web Developer

Firefox Web Developer

Internet Explorer

- Go to the web page you wish to view/set cookie

- Install the little program called IECookiesView

- Double-click to execute program

- In the upper pane of the program, click on the name of the website

- In the lower pane of the program, click on the name of the cookie you wish to edit.

- Right-click on the cookie name and choose option to edit

- Close IECookiesView and restart browser

- Navigate to the web page again

View IE Cookies

View IE Cookies

{ 0 comments }

Check it out

by Barbara Tam on November 10, 2008

{ 0 comments }

LAMP - Linux, Apache, MySQL, and Perl/Python/PHP

by barbarat on November 4, 2008

The only open source web platform you need to know. LAMP stands for Linux, Apache, MySQL, and Perl, Python, or PHP technologies.

LAMP is an open-source Web development platform, also called a Web stack, that uses Linux as the operating system, Apache as the Web server, MySQL as the database management system, and PHP as the object-oriented scripting language. Perl or Python can be substituted for PHP.

{ 1 comment }

Software Quality Assurance Jobs

by barbarat on October 18, 2008

Top 10 sites to find Software QA Jobs:

Dice

Monster

Yahoo Hotjobs

Career Builder

Jobirn

Simply Hired

Craigslist

QA Jobs

Indeed

Linkedin

{ 0 comments }

Delete Cookies Using Ruby/Watir

by barbarat on October 1, 2008

1. In your Ruby script, require:

require ‘fileutils’

2. Set the path to your cookies, you can leave the ENV['USERNAME']

$cookieDir = “C:\\Documents and Settings\\#{ENV['USERNAME']}\\Cookies”
3. Call the file utility function to remove the cookies:

FileUtils.rm_rf $cookieDir

{ 0 comments }

Delete Cache and Cookies in Ruby

by barbarat on September 29, 2008

How do you clear out your browser cache and cookies from your Watir scripts? Create a ruby file del_cache.rb with the code below, then from your main testfile.rb require the file and call the function.

——————————————————————

#!/bin/ruby
#
#
#
#
#
# set TEMPIF=%USERPROFILE%\Local Settings\Temporary Internet Files
# %TEMPIF%\Content.IE5\Index.DAT

require ‘Win32API’

#
#
# HashMethods = a Hash that can be accessed with methods
#   e.g.    h = MethodHash.new
#           h['street'] = ‘Broadway’
#           h.street    = ‘Broadway’
#           puts h.street  ===> Broadway

require ‘delegate’

class MethodHash < SimpleDelegator
def initialize h = {}
super h
end

def method_missing(method_name, *args)
name = method_name.to_s
if name.ends_with?(’=')
self[ name.chop ] = args[0]
else
self[ name ]
end
end
end

class String
def ends_with?(substr)
len = substr.length
self.reverse() [0 .. len-1].reverse == substr
end

def starts_with?(substr)
len = substr.length
self[0 .. len-1] == substr
end

alias start_with?  starts_with?
alias begin_with?  starts_with?
alias begins_with? starts_with?
alias end_with?    ends_with?

# String each() operator reads line-by-line
# These functions return characters
def each_char
self.each_byte{|x| yield x.chr }
end
def collect_char
r = []
self.each_byte{|x| r << x.chr }
r
end
end

=begin

// Windows System calls needed to clear cache.
//

BOOL DeleteUrlCacheEntry(
LPCTSTR lpszUrlName
);

HANDLE FindFirstUrlCacheEntry(
LPCTSTR lpszUrlSearchPattern,
LPINTERNET_CACHE_ENTRY_INFO lpFirstCacheEntryInfo,
LPDWORD lpdwFirstCacheEntryInfoBufferSize
);

BOOL FindNextUrlCacheEntry(
HANDLE hEnumHandle,
LPINTERNET_CACHE_ENTRY_INFO lpNextCacheEntryInfo,
LPWORD lpdwNextCacheEntryInfoBufferSize
);

BOOL FindCloseUrlCache(
IN HANDLE hEnumHandle
);

typedef struct _INTERNET_CACHE_ENTRY_INFO {
DWORD dwStructSize;
LPTSTR lpszSourceUrlName;
LPTSTR lpszLocalFileName;
DWORD CacheEntryType;
DWORD dwUseCount;
DWORD dwHitRate;
DWORD dwSizeLow;
DWORD dwSizeHigh;
FILETIME LastModifiedTime;
FILETIME ExpireTime;
FILETIME LastAccessTime;
FILETIME LastSyncTime;
LPBYTE lpHeaderInfo;
DWORD dwHeaderInfoSize;
LPTSTR lpszFileExtension;
union {
DWORD dwReserved;
DWORD dwExemptDelta;
}
} INTERNET_CACHE_ENTRY_INFO, *LPINTERNET_CACHE_ENTRY_INFO;

=end

def main
w = get_api(’wininet’,FUNCS)
i = 0

info,infosize = get_first_info(w)
cache = w.FindFirstUrlCacheEntry.Call(nil,info,infosize)
if cache != 0
begin
len, source_file_ptr, local_file_ptr = info.unpack ‘LLL’
w.DeleteUrlCacheEntry.Call(source_file_ptr)
i += 1
info,infosize = get_next_info( w, cache )
end while w.FindNextUrlCacheEntry.Call(cache, info, infosize) != 0
end
w.FindCloseUrlCache.Call(cache)
i
end

def get_first_info(api)
sizenum = [0,0].pack(’L*’)
buf =  [1024,0].pack(’L*’).ljust(1024)
r = api.FindFirstUrlCacheEntry.Call(nil,nil,sizenum)
n = sizenum.unpack(’L')[0]
info = sizenum.ljust(n)
[info,sizenum]
end

def get_next_info(api, handle)
sizenum = [0,0].pack(’L*’)
buf =  [1024,0].pack(’L*’).ljust(1024)
r = api.FindNextUrlCacheEntry.Call(handle,nil,sizenum)
n = sizenum.unpack(’L')[0]
info = sizenum.ljust(n)
[info,sizenum]
end

#
# Win32 API used in this file is listed here.
# Each system call can be instatiated like this
#    DeleteUrlCacheEntry = Win32API.new(”wininet”, “DeleteUrlCacheEntry”, ['P'], ‘V’)
# Instead, the functions are defined dynamically from this list:
#
FUNCS = {
‘FindFirstUrlCacheEntry’ => ['ppp','n'],
‘FindNextUrlCacheEntry’  => ['npp','n'],
‘DeleteUrlCacheEntry’    => ['n',  'n'],
‘FindCloseUrlCache’      => ['n',  'n']
}

#
# get_api returns a hash with Win32 API system calls
# Usage:
#     api = get_api(’Kernel32′, {’GetLastError’=>['V', 'N'],…})
#
def get_api(library, function_hash)
f = MethodHash.new
function_hash.each{|funcname,types|
in_types = types[0].collect_char{|x| x}
out_type = types[1]
f[funcname] = Win32API.new(library, funcname, in_types, out_type)
}
f
end

def getLastError
f = Win32API.new(’Kernel32′, ‘GetLastError’, ['V'], ‘N’)
f.call
end

if __FILE__ == $0
n = main
# print “Deleted #{n} items\n”
end

———————————————————

# Your testfile.rb

dir = File.dirname(__FILE__)
require “#{dir}\/lib\/del_cache” #clear cookies & cache, call main
require “watir”
require ‘Win32API’

puts “- Clear cache and cookies”

main

{ 0 comments }

Running a Webload Script

by barbarat on September 17, 2008

TBD

{ 0 comments }

Related Links

by barbarat on September 17, 2008


{ 0 comments }