ラベル watir の投稿を表示しています。 すべての投稿を表示
ラベル watir の投稿を表示しています。 すべての投稿を表示

2010-02-04

Death Agony!!!

Sometime I use many PC for automation integration testing.
But it is difficult to manage which one down by error.
So when some PC down,the PC death agony! by skype.
This code will death agony and vomit log.

# death_agony.rb
#! ruby -Ku
require 'rubygems'
require 'win32ole'
require 'kconv'

$KCODE = 'UTF8'
@MACHINE = ARGV[0]
@GOD = ARGV[1]

@oCom=WIN32OLE.new('AutoItX3.Control')
@oSkype=WIN32OLE.new('Skype4COM.skype')
raise "Please start skype" @oSkype.Client.IsRunning != true

death_agnoy = IO.read('errIO.txt')
@oSkype.SendMessage(@GOD, "Death Agony from #{@MACHINE} at #{Time.now}\n" + death_agony)
sleep(3)

@oUser = @oSkype.User(@GOD)
@oCall = @oSkype.PlaceCall(@oUser.Handle)
@oCall.Status

And catch exception in rake task(who don't use rake for testing?)

# rake.rb
# setup >(rake your_task pc=a_one_of_sacrifice p=where_to_agony) 1> errIO.txt
task :hell_grinder do
begin
ruby "death_test.rb "
rescue
p "ring ring ring..."
ruby "death_agony.rb " + ENV['pc'] + " " + ENV['p']
end
end

Then you can hear death agony from each sacrifice.
*Don't forget regsvr skype dll:here down load link
How to regist it.
> regsvr32 -that skype dll-
Ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh........

2009-11-04

Integrate Watir Rspec for long story testing and force test sequence.

WatirとRspecでテストケースなが~いテストをちょっと効率良く行う。
rspecでテストの順番を指定したい場合が多く、この方法は使えると。
レポートはhtmlで出力。


# spec/test_spec.rb
#! ruby -Ku
#!/usr/bin/env ruby
require 'spec_helper'

$KCODE = 'UTF8'

shared_examples_for "トップ画面にいることの確認" do
it "ログインしてくださいが表示されていること" do
@ie = Watir::IE.new
@ie.goto("#{$testDomain}/foo/index.aspx")
@ie.text.should include('ログインしてください')
end
end

shared_examples_for "ログインできることの確認" do
it "ログインできること、つまりログアウトの表示がされていること" do
@ie = Watir::IE.attach(:title,/.*/)
@ie.text_field(:id, 'account').set('foo')
@ie.text_field(:id, 'password').set('bar')
@ie.button(:xpath, '//td[2]/input').click
@ie.text.should include('ログアウト')
end
end

shared_examples_for "パスワード変更ができてログインできる事の確認" do
it "パスワード変更ができてログインできる事" do
@ie = Watir::IE.attach(:title,/.*/) #このattachで前のテストのIEインスタンスを使用することができる。んで続きが行える。
@ie.text_field(:id, 'CurrentPassword').set('bar')
@ie.text_field(:id,'NewPassword').set('woo')
@ie.text_field(:id,'ConfirmPassword').set('woo')
@ie.button(:name, 'Submit').click_no_wait
@autoit=WIN32OLE.new('AutoItX3.Control')
@autoit.WinWait('Windows Internet Explorer','',10).should == 1
# when dialog(confirm change pwd.), return 1.
@autoit.WinActive('Windows Internet Explorer')
@autoit.ControlClick('Windows Internet Explorer','','OK')
@ie.link(:text, 'ログアウト').click
@ie.text.should include('ログインしてください')
@ie.text_field(:id, 'account').set('foo')
@ie.text_field(:id, 'password').set('woo')
@ie.button(:xpath, '//td[2]/input').click
@ie.text.should include('ログアウト')
end
end

describe "OreOre site long story" do
it_should_behave_like "トップ画面にいることの確認"
it_should_behave_like "ログインできることの確認"
it_should_behave_like "パスワード変更ができてログインできる事の確認"
  # この順番に行われる。
  # describeでどんどんテストケースを追加すると、順番は思ったようにいかない。
# たぶん、test/unitと同じで名前のキャラコード順になる。(たぶん)
end


# spec/spec.opts
#! ruby -Ku
#!/usr/bin/env ruby
--format html:spec/doc/rspec_report.html
--loadby mtime
--colour
--reverse


# spec/spec_helper.rb
#! ruby -Ku
#!/usr/bin/env ruby
$LOAD_PATH.push File.expand_path('../../lib',__FILE__)

require 'rubygems'
require 'spec'
require 'watir'
require 'win32ole'
require 'redgreen'

WIN32OLE.codepage = WIN32OLE::CP_UTF8
#test target domain
$testDomain = 'http://foo.org'


# Rakefile.rb
require 'rake'
require 'spec/rake/spectask'

task :default => [:help]

desc "foo long Story Test"
task :spec do
Spec::Rake::SpecTask.new do |t|
t.spec_files = FileList['spec/*_spec.rb']
t.spec_opts = ['--options', "spec/spec.opts"]
end
end

UTF8のサイトのテストです。

2009-10-28

Cucumber Watir Rspec Mocha, How to add helper module to cucumber.

Cucumber with Watir



# features/support/env.rb
require 'spec/expectations'

if ENV['FIREWATIR']
require 'firewatir'
Browser = FireWatir::Firefox
else
case RUBY_PLATFORM
when /darwin/
require 'safariwatir'
Browser = Watir::Safari
when /win32|mingw/
require 'watir'
Browser = Watir::IE
when /java/
require 'celerity'
Browser = Celerity::Browser
else
raise "This platform is not supported (#{PLATFORM})"
end
end

# "before all"
browser = Browser.new

Before do
@browser = browser
end

# "after all"
at_exit do
browser.close
end


How to add helper modlue



# features/support/foo_helper.rb
module Foo
def zip_code(pref_name)
if pref_name == 'local'
"123-4567"
else
"Pls. ask postman"
end
end
end
World(Foo)


mocha integration.



# features/support/mocha_helper.rb
require "mocha"

World(Mocha::API)

Before do
mocha_setup
end

After do
begin
mocha_verify
ensure
mocha_teardown
end
end

日本語のFeatureの場合、win32 コンソールではひどいが、htmlに結果を出力すればOK。
例えば、

# config/cucumber.yml
default: --format profile features
html_report: --format progress --format html --out=features_report.html features

で、
C:\あ>cucumber -l ja --profile html_report features/send_tera_mail.feature
で実行すれば、ブラウザでは文字化けしない。
他のサイトでもいろいろ試しているようだけど、コンソールではきびしい。

2009-09-28

SJIS and UTF8

Stuck in chr encoding!


Encode Situation.
target site : UTF-8
test data : SJIS(CP932)


source file encode:sjis


#! ruby -ks
~some code~
WIN32OLE.codepage = WIN32OLE::CP_UTF8 # -> for target site encode
# string for ie
some_str = 'SJIS str 日本語です。'
give_str = some_str.toutf8


blogger sanitized my code that's why 2byte chr.
なぜ、こんなことになってしまったか?
読み込むCSVがCP932で書かれていて、これは変更できない制限がある。
テストするサイトはUTF8のエンコーディングで、これも変更できない制限がある。
で、CSVのデータを読み込むときに-kuだと、化ける。
-ksで読み込んで、toutf8でエンコードして、WIN32OLE::CP_UTF8で、
ieインスタンスからutf8でもらって$KCODE=UTF8でregexpすることに
必要だった。
他に良い、方法あるのか模索中

2009-06-18

Don't forget regsvr32 AutoItX3.dll

When using Watir,should register AutoItX3.dll

>cd C:\ruby\lib\ruby\gems\1.8\gems\watir-1.5.6\watir\
>regsvr32 AutoItX3.dll

enjoy Watir!

2009-06-10

How to down load file.


#!/usr/bin/env ruby

require 'test/unit'
require 'rubygems'
require 'watir'
require 'win32ole'



class FileUpLoadTest < Test::Unit::TestCase
include Watir

def test_fileup
ie = Watir::IE.new
ie.goto('foo.com/fileup.html')
assert(ie.file_field(:name,"register_data").exists?,message="error none file field")

#Start down load
ie.file_field(:id,'register_data').click_no_wait
# should click_no_wait,otherwise wait forever behind modal window.

windwName_dwn = "ファイルのダウンロード"
windwName_sve = "名前を付けて保存"
autoit=WIN32OLE.new("AutoItX3.Control")
autoit.WinWait(windwName_dwn)
autoit.WinActivate(windwName_dwn)
autoit.ControlClick(windwName_dwn,"","[CLASS:Button;INSTANCE:2]")
pathAndName = "var/foo.txt"
autoit.WinWait(windwName_sv)
autoit.WinActivate(windwName_sv)
autoit.ControlSetText(windwName_sv, "", 1148, "#{pathAndName}")
autoit.ControlClick(windwName_sv,"","[CLASS:Button;INSTANCE:2]")
autoit.WinWait("ダウンロードの完了")
end
end

2009-06-09

How to file up load


#!/usr/bin/env ruby

require 'test/unit'
require 'rubygems'
require 'watir'
require 'win32ole'



class FileUpLoadTest < Test::Unit::TestCase
include Watir

def test_fileup
ie = Watir::IE.new
ie.goto('foo.com/fileup.html')
assert(ie.file_field(:name,"register_data").exists?,message="error none file field")
path = "C:\\InstantRails-2.0-win\\rails_apps\\somefile.csv" # set("#{path}")
ie.file_field(:id,'register_data').click_no_wait
# debug code check file path and sleep sec.
puts "#{path}"
puts Time.now
sleep(5)
puts Time.now
# debug code end

autoit=WIN32OLE.new("AutoItX3.Control")
autoit.WinWait("ファイルの選択")
autoit.WinActivate("ファイルの選択")
autoit.ControlSetText("ファイルの選択", "", 1148, "#{path}")
autoit.Send("{ENTER}")

ie.button(:name,"btnSubmitFile").click
wait_until {ie.text.include? "アップロードされました。"} #rendering待ち
assert(ie.text.include?("アップロードされました。"),message="error import" ) #データインポートチェック

ie.close

end

end

BCM4321 on Latitude D430

At kernel 3 find wireless hardware lspci | grep -i wireless  check using current kernel module with PCI bus address lspci -vv -s 0c:...