Showing posts with label win32ole. Show all posts
Showing posts with label win32ole. 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........

Sunday, November 29, 2009

How to select ComboBox

How to select ComboBox by AutoIt.exe from ruby
Give parameter to select combobox exe.


### select_year_combobox.au3 ###
WinActivate("Configuration")
Global Const $CB_SETCURSEL = 0x14E
$h_combobox = ControlGetHandle("Configuration", "", "[CLASS:WindowsForms10.COMBOBOX.app.0.378734a; INSTANCE:2]")
$i_index = $CMDLINE[1]
DllCall("user32.dll", "int", "SendMessage", "hwnd", $h_combobox, "int", $CB_SETCURSEL, "int", $i_index, "int", 0)


ControlGetHandle("Configuration", "", "[CLASS:WindowsForms10.COMBOBOX.app.0.378734a; INSTANCE:2]")
ControlGetHandle(<app title>, "", <select combobox instance>).
<select combobox instance> is easy to know by AutoIt Window Info app.


### select_combobox.rb ###
select_year_exe = File.expand_path(File.dirname(__FILE__) + "/select_year_combobox.exe")
year = 1 # ex. index 1 = 2005
system("#{select_year_exe} #{year}")


>ruby select_combobox.rb # app will choose index 1 from combobox.
>select_year_combobox.exe 1 # app will choose index 1 from combobox.

Wednesday, November 11, 2009

Skype mood to twitter by COM

Skype mood to twitter.
Skypeのムードをtwitterにpost。

on windowsXP
requirement

Useage
cmd.exe
>gem install twitter4r
>regsvr32 Skype4COM.dll <--when popup dialog,should 'OK'
>ruby mooding.rb
then every 5 sec. ruby check skype mood and updated at that time,post it to twitter.
だいたい5秒おきに、skypeのムードが更新されたか確認して、されてれば、twitterにポストします。下記コードのみ。
for stopping,止め方、Ctrl+C

#! ruby -Ku
require 'rubygems'
require 'win32ole'
require 'twitter'
require 'kconv'

$KCODE = 'UTF8'

@oTwitter = Twitter::Client.new
twit_id = ARGV[0]
twit_pwd = ARGV[1]
if @oTwitter.authenticate?(twit_id, twit_pwd) == true then
p 'OK auth'
else
raise 'ID,Passwd or both is not collect'
end

@oSkype=WIN32OLE.new('Skype4COM.skype')
mood = nil # Anyway 1st time twit mood
loop do
if @oSkype.Client.IsRunning != true then
raise "Please start skype"
else
end

if @oSkype.CurrentUserProfile.MoodText.toutf8 != mood then
mood = @oSkype.CurrentUserProfile.MoodText.toutf8
@oTwitter = Twitter::Client.new(:login => twit_id, :password => twit_pwd)
@oTwitter.status(:post, mood)
else
sleep(5) # check mood update every almost 5sec.
end
end

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, September 24, 2009

win32ole on ActivePerl 5.6

When I use module::win32ole, I could not make win32ole instance.
Solution.
  • Install AutoIT

  • or
    find AutoItX3.dll and

    cmd.exe
    >regsvr32 AutoItX3.dll