Showing posts with label test. Show all posts
Showing posts with label test. Show all posts

Thursday, February 4, 2010

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........

Wednesday, November 4, 2009

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のサイトのテストです。

Thursday, October 8, 2009

invoke &&

Stuck in && place


1st code:When foo_text does not include 'woo',
But always show "It is great movie".

some_str = foo_text.include?('woo') ? 'madam' : ''
if @jekyll_hyde.include?('one-thirty-four' && some_str)
then puts "It is great movie"
else puts "Please check it out again"
end


This below code works well

some_str = foo_text.include?('woo') ? 'madam' : ''
if @jekyll_hyde.include?(some_str && 'one-thirty-four')
then puts "It is great movie"
else puts "Please check it out again"
end


By the way,really good movie that is.

Monday, September 28, 2009

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することに
必要だった。
他に良い、方法あるのか模索中

Tuesday, August 18, 2009

Brew Tool Suite Perl API

How to apply original keymap.ini

オリジナルのキーマップ iniファイルを作成しテストケースを作るにあたって。

use enumでハマリました。

--keymap.ini

[KEYMAP]
AVK_SELECT=112
AVK_UP=134
AVK_DOWN=135
AVK_LEFT=88
AVK_RIGHT=89
AVK_SOFT1=34
AVK_SOFT2=35
AVK_SOFT3=36
AVK_SOFT4=36
AVK_SEND=69
AVK_CLR=70

だとしたら、
--Testcase.pl

.....
use enum qw( AVK_ASTERISK=1000 AVK_NUMBER_SIGN AVK_SELECT AVK_UP AVK_DOWN AVK_LEFT AVK_RIGHT AVK_SEND AVK_CLR AVK_END);
.....

のように、enumで定義するときに、順序を合わせないと想定通りの挙動をしなかった。

iniファイルの内容をnameでマッピングするのかと思っていたのが間違え立った模様。
足掛け、3日ハマリマシタ。Brewのデベロッパー(正式なアカウントがないと入れない)サイトでもぜんぜんこういう情報がなく。サイトも重いし。アカウント作成すれば入れるフォーラム(無料のサイト)でもあまり情報なしで、perl普段から使ってる人には常識なのかもしれないですが、、、

慣れていないperlコードだけだと、自動テストをまとめてコントロールするのが大変なんで、rakeでできないかなーと模索中。
Autoitも使用するので、rubyで全部コントロールできると楽。

だれか、Brew Tool Suite Perl APIでなく、RubyにてBTILをSwigした、Brew Tool Suite知ってますか?
Does anyone know Brew Tool Suite Ruby API that swiged BITL for ruby?

Thursday, July 9, 2009

Where is legacy apps...

Don't worry.


For tester,legacy machine lover.
There can get legacy apps.
  • IE7 download

  • Old Skype download

  • Very good service !

    Thursday, June 18, 2009

    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!

    Wednesday, June 10, 2009

    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

    Tuesday, June 9, 2009

    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