Thursday, January 08, 2009

AutoITX3, it helps to make automation happen

Once you got such an error, when you run in ruby:

Unknown OLE server: `AutoItX3.Control' (WI2OLERuntimeError)

that might mean you have not registed the AutoItX3.dll in your computer,
in current Watir version, AutoItX3.dll has been included in the watir folder,
so Run the command in "Run":
regsvr32 "C:\ruby\lib\ruby\gems\1.8\gems\watir-1.6.2\lib\watir\AutoItX3.dll"

note: you need to pick up your own path of where AutoItX3.dll locates.

then you will not get the errors :)

learn AutoItX3, please go to http://www.autoitscript.com/autoit3/index.shtml
I just want to use it to handle the popup windows when writing Watir scripts

How to handle the popup window using watir scripts

sometimes, we will meet the popup window issue with our automation scripts, it can not catch the window easily, so use the AutoItX3, we can solve this kind of problem well:
require "watir"
require "win32ole"

def check_for_popup_window

flag =0
autoit = WIN32OLE.new('AutoItX3.Control')

while (flag ==0)

# check the popup window status, set the timeout =1

flag = autoit.WinWait("Microsoft Internet Explorer", "", 1)

#another way to do this, you can get the popup info with autoit Spy tool
#autoit.ControlClick("Microsoft Internet Explorer", "", "[CLASS:Button; INSTANCE:1]")

puts(flag)

# If window found, send appropriate keystroke (e.g. {enter}, {Y}, {N}).

if (flag==1) then autoit.Send("{Enter}") end

sleep(0.5)
end
end

#main body of watir program:

ie = Watir::IE.new

ie.speed = :fast

puts "Step 5: Click one vendor detail link"

#create a new thread to call check for popup window method
popup = Thread.new {check_for_popup_window}

ie.goto test_vendorURI

sleep 1

#tear down the thread has been created
at_exit { Thread.kill(popup) }

A simple example for Xpath on web service test

when you do automation test or performance test on web service, you may need to do some correlation work on dynamic value returned by server.
Take Jmeter as an example, for correlation work, there is two ways to catch dynamic value
1. using Regular Expression Extractor-- you can write simple Regular Expression to extract the value
2. using XPath Extractor--write Xpath to seek the value

Here is a simple example to show how you deal with web service correlation work using Xpath :

I want to get the token value returned by the server, here is the response XML:





true
3FBCB0BDA521B5BC1A399AC094063993D26BC70BA1E3175927D6F






Xpath: //*[local-name()='token']

how about there is the namespace in the XML?? just like this:



getResetPasswordTokenResponse xmlns:ns1="http://user.123.com/user_security_service">

true
3FBCB0BDA521B5BC1A399AC094063993D26BC70BA1E3175927D6F






XPath://*[local-name()='token' and namespace-uri()="http://api.user.123.com"]

it is simple, and user-friendly :)

at Last, you can test your Xpath expression here : http://www.mizar.dk/XPath/Default.aspx

hope this helps!

using Xpath way in Watir with Caution---slowness

i am used to write watir scripts to do the single user performance test or launch it under load test, it helps a lot when I want to get the response time from real user experience perspective.

but there is some situation i need to use Xpath to get the object which is to be clicked....
ie.button(:xpath, "//div[@id='ContentWrapper']/div/div[3]/a/img").click

i find it is realllllly slow when Watir is seeking the object within the Dom, i realize this way is not suitable for me to get response time,just for automation test maybe....

for almost situation i need to click the objects, i always use:
ie.link(:index,"118").click

or I change Post into Get method to get the same thing, for example:
Change : ie.button(:xpath, "//div[@id='ContentWrapper']/div/div[3]/a/img").click
into :
ie.goto "http://1.2.3.4/search.do?para1=performance&pageNumber=1"

so anyway, I like Watir, but using Xpath way in Watir with Caution, it is a little bit slow....

2009是憧憬的一年

经过2008这个多事之年,其实不想过多的回忆什么,倒是有种赶紧熬过2008年的感觉。。。。
冬天即将过去,春天还会远吗?
对于2009年,充满的更多是希望,想借个理由对自己说:新的开始,抛掉所有的不快,让我们重新上路。。。。。。
生活还将继续,而不同的是我们自己对待生活的态度:)
Happy 2009!! A brand New Life is Coming!

I miss Sierra Nevada Beer

突然想起前年在san jose 酒吧里喝到的啤酒,Sierra Nevada,啤酒的色泽跟我们普通喝到的啤酒不同,有些偏深,喝到嘴里苦中带甜,有股花瓣的清香。。。。(不知道是不是给女士喝的,哈哈,不过确实听好喝,价格也不是很贵)


不过还有一件印象深刻的是喝酒之前被服务员要求看护照,因为没带,所以问了句:“只带了国内身份证,能行不?”(注意,我的身份证还不是第二代的,还是最老款的那种,字迹还不是很清晰)
服务员看了看,说问问老板,说着拿着身份证去给经理过过眼
大概过了5分钟,他走过来,拿着啤酒单,对我微笑着说,没问题,您需要什么酒。。。同事都对我笑了,说明我看起来还年轻。。。。

新年了,祝大家有一个新的开始,如果国内有买这个酒的话,我想拿着它跟大家干杯!Cheers Up!

Do not shout at your JBoss!

An interesting post by Brendan Gregg who did a very unthinkable experiment to his JBoss server.

So he found that when he shout at the JBoss server, the server will take a long Disk I/O latency....so he give us a "take away", do not shout at your Jboss if you want a high performance! :)

here is the link of Brendan Gregg's experiment:
http://blogs.sun.com/brendan/entry/unusual_disk_latency

Class SimpleDateFormat is not thread safe

One tiny find this week from our team,during I run the load testing and there is one step we need to fill the target date into the text box.

in our code, we need to parse date/time format using SimpleDateFormat class, so if IthreadA is parsing a value while threadB is changing the pattern, then error message bellowing could happen,"occasionally":
java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Long.parseLong(Long.java:424)
at java.lang.Long.parseLong(Long.java:461)
at java.text.DigitList.getLong(DigitList.java:167)
at java.text.DecimalFormat.parse(DecimalFormat.java:1271)
at java.text.SimpleDateFormat.subParse(SimpleDateFormat.java:1375)
at java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1124)
at java.text.DateFormat.parse(DateFormat.java:333)
at com.XXXX.struts.DateConverter.convert(DateConverter.java:41)
at org.apache.commons.beanutils.ConvertUtilsBean.convert(ConvertUtilsBean.java:428)
So, we just simply change the definition of SimpleDateFormat object from class variable to local variable, this problem have been solved!

"This is a pitfall from JDK" :) I am not sure how many of you already release it....
You can look at the interesting article from Brian Goetz
http://www.ibm.com/developerworks/java/library/j-jtp09263.html

One thread lock issue sloved, another rises...

Recently during performing a load testing to our application, after taking stack trace from back-end, it appears 90% of http threads are locked as this kind of pattern:

"http-0.0.0.0-8080-12" daemon prio=6 tid=0x4bc5f620 nid=0xc54 waiting for monitor entry [0x4f4de000..0x4f4dfcec]
at java.lang.ref.ReferenceQueue.poll(ReferenceQueue.java:81)
- waiting to lock <0x07e4b968> (a java.lang.ref.ReferenceQueue$Lock)
at java.io.ObjectStreamClass.processQueue(ObjectStreamClass.java:2206)
at java.io.ObjectStreamClass.lookup(ObjectStreamClass.java:253)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1035)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1375)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1347)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1290)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:302)
..........

Looking for help through the popular search engine, come across to this thread:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6525425
just exactly the same issue we met!!
we are using JDK1.5.0._07 version on our performance environment (BTW, we are not crazy to do version upgrade stuff :) )
this lock issue has been fixed in JDK1.5.0._14, look at the release notes:http://java.sun.com/j2se/1.5.0/ReleaseNotes.html#150_14

after validation, we find that the issue has really been fixed, there is no one thread lock as previous pattern, and throughput improves nearly 20% (under a relative high user load condition) ,HOWEVER, there is another type of lock rising almost 90% among all http threads.... Pattern 2:

"http-0.0.0.0-8080-48" daemon prio=6 tid=0x4dcc3808 nid=0xb0c waiting for monitor entry [0x5208c000..0x5208f9ec]
at org.jboss.metadata.WebMetaData.getRunAsIdentity(WebMetaData.java:511)
- waiting to lock <0x24e8c7e0> (a java.util.HashMap)
at org.jboss.web.tomcat.security.RunAsListener.instanceEvent(RunAsListener.java:67)
at org.apache.catalina.util.InstanceSupport.fireInstanceEvent(InstanceSupport.java:295)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:676)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:574)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:499)
at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:966)
at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:602)
at org.apache.struts.tiles.TilesUtilImpl.doInclude(TilesUtilImpl.java:99)
at org.apache.struts.tiles.TilesUtil.doInclude(TilesUtil.java:135)
........

we are targeting to look at the source code of third party, hope to solve it luckily, one of source code related:
http://www.java2s.com/Open-Source/Java-Document/EJB-Server-JBoss-4.2.1/tomcat/org/jboss/web/tomcat/security/RunAsListener.java.htm

必须搬家了。。。蜗牛壳,我的新家

我的blog提供商被人举报(joychester.xhblog.com),我不得不再次启用蜗牛壳,其实blogger要不是之前被在国内“封杀”,我也不会搬走,但现在国内也可以自由访问了,所以回来也是一件幸事:)
也让我本想再拖两天的思想彻底打消,蜗牛壳,我搬进来了!